Skip to content

Commit

Permalink
feat: Add image registry to global values
Browse files Browse the repository at this point in the history
  • Loading branch information
fhielpos committed Oct 11, 2023
1 parent 4cabc3c commit 989b8ad
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 17 deletions.
5 changes: 3 additions & 2 deletions charts/kyverno/templates/_helpers/_image.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
{{- if not (typeIs "string" $tag) -}}
{{ fail "Image tags must be strings." }}
{{- end -}}
{{- if .image.registry -}}
{{- print .image.registry "/" (required "An image repository is required" .image.repository) ":" $tag -}}
{{- $imageRegistry := default .image.registry .globalRegistry -}}
{{- if $imageRegistry -}}
{{- print $imageRegistry "/" (required "An image repository is required" .image.repository) ":" $tag -}}
{{- else -}}
{{- print (required "An image repository is required" .image.repository) ":" $tag -}}
{{- end -}}
Expand Down
4 changes: 2 additions & 2 deletions charts/kyverno/templates/admission-controller/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
- name: kyverno-pre
image: {{ include "kyverno.image" (dict "image" .Values.admissionController.initContainer.image "defaultTag" (default .Chart.AppVersion .Values.admissionController.container.image.tag)) | quote }}
image: {{ include "kyverno.image" (dict "globalRegistry" ((.Values.global).image).registry "image" .Values.admissionController.initContainer.image "defaultTag" (default .Chart.AppVersion .Values.admissionController.container.image.tag)) | quote }}
imagePullPolicy: {{ default .Values.admissionController.container.image.pullPolicy .Values.admissionController.initContainer.image.pullPolicy }}
args:
{{- include "kyverno.features.flags" (pick (mergeOverwrite .Values.features .Values.admissionController.featuresOverride)
Expand Down Expand Up @@ -124,7 +124,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
- name: kyverno
image: {{ include "kyverno.image" (dict "image" .Values.admissionController.container.image "defaultTag" .Chart.AppVersion) | quote }}
image: {{ include "kyverno.image" (dict "globalRegistry" ((.Values.global).image).registry "image" .Values.admissionController.container.image "defaultTag" .Chart.AppVersion) | quote }}
imagePullPolicy: {{ .Values.admissionController.container.image.pullPolicy }}
args:
- --caSecretName={{ template "kyverno.admission-controller.serviceName" . }}.{{ template "kyverno.namespace" . }}.svc.kyverno-tls-ca
Expand Down
5 changes: 3 additions & 2 deletions charts/kyverno/templates/background-controller/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
{{- end -}}

{{- define "kyverno.background-controller.image" -}}
{{- if .image.registry -}}
{{ .image.registry }}/{{ required "An image repository is required" .image.repository }}:{{ default .defaultTag .image.tag }}
{{- $imageRegistry := default .image.registry .globalRegistry -}}
{{- if $imageRegistry -}}
{{ $imageRegistry }}/{{ required "An image repository is required" .image.repository }}:{{ default .defaultTag .image.tag }}
{{- else -}}
{{ required "An image repository is required" .image.repository }}:{{ default .defaultTag .image.tag }}
{{- end -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spec:
serviceAccountName: {{ template "kyverno.background-controller.serviceAccountName" . }}
containers:
- name: controller
image: {{ include "kyverno.background-controller.image" (dict "image" .Values.backgroundController.image "defaultTag" .Chart.AppVersion) | quote }}
image: {{ include "kyverno.background-controller.image" (dict "globalRegistry" ((.Values.global).image).registry "image" .Values.backgroundController.image "defaultTag" .Chart.AppVersion) | quote }}
imagePullPolicy: {{ .Values.backgroundController.image.pullPolicy }}
ports:
- containerPort: 9443
Expand Down
5 changes: 3 additions & 2 deletions charts/kyverno/templates/cleanup-controller/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
{{- end -}}

{{- define "kyverno.cleanup-controller.image" -}}
{{- if .image.registry -}}
{{ .image.registry }}/{{ required "An image repository is required" .image.repository }}:{{ default .defaultTag .image.tag }}
{{- $imageRegistry := default .image.registry .globalRegistry -}}
{{- if $imageRegistry -}}
{{ $imageRegistry }}/{{ required "An image repository is required" .image.repository }}:{{ default .defaultTag .image.tag }}
{{- else -}}
{{ required "An image repository is required" .image.repository }}:{{ default .defaultTag .image.tag }}
{{- end -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spec:
serviceAccountName: {{ template "kyverno.cleanup-controller.serviceAccountName" . }}
containers:
- name: controller
image: {{ include "kyverno.cleanup-controller.image" (dict "image" .Values.cleanupController.image "defaultTag" .Chart.AppVersion) | quote }}
image: {{ include "kyverno.cleanup-controller.image" (dict "globalRegistry" ((.Values.global).image).registry "image" .Values.cleanupController.image "defaultTag" .Chart.AppVersion) | quote }}
imagePullPolicy: {{ .Values.cleanupController.image.pullPolicy }}
ports:
- containerPort: 9443
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
{{- end }}
containers:
- name: cleanup
image: {{ (include "kyverno.image" .Values.cleanupJobs.admissionReports) | quote }}
image: {{ (include "kyverno.image" (dict "globalRegistry" ((.Values.global).image).registry "image" .Values.cleanupJobs.admissionReports.image)) | quote }}
imagePullPolicy: {{ .Values.cleanupJobs.admissionReports.image.pullPolicy }}
command:
- /bin/sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
{{- end }}
containers:
- name: cleanup
image: {{ (include "kyverno.image" .Values.cleanupJobs.clusterAdmissionReports) | quote }}
image: {{ (include "kyverno.image" (dict "globalRegistry" ((.Values.global).image).registry "image" .Values.cleanupJobs.clusterAdmissionReports.image)) | quote }}
imagePullPolicy: {{ .Values.cleanupJobs.clusterAdmissionReports.image.pullPolicy }}
command:
- /bin/sh
Expand Down
3 changes: 2 additions & 1 deletion charts/kyverno/templates/hooks/pre-delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ spec:
{{- end }}
containers:
- name: kubectl
image: {{ .Values.webhooksCleanup.image }}
image: {{ (include "kyverno.image" (dict "globalRegistry" ((.Values.global).image).registry "image" .Values.webhooksCleanup.image "defaultTag" (default .Chart.AppVersion .Values.webhooksCleanup.image.tag))) | quote }}
imagePullPolicy: {{ .Values.webhooksCleanup.image.pullPolicy }}
command:
- sh
- '-c'
Expand Down
5 changes: 3 additions & 2 deletions charts/kyverno/templates/reports-controller/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
{{- end -}}

{{- define "kyverno.reports-controller.image" -}}
{{- if .image.registry -}}
{{ .image.registry }}/{{ required "An image repository is required" .image.repository }}:{{ default .defaultTag .image.tag }}
{{- $imageRegistry := default .image.registry .globalRegistry -}}
{{- if $imageRegistry -}}
{{ $imageRegistry }}/{{ required "An image repository is required" .image.repository }}:{{ default .defaultTag .image.tag }}
{{- else -}}
{{ required "An image repository is required" .image.repository }}:{{ default .defaultTag .image.tag }}
{{- end -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spec:
serviceAccountName: {{ template "kyverno.reports-controller.serviceAccountName" . }}
containers:
- name: controller
image: {{ include "kyverno.reports-controller.image" (dict "image" .Values.reportsController.image "defaultTag" .Chart.AppVersion) | quote }}
image: {{ include "kyverno.reports-controller.image" (dict "globalRegistry" ((.Values.global).image).registry "image" .Values.reportsController.image "defaultTag" .Chart.AppVersion) | quote }}
imagePullPolicy: {{ .Values.reportsController.image.pullPolicy }}
ports:
- containerPort: 9443
Expand Down
17 changes: 16 additions & 1 deletion charts/kyverno/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ templating:
debug: false
version: ~

# -- Global value that allows to set a single image registry across all deployments
global:
image:
registry: "ghcr.io"

# -- (string) Override the name of the chart
nameOverride: ~

Expand Down Expand Up @@ -308,7 +313,17 @@ webhooksCleanup:
enabled: true

# -- `kubectl` image to run commands for deleting webhooks.
image: bitnami/kubectl:latest
image:
# -- (string) Image registry
registry: ~
# -- Image repository
repository: bitnami/kubectl
# -- Image tag
# Defaults to `latest` if omitted
tag: '1.26.4'
# -- (string) Image pull policy
# Defaults to image.pullPolicy if omitted
pullPolicy: ~

# -- Image pull secrets
imagePullSecrets: []
Expand Down

0 comments on commit 989b8ad

Please sign in to comment.