Skip to content

Commit

Permalink
Add e2e test with nested jmesPath in context (#1786)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Mueller <marcel.mueller1@rwth-aachen.de>
  • Loading branch information
MarcelMue committed Apr 26, 2021
1 parent 434a4cd commit 64f49ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/e2e/mutate/config.go
Expand Up @@ -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,
},
}
26 changes: 26 additions & 0 deletions test/e2e/mutate/resources.go
Expand Up @@ -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
Expand All @@ -78,6 +102,8 @@ kind: ConfigMap
metadata:
name: target
namespace: test-mutate
labels:
kyverno.key/copy-from: source
data:
data.yaml: |
some: data
Expand Down

0 comments on commit 64f49ca

Please sign in to comment.