Skip to content

Commit

Permalink
docs: update patchMultipleObject example to filter with labelSelector (
Browse files Browse the repository at this point in the history
…#5700)

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md
  • Loading branch information
johnzheng1975 authored Jul 23, 2024
1 parent 2aaa42f commit cc9dd34
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions examples/patchMultipleObjects.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ cat <<EOF >$DEMO_HOME/deployments.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
old-label: old-value
name: deploy1
spec:
template:
Expand All @@ -95,6 +97,8 @@ spec:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
key: value
name: deploy2
spec:
template:
Expand Down Expand Up @@ -149,7 +153,7 @@ patches:
EOF
```
The expected result is:
Two deployment will be patched, the expected result is:
<!-- @definedExpectedOutput @testAgainstLatestRelease -->
Expand All @@ -158,6 +162,8 @@ cat <<EOF >$DEMO_HOME/out_expected.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
old-label: old-value
name: deploy1
spec:
template:
Expand All @@ -180,6 +186,8 @@ spec:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
key: value
name: deploy2
spec:
template:
Expand Down Expand Up @@ -214,5 +222,29 @@ Confirm expectations:
diff $DEMO_HOME/out_actual.yaml $DEMO_HOME/out_expected.yaml
```
To see how to do this with JSON patches,
try the [JSON patch] demo.
Let us do one more try.
Redefine a kustomization file. This time only patch one deployment whose label is "key: value".
```
cat <<EOF >$DEMO_HOME/kustomization.yaml
resources:
- deployments.yaml

patches:
- path: patch.yaml
target:
kind: Deployment
labelSelector: key=value
EOF
```
Run the build:
```
kustomize build $DEMO_HOME
```
Confirm expectations:
```
Only deploy2 is patched since its label matches "labelSelector: key=value". No change for deploy1.
```

0 comments on commit cc9dd34

Please sign in to comment.