Skip to content

Commit af767b3

Browse files
feat(gateway-helm-chart): add wso2.subscription.imagePullSecret
Adds a one-knob shorthand for switching the gateway helm chart from the public GHCR images to the WSO2 private registry. Setting `wso2.subscription.imagePullSecret` to the name of a docker-registry Secret causes the chart to: 1. Inject that secret into every component's imagePullSecrets, additively with the existing global and per-component lists. 2. Rewrite each component's image.repository whose value still starts with `ghcr.io/wso2/api-platform/` to `registry.wso2.com/wso2-api-platform/`. Explicit overrides pass through untouched. Credentials are intentionally not accepted in values.yaml — users create the docker-registry Secret out-of-band, keeping subscription credentials out of Helm release state. Default behavior is unchanged when the field is empty. Fixes #2016
1 parent ef223a9 commit af767b3

4 files changed

Lines changed: 71 additions & 18 deletions

File tree

kubernetes/helm/gateway-helm-chart/templates/_helpers.tpl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,50 @@ app.kubernetes.io/component: {{ $component }}
6060
{{- default "default" .Values.serviceAccount.name -}}
6161
{{- end -}}
6262
{{- end -}}
63+
64+
{{/*
65+
Render a component image reference, applying the WSO2 subscription registry rewrite
66+
when wso2.subscription.imagePullSecret is set AND the repository still matches the
67+
default upstream prefix `ghcr.io/wso2/api-platform/`. Explicit overrides pass through.
68+
69+
Args (dict): root, repository, tag
70+
*/}}
71+
{{- define "gateway-operator.componentImage" -}}
72+
{{- $root := .root -}}
73+
{{- $repo := .repository -}}
74+
{{- $tag := .tag -}}
75+
{{- $sub := $root.Values.wso2.subscription.imagePullSecret -}}
76+
{{- $defaultPrefix := "ghcr.io/wso2/api-platform/" -}}
77+
{{- $wso2Prefix := "registry.wso2.com/wso2-api-platform/" -}}
78+
{{- if and (ne $sub "") (hasPrefix $defaultPrefix $repo) -}}
79+
{{- printf "%s%s:%s" $wso2Prefix (trimPrefix $defaultPrefix $repo) $tag -}}
80+
{{- else -}}
81+
{{- printf "%s:%s" $repo $tag -}}
82+
{{- end -}}
83+
{{- end -}}
84+
85+
{{/*
86+
Render an `imagePullSecrets:` YAML block (without indentation) by merging:
87+
1. wso2.subscription.imagePullSecret (if set)
88+
2. .Values.imagePullSecrets (global)
89+
3. component-level imagePullSecrets (passed in)
90+
91+
Returns an empty string when no secrets resolve, so callers can wrap in
92+
`{{- with (include ...) }} {{- . | nindent N }} {{- end }}`.
93+
94+
Args (dict): root, componentPullSecrets
95+
*/}}
96+
{{- define "gateway-operator.componentImagePullSecretsBlock" -}}
97+
{{- $root := .root -}}
98+
{{- $componentPullSecrets := default (list) .componentPullSecrets -}}
99+
{{- $globalPullSecrets := default (list) $root.Values.imagePullSecrets -}}
100+
{{- $sub := $root.Values.wso2.subscription.imagePullSecret -}}
101+
{{- $subList := ternary (list $sub) (list) (ne $sub "") -}}
102+
{{- $all := concat $subList $globalPullSecrets $componentPullSecrets -}}
103+
{{- if $all -}}
104+
imagePullSecrets:
105+
{{- range $all }}
106+
- name: {{ . }}
107+
{{- end }}
108+
{{- end -}}
109+
{{- end -}}

