Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update patchMultipleObject example to filter with labelSelector #5700

Merged
merged 8 commits into from
Jul 23, 2024
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.
```

Loading