From 64f49caa8483bb8a3c2372b1bd42313d323e39f8 Mon Sep 17 00:00:00 2001 From: Bricktop Date: Mon, 26 Apr 2021 23:02:52 +0200 Subject: [PATCH] Add e2e test with nested jmesPath in context (#1786) Signed-off-by: Marcel Mueller --- test/e2e/mutate/config.go | 4 ++++ test/e2e/mutate/resources.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/test/e2e/mutate/config.go b/test/e2e/mutate/config.go index 26184bffbc..0dc5e0995c 100644 --- a/test/e2e/mutate/config.go +++ b/test/e2e/mutate/config.go @@ -15,4 +15,8 @@ var MutateTests = []struct { TestName: "test-mutate-with-logic-in-context", Data: configMapMutationWithContextLogicYaml, }, + { + TestName: "test-mutate-with-context-label-selection", + Data: configMapMutationWithContextLabelSelectionYaml, + }, } diff --git a/test/e2e/mutate/resources.go b/test/e2e/mutate/resources.go index e49d66ae7f..fe060d68a8 100644 --- a/test/e2e/mutate/resources.go +++ b/test/e2e/mutate/resources.go @@ -57,6 +57,30 @@ spec: +(kyverno.key/copy-me): "{{ labelValue }}" `) +var configMapMutationWithContextLabelSelectionYaml = []byte(` +apiVersion: kyverno.io/v1 +kind: ClusterPolicy +metadata: + name: "mutate-policy" +spec: + rules: + - name: "gen-role" + match: + resources: + kinds: + - ConfigMap + context: + - name: labelValue + apiCall: + urlPath: "/api/v1/namespaces/{{ request.object.metadata.namespace }}/configmaps" + jmesPath: "items[?metadata.name == '{{ request.object.metadata.labels.\"kyverno.key/copy-from\" }}'].metadata.labels.\"kyverno.key/copy-me\" | [0]" + mutate: + patchStrategicMerge: + metadata: + labels: + +(kyverno.key/copy-me): "{{ labelValue }}" +`) + // Source ConfigMap from which data is taken to copy var sourceConfigMapYaml = []byte(` apiVersion: v1 @@ -78,6 +102,8 @@ kind: ConfigMap metadata: name: target namespace: test-mutate + labels: + kyverno.key/copy-from: source data: data.yaml: | some: data