kubernetes/helm/gateway-helm-chart/templates/gateway/controller/deployment.yaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,8 @@ spec:
4242
{{- end }}
4343
spec:
4444
serviceAccountName: {{ include "gateway-operator.serviceAccountName" . }}
45-
{{- $globalPullSecrets := default (list) .Values.imagePullSecrets }}
46-
{{- $componentPullSecrets := default (list) $controller.imagePullSecrets }}
47-
{{- $pullSecrets := concat $globalPullSecrets $componentPullSecrets }}
48-
{{- if $pullSecrets }}
49-
imagePullSecrets:
50-
{{- range $pullSecrets }}
51-
- name: {{ . }}
52-
{{- end }}
45+
{{- with (include "gateway-operator.componentImagePullSecretsBlock" (dict "root" . "componentPullSecrets" $controller.imagePullSecrets)) }}
46+
{{- . | nindent 6 }}
5347
{{- end }}
5448
{{- with $deployment.podSecurityContext }}
5549
securityContext:
@@ -72,7 +66,7 @@ spec:
7266
{{- end }}
7367
containers:
7468
- name: gateway-controller
75-
image: "{{ $controller.image.repository }}:{{ $controller.image.tag }}"
69+
image: {{ include "gateway-operator.componentImage" (dict "root" . "repository" $controller.image.repository "tag" $controller.image.tag) | quote }}
7670
imagePullPolicy: {{ $controller.image.pullPolicy }}
7771
{{- with $deployment.securityContext }}
7872
securityContext:

kubernetes/helm/gateway-helm-chart/templates/gateway/gateway-runtime/deployment.yaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,8 @@ spec:
3939
{{- end }}
4040
spec:
4141
serviceAccountName: {{ include "gateway-operator.serviceAccountName" . }}
42-
{{- $globalPullSecrets := default (list) .Values.imagePullSecrets }}
43-
{{- $componentPullSecrets := default (list) $unified.imagePullSecrets }}
44-
{{- $pullSecrets := concat $globalPullSecrets $componentPullSecrets }}
45-
{{- if $pullSecrets }}
46-
imagePullSecrets:
47-
{{- range $pullSecrets }}
48-
- name: {{ . }}
49-
{{- end }}
42+
{{- with (include "gateway-operator.componentImagePullSecretsBlock" (dict "root" . "componentPullSecrets" $unified.imagePullSecrets)) }}
43+
{{- . | nindent 6 }}
5044
{{- end }}
5145
{{- with $deployment.podSecurityContext }}
5246
securityContext:
@@ -69,7 +63,7 @@ spec:
6963
{{- end }}
7064
containers:
7165
- name: gateway-runtime
72-
image: "{{ $unified.image.repository }}:{{ $unified.image.tag }}"
66+
image: {{ include "gateway-operator.componentImage" (dict "root" . "repository" $unified.image.repository "tag" $unified.image.tag) | quote }}
7367
imagePullPolicy: {{ $unified.image.pullPolicy }}
7468
args: ["--pol.config", "/etc/policy-engine/config.toml"]
7569
{{- with $deployment.securityContext }}

kubernetes/helm/gateway-helm-chart/values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ fullnameOverride: ""
66

77
imagePullSecrets: []
88

9+
# WSO2 Subscription parameters (https://wso2.com/subscription/)
10+
wso2:
11+
subscription:
12+
# Name of a docker-registry Secret (in the release namespace) holding credentials
13+
# for registry.wso2.com. Setting this enables WSO2 subscription mode:
14+
# 1. The secret is added to every component's imagePullSecrets.
15+
# 2. Default `ghcr.io/wso2/api-platform/*` image repositories are rewritten to
16+
# `registry.wso2.com/wso2-api-platform/*`, so the released WSO2 images at
17+
# https://docker.wso2.com/ are pulled instead.
18+
# Explicit image.repository overrides are preserved as-is.
19+
#
20+
# Create the secret with:
21+
# kubectl create secret docker-registry wso2-subscription-creds \
22+
# --docker-server=registry.wso2.com \
23+
# --docker-username=<wso2-email> \
24+
# --docker-password=<wso2-password-or-token>
25+
imagePullSecret: ""
26+
927
commonLabels: {}
1028
commonAnnotations: {}
1129

0 commit comments

Comments
 (0)