From b5cf3a2146341349894b9086c9f6090dbf0b3eb7 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 7 Oct 2018 22:28:59 +0200 Subject: [PATCH] add yaml-version of jsonpatch tests --- examples/jsonpatch.md | 45 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/examples/jsonpatch.md b/examples/jsonpatch.md index 99dcb6d3c..61c00f38f 100644 --- a/examples/jsonpatch.md +++ b/examples/jsonpatch.md @@ -46,6 +46,25 @@ cat <$DEMO_HOME/ingress_patch.json EOF ``` +You can also write the patch in YAML format. This example also shows the "add" operation: + + +``` +cat <$DEMO_HOME/ingress_patch.yaml +- op: replace + path: /spec/rules/0/host + value: foo.bar.io + +- op: add + path: /spec/rules/0/http/paths/- + value: + path: '/test' + backend: + serviceName: my-test + servicePort: 8081 +EOF +``` + Apply the patch by adding _patchesJson6902_ field in kustomization.yaml @@ -61,17 +80,39 @@ patchesJson6902: EOF ``` -Running `kustomize build $DEMO_HOME`, in the ourput confirm that host has been updated correctly. +Running `kustomize build $DEMO_HOME`, in the output confirm that host has been updated correctly. ``` test 1 == \ $(kustomize build $DEMO_HOME | grep "host: foo.bar.io" | wc -l); \ echo $? ``` -Running `kustomize build $DEMO_HOME`, in the ourput confirm that the servicePort has been updated correctly. +Running `kustomize build $DEMO_HOME`, in the output confirm that the servicePort has been updated correctly. ``` test 1 == \ $(kustomize build $DEMO_HOME | grep "servicePort: 8080" | wc -l); \ echo $? ``` + +If the patch is YAML-formatted, it will be parsed correctly: + + +``` +cat <>$DEMO_HOME/kustomization.yaml +patchesJson6902: +- target: + group: extensions + version: v1beta1 + kind: Ingress + name: my-ingress + path: ingress_patch.yaml +EOF +``` + + +``` +test 1 == \ + $(kustomize build $DEMO_HOME | grep "path: /test" | wc -l); \ + echo $? +```