Overriding a Bitnami Subchart

With Bitnami moving to a paid model, we migrated all of our existing Bitnami OSS items to the bitnamilegacy repository. One issue we ran into though, even though Elasticsearch itself migrated to bitnamilegacy, any underlying images it was using are still from the regular Bitnami repository since there has been no new release to perform migration under the hood.

As part of its initContainers, Elastic pulls in os-shell. The question became, how do we specify a different repository for os-shell when we are pulling in the chart externally (and not pulling from disk ourselves). The solution was deceptively simple:

elasticsearch:
  sysctlImage:
    repository: bitnamilegacy/os-shell

What this hides is the rube goldberg machine Bitnami setup to process the above into an image/repository/tag setting you would normally see:

Unpacking the elasticsearch helm chart, we find in
templates/ingest/statefulset.yaml:

      initContainers:
        {{- if and .Values.sysctlImage.enabled .Values.enableDefaultInitContainers }}
        ## Image that performs the sysctl operation to modify Kernel settings (needed sometimes to avoid boot errors)
        - name: sysctl
          image: {{ include "elasticsearch.sysctl.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
          command:
            - /bin/bash
            - -ec
            - |
              {{- include "elasticsearch.sysctlIfLess" (dict "key" "vm.max_map_count" "value" "262144") | nindent 14 }}
              {{- include "elasticsearch.sysctlIfLess" (dict "key" "fs.file-max" "value" "65536") | nindent 14 }}
          securityContext:
            privileged: true
            runAsUser: 0
          {{- if .Values.sysctlImage.resources }}
          resources: {{- toYaml .Values.sysctlImage.resources | nindent 12 }}
          {{- else if ne .Values.sysctlImage.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.sysctlImage.resourcesPreset) | nindent 12 }}
          {{- end }}

You might think that we then need:

elasticsearch:
  sysctlImage:
    enabled: true
  sysctl:
    image: ...

But no! That is a helper function!

In templates/_helpers.tpl:

{{/*
Return the proper sysctl image name
*/}}
{{- define "elasticsearch.sysctl.image" -}}
{{ include "common.images.image" (dict "imageRoot" .Values.sysctlImage "global" .Values.global) }}
{{- end -}} 

But wait, what is "common.images.image"!?

Another template that comes from the bitnami-common chart:

{{- define "common.images.image" -}}
{{- $registryName := default .imageRoot.registry ((.global).imageRegistry) -}}
{{- $repositoryName := .imageRoot.repository -}}
{{- $separator := ":" -}}
{{- $termination := .imageRoot.tag | toString -}}

{{- if not .imageRoot.tag }}
  {{- if .chart }}
    {{- $termination = .chart.AppVersion | toString -}}
  {{- end -}}
{{- end -}}
{{- if .imageRoot.digest }}
    {{- $separator = "@" -}}
    {{- $termination = .imageRoot.digest | toString -}}
{{- end -}}
{{- if $registryName }}
    {{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}}
{{- else -}}
    {{- printf "%s%s%s"  $repositoryName $separator $termination -}}
{{- end -}}
{{- end -}}

Yaml is the worst.