Skip to content

Instantly share code, notes, and snippets.

@peterjanes
Created March 30, 2020 21:19
Show Gist options
  • Save peterjanes/ab76834e9889d9be9c2aef7cfcf5c995 to your computer and use it in GitHub Desktop.
Save peterjanes/ab76834e9889d9be9c2aef7cfcf5c995 to your computer and use it in GitHub Desktop.
Curious kustomize behaviour - `kustomize build use` will apply the transformer to the generated secret but not to the local service
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
generators:
- my-generator.yaml
transformers:
- my-transformer.yaml
---
apiVersion: builtin
kind: SecretGenerator
metadata:
name: mySecret
namespace: whatever
behaviour: merge
literals:
- FRUIT=apple
- VEGETABLE=carrot
---
apiVersion: builtin
kind: PrefixSuffixTransformer
metadata:
name: notImportantHere
prefix: baked-
suffix: -pie
fieldSpecs:
- path: metadata/name
---
apiVersion: v1
kind: Service
metadata:
name: apple
spec:
ports:
- port: 7002
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../shared/
- apple.yaml
@peterjanes
Copy link
Author

Before running, put the files prefixed with use-* in a use/ directory and those prefixed with shared-* in shared/. Notice that the mySecret resource is transformed but the apple resource is not.

$ kustomize build use
apiVersion: v1
data:
  FRUIT: YXBwbGU=
  VEGETABLE: Y2Fycm90
kind: Secret
metadata:
  name: baked-mySecret-pie-tt72hh58h8
  namespace: whatever
type: Opaque
---
apiVersion: v1
kind: Service
metadata:
  name: apple
spec:
  ports:
  - port: 7002

@peterjanes
Copy link
Author

Makes sense now that I look at it again: the transformation is performed before the resource is "imported" into the other kustomization, rather than being a shared configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment