I have a base resource that gets imported in an overlay, which in the overlays also makes other resources from the same base but with a different suffix. In the overlay, the base resource needs to be patched without affecting the other newly created resources. However, all three of them are changed. How can I just modify the one I am intending to modify?
Below is an example of this. The base resource is a Deployment with 1 replica. In the overlay, the base is added as a resource but I try to patch it and set the replicas to 0. Unfortunately, all replicas of all deployments get set to 0.
Base
EX_HOME=$(mktemp -d)
BASE=$EX_HOME/base
mkdir $BASE
cat <<EOF >$BASE/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: example
labels:
app: example
spec:
replicas: 1
selector:
matchLabels:
app: example
template:
metadata:
labels:
app: example
spec:
containers:
- name: example
image: alpine:latest
command: ["sh","-c", "sleep 1h"]
EOF
cat <<EOF>$BASE/kustomization.yaml
resources:
- deployment.yaml
EOF
Overlay
OVERLAYS=$EX_HOME/overlays
mkdir -p $OVERLAYS/srv0
mkdir -p $OVERLAYS/srv1
cat <<EOF>$OVERLAYS/kustomization.yaml
resources:
- svr0
- svr1
- ../base
patches:
- patch: |-
- op: replace
path: /spec/replicas
value: 0
target:
kind: Deployment
group: apps
version: v1
name: example
EOF
cat <<EOF>$OVERLAYS/svr0/kustomization.yaml
resources:
- ../../base
nameSuffix: -svr0
EOF
cat <<EOF>$OVERLAYS/svr0/kustomize.yaml
resources:
- ../../base
nameSuffix: -svr1
EOF