kubernetesoperatorskubernetes-helmkubernetes-operator

How to make sure subcharts charts are installed before the actual resources


I am trying to create a helm based operator and for most part, I've got it working. However I need to make sure that the subcharts are installed before the operator is trying to create resources from those subcharts. For e.g I have mongodb community-operator helm chart as a subchart. However, when I deploy the operator i get the below error

failed to install release: unable to build kubernetes objects from release manifest: resource mapping not found for name: "test-mongodb" namespace: "default" from "": no matches for kind "MongoDBCommunity" in version "mongodbcommunity.mongodb.com/v1" ensure CRDs are installed first.

Looks like its trying to create the mongodb instance before actually installing the operator and crds. How can I force it to first install the subcharts and then try to create mongodb instance.


Solution

  • inside the chart.yaml you can use the condition & tag

    dependencies:
    - name: subchart
      version: 0.0.1
      repository: https://chart.github.io/helm-charts
      condition: subchart.enabled
    

    so if the chart name as subchart is not installed already in cluster it will throw the error.

    Official doc : https://helm.sh/docs/chart_best_practices/dependencies/

    if you have multiple sub charts as dependencies you can also go with the tags