Skip to content

Commit 5224429

Browse files
committed
Updates to support imagePullSecret and registryPrefix
* Use the imagePullSecret to attach a secret to each deployment in the chart * Use the registryPrefix to replace ghcr.io/docker.io with your own prefix Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 44f6df4 commit 5224429

13 files changed

+104
-18
lines changed

chart/openfaas/templates/_helpers.tpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,38 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
4545
{{- define "openfaas.ingress.supportsPathType" -}}
4646
{{- or (eq (include "openfaas.ingress.isStable" .) "true") (and (eq (include "openfaas.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18.x" (include "openfaas.ingress.kubeVersion" .))) -}}
4747
{{- end -}}
48+
49+
{{/*
50+
Image helper that replaces registry with custom prefix if specified.
51+
Usage: {{ include "openfaas.image" (dict "image" .Values.someImage "registryPrefix" .Values.registryPrefix) }}
52+
*/}}
53+
{{- define "openfaas.image" -}}
54+
{{- $image := .image -}}
55+
{{- $registryPrefix := .registryPrefix -}}
56+
{{- if $registryPrefix -}}
57+
{{- if hasPrefix "docker.io/" $image -}}
58+
{{- printf "%s/%s" $registryPrefix (trimPrefix "docker.io/" $image) -}}
59+
{{- else if hasPrefix "ghcr.io/" $image -}}
60+
{{- printf "%s/%s" $registryPrefix (trimPrefix "ghcr.io/" $image) -}}
61+
{{- else if hasPrefix "quay.io/" $image -}}
62+
{{- printf "%s/%s" $registryPrefix (trimPrefix "quay.io/" $image) -}}
63+
{{- else if hasPrefix "registry.k8s.io/" $image -}}
64+
{{- printf "%s/%s" $registryPrefix (trimPrefix "registry.k8s.io/" $image) -}}
65+
{{- else if contains "/" $image -}}
66+
{{- /* Image has a registry, replace the first part */ -}}
67+
{{- $parts := splitList "/" $image -}}
68+
{{- if gt (len $parts) 2 -}}
69+
{{- /* More than 2 parts, replace first part */ -}}
70+
{{- printf "%s/%s" $registryPrefix (join "/" (rest $parts)) -}}
71+
{{- else -}}
72+
{{- /* Exactly 2 parts, keep the organization/repository structure */ -}}
73+
{{- printf "%s/%s" $registryPrefix $image -}}
74+
{{- end -}}
75+
{{- else -}}
76+
{{- /* No registry prefix, add our custom one */ -}}
77+
{{- printf "%s/%s" $registryPrefix $image -}}
78+
{{- end -}}
79+
{{- else -}}
80+
{{- $image -}}
81+
{{- end -}}
82+
{{- end -}}

chart/openfaas/templates/alertmanager-dep.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ spec:
2626
sidecar.istio.io/inject: "true"
2727
checksum/alertmanager-config: {{ include (print $.Template.BasePath "/alertmanager-cfg.yaml") . | sha256sum | quote }}
2828
spec:
29+
{{- with .Values.imagePullSecrets }}
30+
imagePullSecrets:
31+
{{- toYaml . | nindent 8 }}
32+
{{- end }}
2933
containers:
3034
- name: alertmanager
31-
image: {{ .Values.alertmanager.image }}
35+
image: {{ include "openfaas.image" (dict "image" .Values.alertmanager.image "registryPrefix" .Values.registryPrefix) }}
3236
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
3337
command:
3438
- "alertmanager"

chart/openfaas/templates/autoscaler-dep.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ spec:
2323
labels:
2424
app: autoscaler
2525
spec:
26+
{{- with .Values.imagePullSecrets }}
27+
imagePullSecrets:
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
2630
volumes:
2731
{{- if .Values.basic_auth }}
2832
- name: auth
@@ -36,7 +40,7 @@ spec:
3640
- name: autoscaler
3741
resources:
3842
{{- .Values.autoscaler.resources | toYaml | nindent 12 }}
39-
image: {{ .Values.autoscaler.image }}
43+
image: {{ include "openfaas.image" (dict "image" .Values.autoscaler.image "registryPrefix" .Values.registryPrefix) }}
4044
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
4145
command:
4246
- "/usr/bin/autoscaler"

chart/openfaas/templates/dashboard-dep.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ spec:
2222
labels:
2323
app: dashboard
2424
spec:
25+
{{- with .Values.imagePullSecrets }}
26+
imagePullSecrets:
27+
{{- toYaml . | nindent 8 }}
28+
{{- end }}
2529
volumes:
2630
{{- if .Values.basic_auth }}
2731
- name: auth
@@ -58,7 +62,7 @@ spec:
5862
- name: dashboard
5963
resources:
6064
{{- .Values.dashboard.resources | toYaml | nindent 12 }}
61-
image: {{ .Values.dashboard.image }}
65+
image: {{ include "openfaas.image" (dict "image" .Values.dashboard.image "registryPrefix" .Values.registryPrefix) }}
6266
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
6367

6468
command:

chart/openfaas/templates/event-worker-dep.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ spec:
2424
labels:
2525
app: event-worker
2626
spec:
27+
{{- with .Values.imagePullSecrets }}
28+
imagePullSecrets:
29+
{{- toYaml . | nindent 8 }}
30+
{{- end }}
2731
volumes:
2832
- name: license
2933
secret:
@@ -37,7 +41,7 @@ spec:
3741
- name: event-worker
3842
resources:
3943
{{- .Values.eventWorker.resources | toYaml | nindent 12 }}
40-
image: {{ .Values.eventWorker.image }}
44+
image: {{ include "openfaas.image" (dict "image" .Values.eventWorker.image "registryPrefix" .Values.registryPrefix) }}
4145
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
4246
command:
4347
- "event-worker"

chart/openfaas/templates/gateway-dep.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ spec:
3030
labels:
3131
app: gateway
3232
spec:
33+
{{- with .Values.imagePullSecrets }}
34+
imagePullSecrets:
35+
{{- toYaml . | nindent 8 }}
36+
{{- end }}
3337
{{- if and .Values.gateway.topologySpreadConstraints .Values.openfaasPro }}
3438
topologySpreadConstraints:
3539
{{- toYaml .Values.gateway.topologySpreadConstraints | nindent 8 }}
@@ -70,9 +74,9 @@ spec:
7074
resources:
7175
{{- .Values.gateway.resources | toYaml | nindent 12 }}
7276
{{- if .Values.openfaasPro }}
73-
image: {{ .Values.gatewayPro.image }}
77+
image: {{ include "openfaas.image" (dict "image" .Values.gatewayPro.image "registryPrefix" .Values.registryPrefix) }}
7478
{{- else }}
75-
image: {{ .Values.gateway.image }}
79+
image: {{ include "openfaas.image" (dict "image" .Values.gateway.image "registryPrefix" .Values.registryPrefix) }}
7680
{{- end }}
7781
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
7882
command:
@@ -233,7 +237,7 @@ spec:
233237
- name: operator
234238
resources:
235239
{{- .Values.operator.resources | toYaml | nindent 12 }}
236-
image: {{ .Values.operator.image }}
240+
image: {{ include "openfaas.image" (dict "image" .Values.operator.image "registryPrefix" .Values.registryPrefix) }}
237241
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
238242
command:
239243
- ./faas-netes
@@ -355,11 +359,11 @@ spec:
355359
resources:
356360
{{- .Values.faasnetes.resources | toYaml | nindent 12 }}
357361
{{- if .Values.openfaasPro }}
358-
image: {{ .Values.faasnetesPro.image }}
362+
image: {{ include "openfaas.image" (dict "image" .Values.faasnetesPro.image "registryPrefix" .Values.registryPrefix) }}
359363
{{- else if .Values.oem }}
360-
image: {{ .Values.faasnetesOem.image}}
364+
image: {{ include "openfaas.image" (dict "image" .Values.faasnetesOem.image "registryPrefix" .Values.registryPrefix) }}
361365
{{- else }}
362-
image: {{ .Values.faasnetes.image }}
366+
image: {{ include "openfaas.image" (dict "image" .Values.faasnetes.image "registryPrefix" .Values.registryPrefix) }}
363367
{{- end }}
364368
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
365369
{{- if .Values.securityContext }}

chart/openfaas/templates/ingress-operator-dep.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ spec:
2323
labels:
2424
app: ingress-operator
2525
spec:
26+
{{- with .Values.imagePullSecrets }}
27+
imagePullSecrets:
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
2630
serviceAccountName: ingress-operator
2731
containers:
2832
- name: operator
2933
resources:
3034
{{- .Values.ingressOperator.resources | toYaml | nindent 10 }}
31-
image: {{ .Values.ingressOperator.image }}
35+
image: {{ include "openfaas.image" (dict "image" .Values.ingressOperator.image "registryPrefix" .Values.registryPrefix) }}
3236
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
3337
command:
3438
- ./ingress-operator

chart/openfaas/templates/jetstream-queueworker-dep.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ spec:
2323
labels:
2424
app: queue-worker
2525
spec:
26+
{{- with .Values.imagePullSecrets }}
27+
imagePullSecrets:
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
2630
{{- if and .Values.jetstreamQueueWorker.topologySpreadConstraints .Values.openfaasPro }}
2731
topologySpreadConstraints:
2832
{{- toYaml .Values.jetstreamQueueWorker.topologySpreadConstraints | nindent 8 }}
@@ -37,7 +41,7 @@ spec:
3741
- name: queue-worker
3842
resources:
3943
{{- .Values.queueWorker.resources | toYaml | nindent 12 }}
40-
image: {{ .Values.jetstreamQueueWorker.image }}
44+
image: {{ include "openfaas.image" (dict "image" .Values.jetstreamQueueWorker.image "registryPrefix" .Values.registryPrefix) }}
4145
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
4246
{{- if .Values.jetstreamQueueWorker.pprof }}
4347
ports:

chart/openfaas/templates/nats-dep.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ spec:
2222
labels:
2323
app: nats
2424
spec:
25+
{{- with .Values.imagePullSecrets }}
26+
imagePullSecrets:
27+
{{- toYaml . | nindent 8 }}
28+
{{- end }}
2529
containers:
2630
- name: nats
2731
resources:
2832
{{- .Values.nats.resources | toYaml | nindent 12 }}
2933
{{- if eq .Values.queueMode "jetstream" }}
30-
image: {{ .Values.nats.image }}
34+
image: {{ include "openfaas.image" (dict "image" .Values.nats.image "registryPrefix" .Values.registryPrefix) }}
3135
{{- else }}
32-
image: {{ .Values.stan.image }}
36+
image: {{ include "openfaas.image" (dict "image" .Values.stan.image "registryPrefix" .Values.registryPrefix) }}
3337
{{- end }}
3438
imagePullPolicy: {{ .Values.openfaasImagePullPolicy }}
3539
ports:

chart/openfaas/templates/oidc-plugin-dep.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ spec:
2424
labels:
2525
app: oidc-plugin
2626
spec:
27+
{{- with .Values.imagePullSecrets }}
28+
imagePullSecrets:
29+
{{- toYaml . | nindent 8 }}
30+
{{- end }}
2731
serviceAccountName: oidc-plugin
2832
volumes:
2933
- name: oidc-plugin-temp-volume
@@ -48,7 +52,7 @@ spec:
4852
- name: oidc-plugin
4953
resources:
5054
{{- .Values.oidcAuthPlugin.resources | toYaml | nindent 12 }}
51-
image: {{ .Values.oidcAuthPlugin.image }}
55+
image: {{ include "openfaas.image" (dict "image" .Values.oidcAuthPlugin.image "registryPrefix" .Values.registryPrefix) }}
5256
imagePullPolicy: Always
5357
{{- if .Values.securityContext }}
5458
securityContext:

0 commit comments

Comments
 (0)