Skip to content

Commit daf0a5a

Browse files
committed
support custom imagePullSecrets in CSI ServiceAccounts
sample usage: CSI_IMAGE_PULL_SECRETS="secret-1" make build-installer helm template csi deploy/charts/ceph-csi-drivers --set 'csiImagePullSecrets={secret-1}' Signed-off-by: Leela Venkaiah G <lgangava@ibm.com>
1 parent 2587c60 commit daf0a5a

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ NAME_PREFIX ?= ceph-csi-operator-
99
NAMESPACE ?= $(NAME_PREFIX)system
1010
# A comma separated list of namespaces for operator to cache objects from
1111
WATCH_NAMESPACE ?= ""
12+
# A comma separated list of imagepullsecret names that will be added to all CSI deployments and daemonsets
13+
CSI_IMAGE_PULL_SECRETS ?=
1214

1315
IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)
1416

@@ -35,6 +37,8 @@ SHELL = /usr/bin/env bash -o pipefail
3537

3638
# Define the content of the temporary top-most kustomize overlay for the
3739
# build-installer, build-multifile-installer and deploy targets
40+
# Awk statement converts comma-separated secrets to JSON array of objects
41+
# ie, "secret-1,secret-2" -> [{"name": "secret-1", "name": "secret-2"}]
3842
define BUILD_INSTALLER_OVERLAY
3943
apiVersion: kustomize.config.k8s.io/v1beta1
4044
kind: Kustomization
@@ -55,6 +59,14 @@ patches:
5559
target:
5660
kind: Deployment
5761
name: controller-manager
62+
$(if $(CSI_IMAGE_PULL_SECRETS),
63+
- patch: |-
64+
- op: add
65+
path: /imagePullSecrets
66+
value: [$(shell echo -n "$(CSI_IMAGE_PULL_SECRETS)" | awk -F',' '{for(i=1;i<=NF;i++) printf "%s{\"name\": \"%s\"}", (i>1?", ":""), $$i}')]
67+
target:
68+
kind: ServiceAccount
69+
)
5870
images:
5971
- name: controller
6072
newName: ${IMG}
@@ -71,6 +83,15 @@ namespace: $(NAMESPACE)
7183
namePrefix: $(NAME_PREFIX)
7284
resources:
7385
- ../config/csi-rbac
86+
$(if $(CSI_IMAGE_PULL_SECRETS),
87+
patches:
88+
- patch: |-
89+
- op: add
90+
path: /imagePullSecrets
91+
value: [$(shell echo -n "$(CSI_IMAGE_PULL_SECRETS)" | awk -F',' '{for(i=1;i<=NF;i++) printf "%s{\"name\": \"%s\"}", (i>1?", ":""), $$i}')]
92+
target:
93+
kind: ServiceAccount
94+
)
7495
endef
7596
export BUILD_CSI_RBAC_OVERLAY
7697

deploy/charts/ceph-csi-drivers/templates/serviceaccount.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@ kind: ServiceAccount
88
metadata:
99
name: {{ $normalizedDriverName }}-ctrlplugin-sa
1010
namespace: {{ $root.Release.Namespace }}
11+
{{- if gt (len $root.Values.csiImagePullSecrets) 0 }}
12+
imagePullSecrets:
13+
{{ range $pullSecret := $root.Values.csiImagePullSecrets -}}
14+
- name: {{ $pullSecret }}
15+
{{- end }}
16+
{{- end }}
1117
---
1218
apiVersion: v1
1319
kind: ServiceAccount
1420
metadata:
1521
name: {{ $normalizedDriverName }}-nodeplugin-sa
1622
namespace: {{ $root.Release.Namespace }}
23+
{{- if gt (len $root.Values.csiImagePullSecrets) 0 }}
24+
imagePullSecrets:
25+
{{- range $pullSecret := $root.Values.csiImagePullSecrets -}}
26+
- name: {{ $pullSecret }}
27+
{{- end }}
28+
{{- end }}
1729
{{- end }}
1830
{{- end }}

deploy/charts/ceph-csi-drivers/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,6 @@ drivers:
474474

475475
# List of tolerations for the controller plugin
476476
tolerations: []
477+
478+
# List of pull secret names that will be added to all csi serviceaccounts
479+
csiImagePullSecrets: []

docs/helm-charts/drivers-chart.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The following table lists the configurable parameters of the ceph-csi-drivers ch
5656
| `clientProfiles[0].cephFs.subVolumeGroup` | | `""` |
5757
| `clientProfiles[0].name` | | `""` |
5858
| `clientProfiles[0].rbd.radosNamespace` | | `""` |
59+
| `csiImagePullSecrets` | | `[]` |
5960
| `drivers.cephfs.attachRequired` | | `true` |
6061
| `drivers.cephfs.cephFsClientType` | | `"kernel"` |
6162
| `drivers.cephfs.clusterName` | | `""` |

0 commit comments

Comments
 (0)