Helm conditionally install subchart
Update: With helm 3.0 release and Chart version v2, the chart dependencies have to be added in Chart.yaml instead of a separate requirements.yaml file. So if you are using apiVersion=v2 in helm 3, see the helm v2->v3 changes. This would then be:
apiVersion: v2
name: myapplication
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.0
dependencies:
- name: apidocs
condition: apidocs.enabled
I've found out the answer:
In requirements.yaml, add:
dependencies:
- name: api
condition: api.enabled
- name: messagequeue
condition: messagequeue.enabled
and in values.yaml, add
api:
enabled: true
messagequeue:
enabled: false
Now during installation, pass the values to enabled or disable the messagequeue as follows:
helm install --dry-run --debug website\ --set messagequeue.enabled=true
or
helm install --dry-run --debug website\ --set messagequeue.enabled=false
Using Helm version v3.4.1.
I was having this error.
helm chart with requirements.yaml, did not find local charts
"helm dep build" fails if requirements.yaml contains local dependencies and remote one #3742.
My solution was to:
- Rename
charts/
(directory) tosubcharts/
- And
chmod 755 subcharts/*
Heml 3 didn't like it when I placed my local dependencies in charts/
Also Helm dep up needs permissions to move the local dependencies from your subcharts directory to tmpcharts/
and so on.
**
This is not my find.
**
I read this from @sgandon :
Bug documented #3742.
comment.
the reason why the os.Stat() fails to find the folder. This is because the calling function downloadAll is renaming the charts folder to tmpcharts during the update thus making our unpacked chart not foundable for that duration.
Note:
!! On Helm 3 requirements.yaml is deprecated. !!
You add the dependencies in the Parent/Main Charts.yaml.
dependencies:
- name: chart-you-want-to-deploy-1
repository: file://subcharts/chart-you-want-to-deploy-1
version: 0.0.1
condition: chart-you-want-to-deploy-1.enabled
- name: chart-you-want-to-deploy-2
repository: file://subcharts/chart-you-want-to-deploy-2
version: 0.0.1
condition: chart-you-want-to-deploy-2e.enabled
Added my variables to my globals in the Parent/Main Values.yaml
globals:
chart-you-want-to-deploy-1:
enabled: true
chart-you-want-to-deploy-2:
enabled: false
Dont forget to add the flags to your command.
In my case I was using a CI/CD tool (Gitlab)
script:
- >
helm dep up Main-Chart-Name && \
helm upgrade --install \
--set chart-you-want-to-deploy-1.enabled=false \
--set chart-you-want-to-deploy-2.enabled=true \
RELEASE_NAME Main-Chart-Name
my tree
Main-Chart-Name
├── Chart.yaml
├── subcharts
│ ├── chart-you-want-to-deploy-1
│ │ ├── Chart.yaml
│ │ ├── charts
│ │ ├── templates
│ │ │ └── chart-you-want-to-deploy-1.yaml
│ │ └── values.yaml
│ └── chart-you-want-to-deploy-2
│ ├── Chart.yaml
│ ├── charts
│ ├── templates
│ │ └── chart-you-want-to-deploy-2.yaml
│ └── values.yaml
├── templates
│ ├── helpers.tpl
│ ├── my.yaml
│ ├── main.yaml
│ └── templates.yaml
└── values.yaml
P.S. - Thank you @Narayana and @sgandon . Thanks to you guys I'm happy deploying!
I tried that now in 2022 and did the following:
in chart.yaml:
dependencies:
- name: db
version: 0.1.0
condition: db.enabled
- name: mailer
version: 0.1.0
condition: mailer.enabled
Then i added in values.yaml of the main chart:
db:
enabled: true
...
mailer:
enabled: true
....
and added my subcharts db and mailer to the charts directory. Works as expected.