embeding conf files into helm chart

10,615

If the content of the files is static then you could create a files directory in your chart at the same level as the templates directory (not inside it) and reference them like:

kind: ConfigMap
metadata:
  name: splunk-master-configmap
data:
  {{ (.Files.Glob "files/indexes.conf").AsConfig | indent 2 }}
  {{ (.Files.Glob "files/otherfile.conf").AsConfig | indent 2 }}
# ... and so on

Where this would break down is if you want to be able to reference the values of variables inside the files so that the content is controlled from the values.yaml. If you want to expose each value individually then there's an example in the helm documentation using range. But I think a good fit or your case is what the stable/mysql chart does. It has a ConfigMap that takes values as strings:

{{- if .Values.configurationFiles }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "mysql.fullname" . }}-configuration
data:
{{- range $key, $val := .Values.configurationFiles }}
  {{ $key }}: |-
{{ $val | indent 4}}
{{- end }}
{{- end -}}

And the values.yaml allows both the files and their content to be set and overridden by the user of the chart:

# Custom mysql configuration files used to override default mysql settings
configurationFiles:
#  mysql.cnf: |-
#    [mysqld]
#    skip-name-resolve
#    ssl-ca=/ssl/ca.pem
#    ssl-cert=/ssl/server-cert.pem
#    ssl-key=/ssl/server-key.pem

It comments out that content and leaves it to the user of the chart to set but you could have defaults in the values.yaml.

You would only need tpl if you needed further flexibility. The stable/keycloak chart lets the user of the chart create their own configmap and point it into the keycloak deployment via tpl. But I think your case is probably closest to the mysql one.

Edit: the tpl function can also be used to take the content of files loaded with Files.Get and effectively make that content part of the template - see How do I load multiple templated config files into a helm chart? if you're interested in this

Share:
10,615

Related videos on Youtube

Nick Gleed
Author by

Nick Gleed

Updated on June 04, 2022

Comments

  • Nick Gleed
    Nick Gleed almost 2 years

    Im new at helm. Im building a splunk helm chart with numerous conf files. I currently use something like this in a configmap ..

        apiVersion: v1
    kind: ConfigMap
    metadata:
      name: splunk-master-configmap
    data:
      indexes.conf: |
        # global settings
        # Inheritable by all indexes: no hot/warm bucket can exceed 1 TB.
        # Individual indexes can override this setting.
        homePath.maxDataSizeMB = 1000000
    

    but I would prefer to have the conf files in a seperate folder e.g. configs/helloworld.conf and have come accross "tpl" but am struggling to understand how to implement it. - can anyone advise best practices. On a side note splunk has orders of presidences >> so there may be many indexes.conf files used in various locations. does anyone have any thoughts on how best to implement this?!??!

    Cheers.

  • Ryan Dawson
    Ryan Dawson over 5 years
    If you need to create a directory structure an approach might be to use subPaths for mounting them like in stackoverflow.com/a/49288088/9705485 Not entirely sure if that is what you're asking though.
  • Nick Gleed
    Nick Gleed over 5 years
    meant to say ...... Thanks - I might use the 1st approach - If I had numerous instances of the same named file >> indexes.conf which resided in various locations on the splunk dir structure, would it be applicable to recreate the dir structure in the files folder ? e.g. files/etc/apps/search/local/indexes.conf files/etc/apps/app1/local/indexes.conf files/etc/apps/app2/local/indexes.conf files/etc/system/local/indexes.conf
  • Ryan Dawson
    Ryan Dawson over 5 years
    I think you could follow the subPaths suggestion in order to do it if the files are required to be in those locations. I don't know whether the files are required to be in those locations. Perhaps that's a separate question about splunk and the structure of your apps. Are app1 and app2 specific apps and you'd want to update the splunk deployment if a new one were added or should the list of apps grow indefinitely without updating the splunk release?
  • Nick Gleed
    Nick Gleed over 5 years
    yeah - the gui of splunk places conf's into those (etc/apps/xxx/) paths pertinent to the index or tool you are using. The apps are likely to grow organically - but the deployment needs to be scriptable and as such gui changes need to reflected in helm deployment script. Alternatively global conf settings can be applied to etc/system/local..... this is a splunk thing - but thanks for your help - i love stackoverflow !!
  • Ryan Dawson
    Ryan Dawson over 5 years
    It sounds to me like the initial/global files could be set up using .Files.Glob and you could support injection of further configmaps that are mounted on subPaths of the user's choosing following much the same approach as the keycloak chart does for allowing users to inject their own custom realms. But I'm not entirely sure. If the files need to be created quickly in response to ui events then that sounds more like something that would need to be coded to write the files.