21
votes

Is there a way to conditionally install a helm subchart based on global values.yaml? I've all my internal services and components as subcharts, and one of them is a messagequeue chart. In my dev and test environment (local k8s), I use RabbitMQ, and in staging and Prod (AKS), I use Azure Service Bus. Based on the namespace/values.yaml, I want to install rabbitmq or not.

P.S - I've created all the components as subcharts so that they are all part of a single release.

3

3 Answers

33
votes

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
2
votes

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) to subcharts/
  • 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!

0
votes

I would propose this (ugly) workaround as answer borrowed from @sgandon: https://github.com/helm/helm/issues/3742#issuecomment-383095917

dependencies: - name: mobi-postgresql version: 1.0.1 repository: "@mobi" alias: postgresql - name: oraclepdb version: 0.0.1 repository: "file://subcharts/oraclepdb" condition: oraclepdb.enabled

Then you can use the practice Chart dependencies to manage subcharts as dependencies via helm dep update and helm dep build.

It's not beautiful as long as this bug is not fixed.