From 9986b65326c0b6af8058c9641a851eb4cedcd702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ga=C3=9F?= Date: Wed, 18 Jul 2018 14:01:22 +0200 Subject: [PATCH 1/2] Disable creation of NetworkPolicy podSelector.matchLabels --- pkg/transformers/labelsandannotationsconfig.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/transformers/labelsandannotationsconfig.go b/pkg/transformers/labelsandannotationsconfig.go index b87d30a56..4122743ad 100644 --- a/pkg/transformers/labelsandannotationsconfig.go +++ b/pkg/transformers/labelsandannotationsconfig.go @@ -162,7 +162,7 @@ var defaultLabelsPathConfigs = []PathConfig{ { GroupVersionKind: &schema.GroupVersionKind{Group: "networking.k8s.io", Kind: "NetworkPolicy"}, Path: []string{"spec", "podSelector", "matchLabels"}, - CreateIfNotPresent: true, + CreateIfNotPresent: false, }, { GroupVersionKind: &schema.GroupVersionKind{Group: "networking.k8s.io", Kind: "NetworkPolicy"}, From ed9f716361986bddaa4a19c2ea65b6f4f329c638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ga=C3=9F?= Date: Wed, 18 Jul 2018 14:11:18 +0200 Subject: [PATCH 2/2] Add unit test for NetworkPolicy --- .../testdata/testcase-base-only/expected.diff | 27 +++++++++++++++++++ .../testdata/testcase-base-only/expected.yaml | 25 +++++++++++++++++ .../in/resources/networkpolicy.yaml | 13 +++++++++ 3 files changed, 65 insertions(+) create mode 100644 pkg/commands/testdata/testcase-base-only/in/resources/networkpolicy.yaml diff --git a/pkg/commands/testdata/testcase-base-only/expected.diff b/pkg/commands/testdata/testcase-base-only/expected.diff index de911f805..5dba387e1 100644 --- a/pkg/commands/testdata/testcase-base-only/expected.diff +++ b/pkg/commands/testdata/testcase-base-only/expected.diff @@ -32,6 +32,33 @@ diff -u -N /tmp/noop/apps_v1beta2_Deployment_nginx.yaml /tmp/transformed/apps_v1 spec: containers: - image: nginx +diff -u -N /tmp/noop/networking.k8s.io_v1_NetworkPolicy_nginx.yaml /tmp/transformed/networking.k8s.io_v1_NetworkPolicy_nginx.yaml +--- /tmp/noop/networking.k8s.io_v1_NetworkPolicy_nginx.yaml YYYY-MM-DD HH:MM:SS ++++ /tmp/transformed/networking.k8s.io_v1_NetworkPolicy_nginx.yaml YYYY-MM-DD HH:MM:SS +@@ -1,13 +1,21 @@ + apiVersion: networking.k8s.io/v1 + kind: NetworkPolicy + metadata: +- name: nginx ++ annotations: ++ note: This is a test annotation ++ labels: ++ app: mynginx ++ org: example.com ++ team: foo ++ name: team-foo-nginx + spec: + ingress: + - from: + - podSelector: + matchLabels: +- app: nginx ++ app: mynginx ++ org: example.com ++ team: foo + podSelector: + matchExpressions: + - key: app diff -u -N /tmp/noop/v1_Service_nginx.yaml /tmp/transformed/v1_Service_nginx.yaml --- /tmp/noop/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS +++ /tmp/transformed/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS diff --git a/pkg/commands/testdata/testcase-base-only/expected.yaml b/pkg/commands/testdata/testcase-base-only/expected.yaml index 886d804b8..966cec3a2 100644 --- a/pkg/commands/testdata/testcase-base-only/expected.yaml +++ b/pkg/commands/testdata/testcase-base-only/expected.yaml @@ -44,3 +44,28 @@ spec: containers: - image: nginx name: nginx +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-nginx +spec: + ingress: + - from: + - podSelector: + matchLabels: + app: mynginx + org: example.com + team: foo + podSelector: + matchExpressions: + - key: app + operator: In + values: + - test diff --git a/pkg/commands/testdata/testcase-base-only/in/resources/networkpolicy.yaml b/pkg/commands/testdata/testcase-base-only/in/resources/networkpolicy.yaml new file mode 100644 index 000000000..213801ce1 --- /dev/null +++ b/pkg/commands/testdata/testcase-base-only/in/resources/networkpolicy.yaml @@ -0,0 +1,13 @@ +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: nginx +spec: + podSelector: + matchExpressions: + - {key: app, operator: In, values: [test]} + ingress: + - from: + - podSelector: + matchLabels: + app: nginx