Search code examples
yamlkubernetes-helm

Conditionally manage Helm chart dependencies without keeping the child charts inside 'charts' directory


I currently have 3 Helm repositories with the following structure:

repoA/
├── templates/
├── Chart.yaml
├── values.yaml

repoB/
├── templates/
├── Chart.yaml
├── values.yaml

masterRepo/
├── templates/
├── Chart.yaml
├── values.yaml
├── requirements.yaml

The requirements.yaml file from masterRepo is something like below:

dependencies:
- name: repoA
  version: "1.0"
  repository: "file://../repoA"
  condition: repoA.enabled
- name: repoB
  version: "1.0"
  repository: "file://../repoB"
  condition: repoB.enabled

I would like to only use masterRepo to deploy the dependent Helm charts.

I know I can manually put all the child repositories in the masterRepo/charts and it will work but I wanna keep these repositories independent so that other master-repositories can use any of

What to do to make parent Helm chart detect all the required Helm charts and install them conditionally (based on repoX.enabled variable) without keeping the dependent repositories inside the charts directory of the Master-helm-chart?


Solution

  • If you have multiple Helm charts at different locations in the system, you can create dependencies without changing their location.

    With the structure specified in the question, we can add dependencies in requirements.yaml (for Helm version: 2.x.x) or Chart.yaml (for Helm version:3.x.x). I am currently using Helm v2.16.1.

    Now simply run helm dependency update or helm dep up from inside the masterRepo directory and a charts directory gets created. Now the updated structure of masterRepo looks like:

    masterRepo/
    ├── charts/
           └── chartA-1.tgz
           └── chartB-1.tgz
    ├── templates/
    ├── Chart.yaml
    ├── requirements.lock
    ├── requirements.yaml
    ├── values.yaml
    

    The new files/directories added are:

    1. ChartA-1.tgz and ChartB-1.tgz TAR Archive files which are nothing but zipped chartA and chartB charts.
    2. requirements.lock: Used to rebuild the charts/ directory. Read more about this file in this SO post.

    To install the child charts conditionally, you can the following the values.yaml file of the masterRepo:

    repoA:
      enabled: True
    repoB:
      enabled: True
    

    Now a simple helm install command from inside the masterRepo will deploy masterRepo as well as it's dependencies (chartA and chartB).

    Hope this helps. Happy Helming!