From 09dfd80b06b936a84e8d8af7fea4bb65bcadc003 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Wed, 3 Feb 2021 21:34:44 +0100 Subject: [PATCH] Test Strategic Merge and JSON 6902 patches Signed-off-by: Hidde Beydals --- .github/workflows/e2e.yaml | 15 ++++-- .../overrides/{test.yaml => images.yaml} | 8 ++-- config/testdata/overrides/patches.yaml | 47 +++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) rename config/testdata/overrides/{test.yaml => images.yaml} (84%) create mode 100644 config/testdata/overrides/patches.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 4d3e60b40..a2471d391 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -82,12 +82,21 @@ jobs: kubectl -n impersonation wait kustomizations/podinfo --for=condition=ready --timeout=4m kubectl -n impersonation delete kustomizations/podinfo until kubectl -n impersonation get deploy/podinfo 2>&1 | grep NotFound ; do sleep 2; done - - name: Run image overide tests + - name: Run images override tests run: | - kubectl -n override-test apply -f ./config/testdata/overrides - kubectl -n override-test wait kustomizations/podinfo --for=condition=ready --timeout=1m + kubectl -n images-test apply -f ./config/testdata/overrides/images.yaml + kubectl -n images-test wait kustomizations/podinfo --for=condition=ready --timeout=1m ACTUAL_TAG=$(kubectl -n override-test get deployments podinfo -o jsonpath='{.spec.template.spec.containers[0].image}' | cut -f2 -d ":") if [[ $ACTUAL_TAG != "5.0.0" ]]; then echo "Image tag did not override" && exit 1; fi + - name: Run patches override tests + run: | + kubectl -n patches-test apply -f ./config/testdata/overrides/patches.yaml + kubectl -n patches-test wait kustomizations/podinfo --for=condition=ready --timeout=1m + RESULT=$(kubectl -n patches-test get deployment mypodinfo -o jsonpath='{.metadata.labels.yyyy}') + if [ "$RESULT" != "xxxx" ]; then + echo -e "$RESULT\n\ndoes not equal\n\nxxxx" + exit 1 + fi - name: Logs run: | kubectl -n kustomize-system logs deploy/source-controller diff --git a/config/testdata/overrides/test.yaml b/config/testdata/overrides/images.yaml similarity index 84% rename from config/testdata/overrides/test.yaml rename to config/testdata/overrides/images.yaml index 37db7f6fe..9d9a0a13e 100644 --- a/config/testdata/overrides/test.yaml +++ b/config/testdata/overrides/images.yaml @@ -1,13 +1,13 @@ apiVersion: v1 kind: Namespace metadata: - name: override-test + name: images-test --- apiVersion: source.toolkit.fluxcd.io/v1beta1 kind: GitRepository metadata: name: podinfo - namespace: override-test + namespace: images-test spec: interval: 5m url: https://github.com/stefanprodan/podinfo @@ -18,9 +18,9 @@ apiVersion: kustomize.toolkit.fluxcd.io/v1beta1 kind: Kustomization metadata: name: podinfo - namespace: override-test + namespace: images-test spec: - targetNamespace: override-test + targetNamespace: images-test interval: 5m path: "./kustomize" prune: true diff --git a/config/testdata/overrides/patches.yaml b/config/testdata/overrides/patches.yaml new file mode 100644 index 000000000..483b9bd84 --- /dev/null +++ b/config/testdata/overrides/patches.yaml @@ -0,0 +1,47 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: patches-test +--- +apiVersion: source.toolkit.fluxcd.io/v1beta1 +kind: GitRepository +metadata: + name: podinfo + namespace: patches-test +spec: + interval: 5m + url: https://github.com/stefanprodan/podinfo + ref: + branch: master +--- +apiVersion: kustomize.toolkit.fluxcd.io/v1beta1 +kind: Kustomization +metadata: + name: podinfo + namespace: patches-test +spec: + targetNamespace: patches-test + interval: 5m + path: "./kustomize" + prune: true + sourceRef: + kind: GitRepository + name: podinfo + validation: client + patchesStrategicMerge: + - kind: Deployment + apiVersion: apps/v1 + metadata: + name: mypodinfo + labels: + xxxx: yyyy + patchesJson6902: + - target: + group: apps + version: v1 + kind: Deployment + name: mypodinfo + patch: + - op: add + path: /metadata/labels/yyyy + value: xxxx