Skip to content

Commit

Permalink
update helm charts for helm-dashboard
Browse files Browse the repository at this point in the history
1. fix `imagePullSecrets` bug in deployment.yaml
2. add `global` config
3. optimize image field with global registry config
  • Loading branch information
warjiang committed Nov 7, 2023
1 parent 4c84b79 commit aaadfbb
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
51 changes: 51 additions & 0 deletions charts/helm-dashboard/templates/_commons.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Return the proper image name
{{ include "common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global ) }}
*/}}
{{- define "common.images.image" -}}
{{- $registryName := .imageRoot.registry -}}
{{- $repositoryName := .imageRoot.repository -}}
{{- $separator := ":" -}}
{{- $termination := .imageRoot.tag | toString -}}
{{- if .global }}
{{- if .global.imageRegistry }}
{{- $registryName = .global.imageRegistry -}}
{{- 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 -}}

{{/*
Return the proper Docker Image Registry Secret Names (deprecated: use common.images.renderPullSecrets instead)
{{ include "common.images.pullSecrets" ( dict "images" (list .Values.path.to.the.image1, .Values.path.to.the.image2) "global" .Values.global) }}
*/}}
{{- define "common.images.pullSecrets" -}}
{{- $pullSecrets := list }}

{{- if .global }}
{{- range .global.imagePullSecrets -}}
{{- $pullSecrets = append $pullSecrets . -}}
{{- end -}}
{{- end -}}

{{- range .images -}}
{{- range .pullSecrets -}}
{{- $pullSecrets = append $pullSecrets . -}}
{{- end -}}
{{- end -}}

{{- if (not (empty $pullSecrets)) }}
imagePullSecrets:
{{- range $pullSecrets }}
- name: {{ . }}
{{- end }}
{{- end }}
{{- end -}}
28 changes: 28 additions & 0 deletions charts/helm-dashboard/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,31 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Return the proper image Registry Secret Names
*/}}
{{- define "helm-dashboard.imagePullSecrets" -}}
{{ include "common.images.pullSecrets" (dict "images" (list .Values.image) "global" .Values.global) }}
{{- end -}}


{{/*
Return the proper image name
*/}}
{{- define "helm-dashboard.image" -}}
{{- $image := .Values.image -}}
{{- $tag := .Chart.AppVersion -}}
{{- if $image.tag -}}
{{- $tag = $image.tag -}}
{{- end -}}
{{- $_ := set $image "tag" $tag -}}
{{ include "common.images.image" (dict "imageRoot" $_ "global" .Values.global) }}
{{- end -}}

{{/*
Return the proper image name
*/}}
{{- define "test.image" -}}
{{ include "common.images.image" (dict "imageRoot" .Values.testImage "global" .Values.global) }}
{{- end -}}
7 changes: 2 additions & 5 deletions charts/helm-dashboard/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ spec:
labels:
{{- include "helm-dashboard.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "helm-dashboard.imagePullSecrets" . | nindent 6 }}
serviceAccountName: {{ include "helm-dashboard.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
Expand All @@ -38,7 +35,7 @@ spec:
{{- end }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
image: "{{ include "helm-dashboard.image" . }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: HELM_CACHE_HOME
Expand Down
3 changes: 2 additions & 1 deletion charts/helm-dashboard/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ metadata:
annotations:
"helm.sh/hook": test
spec:
{{- include "helm-dashboard.imagePullSecrets" . | nindent 2 }}
containers:
- name: wget
image: busybox
image: {{ include "test.image" . }}
command: ['wget']
args: ['--timeout=5', '{{ include "helm-dashboard.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
23 changes: 22 additions & 1 deletion charts/helm-dashboard/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ replicaCount: 1
# Flag for setting environment to debug mode
debug: false

global:
## @param global.imageRegistry Global Docker image registry
imageRegistry: ""
## Optionally specify an array of imagePullSecrets.
## Example:
## imagePullSecrets:
## - myRegistryKeySecretName
imagePullSecrets: []

image:
repository: komodorio/helm-dashboard
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""
imagePullSecrets: []

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

Expand Down Expand Up @@ -119,3 +128,15 @@ tolerations: []

affinity: {}


testImage:
repository: busybox
tag: latest
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
# tag: ""
## Optionally specify an array of imagePullSecrets.
## Example:
## imagePullSecrets:
## - myRegistryKeySecretName
imagePullSecrets: []

0 comments on commit aaadfbb

Please sign in to comment.