Skip to content

Instantly share code, notes, and snippets.

@MadVikingGod
Created January 28, 2020 16:33
Show Gist options
  • Save MadVikingGod/d75e2907ab54154194b29e10659d7fc4 to your computer and use it in GitHub Desktop.
Save MadVikingGod/d75e2907ab54154194b29e10659d7fc4 to your computer and use it in GitHub Desktop.
Kustomize secret generator merge
#ghist wont let me use sub dirs so here we go
mkdir -p base works doesnt-work/responsibility
cat >base/kustomization.yaml <<EOF
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
secretGenerator:
- name: secret
literals:
- SECRET1=super secret
- SECRET2=only kind of secret
EOF
cat >works/kustomization.yaml <<EOF
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
secretGenerator:
- name: secret
literals:
- SECRET2=overwrite this secret
behavior: merge
EOF
cat >doesnt-work/kustomization.yaml <<EOF
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
- responsibility
EOF
cat >doesnt-work/responsibility/kustomization.yaml <<EOF
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
secretGenerator:
- name: secret
literals:
- SECRET2=overwrite this secret
behavior: merge
EOF
#wase and works will run successfully
kustomize build base
kustomize build works
#if you don't use merge you get this error as expected
kustomize build doesnt-work
# Error: accumulating resources: recursed merging from path '/Users/aaronc/projects/server-helm-chart/scratch/secret-gen-error/doesnt-work/responsibility': may not add resource with an already registered id: ~G_v1_Secret|~X|secret
#doesnt-work produces this error
kustomize build doesnt-work
# Error: accumulating resources: recursed accumulation of path '/Users/aaronc/projects/server-helm-chart/scratch/secret-gen-error/doesnt-work/responsibility': merging from generator &{0xc0005632c0 { } {map[] map[] false} {{ secret merge {[SECRET2=overwrite this secret] [] []}} }}: id resid.ResId{Gvk:resid.Gvk{Group:"", Version:"v1", Kind:"Secret"}, Name:"secret", Namespace:""} does not exist; cannot merge or replace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment