kustomize: add imagePullSecrets to all deployments
You could use patches
field instead of patchesStrategicMerge
in order to patch multiple resources.
Based on this demo example you can do this by specifiyng patch and target selector:
patches:- path: <PatchFile> target: group: <Group> version: <Version> kind: <Kind> name: <Name> namespace: <Namespace> labelSelector: <LabelSelector> annotationSelector: <AnnotationSelector>
In this case your kustomization.yaml
should look like this:
bases: - ../basepatches:- path: regcred-1.yaml target: kind: Deployment
Let me know if that solved your case.
Something like this seems to work to append an imagePullSecret
:
patches: - target: kind: Deployment patch: |- - op: add path: /spec/template/spec/imagePullSecrets/- value: name: regcred - target: kind: CronJob patch: |- - op: replace path: /spec/jobTemplate/spec/template/spec/imagePullSecrets value: - name: regcred
Or more simply, you can just run this once:
kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "regcred"}]}'
Using Inline Patch:
kind: KustomizationapiVersion: kustomize.config.k8s.io/v1beta1resources: - ../../basepatches: - target: kind: Deployment patch: |- - op: add path: /spec/template/spec/imagePullSecrets value: [{ name: image-pull-secret }]
Reference: Patching multiple resources at once.