Skip to content

Commit b5cf3a2

Browse files
committed
add yaml-version of jsonpatch tests
1 parent 5cf0cbe commit b5cf3a2

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

examples/jsonpatch.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ cat <<EOF >$DEMO_HOME/ingress_patch.json
4646
EOF
4747
```
4848

49+
You can also write the patch in YAML format. This example also shows the "add" operation:
50+
51+
<!-- @addYamlPatch @test -->
52+
```
53+
cat <<EOF >$DEMO_HOME/ingress_patch.yaml
54+
- op: replace
55+
path: /spec/rules/0/host
56+
value: foo.bar.io
57+
58+
- op: add
59+
path: /spec/rules/0/http/paths/-
60+
value:
61+
path: '/test'
62+
backend:
63+
serviceName: my-test
64+
servicePort: 8081
65+
EOF
66+
```
67+
4968
Apply the patch by adding _patchesJson6902_ field in kustomization.yaml
5069

5170
<!-- @applyJsonPatch @test -->
@@ -61,17 +80,39 @@ patchesJson6902:
6180
EOF
6281
```
6382

64-
Running `kustomize build $DEMO_HOME`, in the ourput confirm that host has been updated correctly.
83+
Running `kustomize build $DEMO_HOME`, in the output confirm that host has been updated correctly.
6584
<!-- @confirmHost @test -->
6685
```
6786
test 1 == \
6887
$(kustomize build $DEMO_HOME | grep "host: foo.bar.io" | wc -l); \
6988
echo $?
7089
```
71-
Running `kustomize build $DEMO_HOME`, in the ourput confirm that the servicePort has been updated correctly.
90+
Running `kustomize build $DEMO_HOME`, in the output confirm that the servicePort has been updated correctly.
7291
<!-- @confirmServicePort @test -->
7392
```
7493
test 1 == \
7594
$(kustomize build $DEMO_HOME | grep "servicePort: 8080" | wc -l); \
7695
echo $?
7796
```
97+
98+
If the patch is YAML-formatted, it will be parsed correctly:
99+
100+
<!-- @applyYamlPatch @test -->
101+
```
102+
cat <<EOF >>$DEMO_HOME/kustomization.yaml
103+
patchesJson6902:
104+
- target:
105+
group: extensions
106+
version: v1beta1
107+
kind: Ingress
108+
name: my-ingress
109+
path: ingress_patch.yaml
110+
EOF
111+
```
112+
113+
<!-- @confirmYamlPatch @test -->
114+
```
115+
test 1 == \
116+
$(kustomize build $DEMO_HOME | grep "path: /test" | wc -l); \
117+
echo $?
118+
```

0 commit comments

Comments
 (0)