Not able to specify custom helm values file location to HelmChart kadet component
AgathEmmanuel opened this issue · 5 comments
Description
When we try to provide custom helm values file location to the HelmChart kadet component, its not being taken up by the component, instead its will make use of the default values file located in Helm Chart. So we are forced to use the default values only.
In cases where we maintain different values file for different environments or targets, this makes things very difficult.
To Reproduce
Steps to reproduce the behavior:
Make sure you have the helm chart of the specific application locally, my files were structured as shown below
├── charts
│ ├── ethereum
│ │ ├── Chart.yaml
│ │ └── values.yaml
│ └── values-files
│ └── values.yaml
├── compiled
├── components
│ └── ethereum
│ └── __init__.py
├── inventory
│ ├── classes
│ │ └── components
│ │ └── ethereum
│ │ └── init.yml
│ └── targets
│ └── local.yml
├── README.md
└── templates
inventory/classes/components/ethereum/init.yml
from kapitan.inputs.helm import HelmChart
from kapitan.inputs.kadet import BaseObj, inventory, load_from_search_paths
inv = inventory()
# utils = load_from_search_paths("utils")
def main():
main_obj = BaseObj()
ethereum = HelmChart(
chart_dir='charts/ethereum',
helm_params={"namespace": "local-test", "name": "ethereum-test"},
helm_values_file='charts/values-files/values.yaml'
)
main_obj.root.update(ethereum.root)
return main_obj
inventory/targets/local.yml
---
classes:
- components.ethereum
-
parameters:
kapitan:
vars:
target: local
inventory/classes/components/ethereum/init.yml
---
parameters:
kapitan:
compile:
- output_path: kubernetes
input_type: kadet
output_type: yml
input_paths:
- components/ethereum
Expected behavior
HelmChart(
chart_dir='charts/ethereum',
helm_params={"namespace": "local-test", "name": "ethereum-test"},
helm_values_file='charts/values-files/values.yaml'
)
Here when the component is expected to make use the file provided via helm_values_file or helm_values_files
but, it will only make use of the default values.yml file present in the chart. In my case 'charts/ethereum/values.yaml'
python --version
: Python 3.10.6pip3 --version
: pip 22.0.2Are you using pyenv or virtualenv?
: No
Hey @AgathEmmanuel , is there a reason why you are using a generator for the helm chart instead of the input_type_helm
?
Hello @AgathEmmanuel ,
I am not aware of the helm_values_file
being implemented tbh Perhaps you need to read it in python and pass the content to HelmChart?
My bad, looks like there is some sort of support, let me look into it
Also, why not using the inventory to source the values?
class HelmChart(BaseModel):
"""
Returns rendered helm chart in chart_dir
Each rendered file will be a key in self.root
Requires chart_dir to exist (it will not download it)
"""
chart_dir: str
helm_params: dict = {}
helm_values: dict = {}
helm_path: str = None
def new(self):
for obj in self.load_chart():
self.root[
f"{obj['metadata']['name'].lower()}-{obj['kind'].lower().replace(':','-')}"
] = BaseObj.from_dict(obj)
def load_chart(self):
helm_values_file = None
if self.helm_values != {}:
helm_values_file = write_helm_values_file(self.helm_values)
output, error_message = render_chart(
self.chart_dir, "-", self.helm_path, self.helm_params, helm_values_file, None
)
if error_message:
raise HelmTemplateError(error_message)
return yaml.safe_load_all(output)
The HelmChart class expects values to be provided as a dictionary. helm_value_file
is not supported.
My suggestion is to read the file with python, or use the helm
input type that does support it from the inventory
Hey @AgathEmmanuel , is there a reason why you are using a generator for the helm chart instead of the
input_type_helm
?
We had a special case where we had to use kapitan to deploy the same application based on the same helm chart to same environment multiple times.
For example:
appA have a HelmChartA
We needed to deploy appA1, appA2, appA3 based on same HelmChartA to same namespace in same environment.
So using input_type_helm
meant that we had to create multple targets (target_appA1, target_appA2, target_appA3) to make this happen. Using generators meant that things where much cleaner, centralized to one target and easy to handle.
class HelmChart(BaseModel): """ Returns rendered helm chart in chart_dir Each rendered file will be a key in self.root Requires chart_dir to exist (it will not download it) """ chart_dir: str helm_params: dict = {} helm_values: dict = {} helm_path: str = None def new(self): for obj in self.load_chart(): self.root[ f"{obj['metadata']['name'].lower()}-{obj['kind'].lower().replace(':','-')}" ] = BaseObj.from_dict(obj) def load_chart(self): helm_values_file = None if self.helm_values != {}: helm_values_file = write_helm_values_file(self.helm_values) output, error_message = render_chart( self.chart_dir, "-", self.helm_path, self.helm_params, helm_values_file, None ) if error_message: raise HelmTemplateError(error_message) return yaml.safe_load_all(output)
The HelmChart class expects values to be provided as a dictionary.
helm_value_file
is not supported.My suggestion is to read the file with python, or use the
helm
input type that does support it from the inventory
Got it. This will do the job. Sorry, I misinterpreted that the helm_values_file variable was meant to take in the helm values file location just like how we are able to do it in input_type_helm. Thanks a ton.