diff --git a/run_helm_test.sh b/run_helm_test.sh new file mode 100755 index 0000000000000000000000000000000000000000..9c22b83bae0c14b99e1170a5c537938ef8aa497e --- /dev/null +++ b/run_helm_test.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -e + +helm template ./src/main/helm/ -f src/main/helm/test-values.yaml +helm lint -f src/main/helm/test-values.yaml ./src/main/helm/ +cd src/main/helm && helm unittest --helm3 -f '../../test/helm/*.yaml' -v '../../test/unit-values.yaml' . \ No newline at end of file diff --git a/src/main/helm/templates/network_policy.yaml b/src/main/helm/templates/network_policy.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3b51b06b701c750ef3eed2168d97165efe360b01 --- /dev/null +++ b/src/main/helm/templates/network_policy.yaml @@ -0,0 +1,82 @@ +# +# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +{{- if not (.Values.network_policy).disabled }} +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: network-policy-pluto + namespace: {{ .Release.Namespace }} +spec: + podSelector: + matchLabels: + component: pluto + policyTypes: + - Ingress + - Egress + ingress: + - ports: + - port: 9090 + from: + - podSelector: + matchLabels: + component: goofy + - podSelector: + matchLabels: + ozg-component: eingangsadapter + {{- with (.Values.network_policy).additional_ingress_config }} + - from: +{{ toYaml . | indent 8 }} + {{- end }} + egress: + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: elastic-system + podSelector: + matchLabels: + elasticsearch.k8s.elastic.co/cluster-name : ozg-search-cluster + ports: + - port: 9200 + protocol: TCP + - to: + - podSelector: + matchLabels: + component: ozg-mongodb + ports: + - port: 27017 + protocol: TCP + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: kube-system + podSelector: + matchLabels: + k8s-app: kube-dns + ports: + - port: 53 + protocol: UDP + - port: 53 + protocol: TCP +{{- end }} \ No newline at end of file diff --git a/src/test/helm/network_policy_test.yaml b/src/test/helm/network_policy_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..674c033ae4ea564208b09276b5d09d47717fabad --- /dev/null +++ b/src/test/helm/network_policy_test.yaml @@ -0,0 +1,138 @@ +# +# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +suite: network policy test +release: + namespace: by-helm-test +templates: + - templates/network_policy.yaml +tests: + - it: should match apiVersion + asserts: + - isAPIVersion: + of: networking.k8s.io/v1 + - it: should match kind + asserts: + - isKind: + of: NetworkPolicy + - it: validate metadata + asserts: + - equal: + path: metadata + value: + name: network-policy-pluto + namespace: by-helm-test + - it: validate spec + asserts: + - equal: + path: spec + value: + podSelector: + matchLabels: + component: pluto + policyTypes: + - Ingress + - Egress + ingress: + - ports: + - port: 9090 + from: + - podSelector: + matchLabels: + component: goofy + - podSelector: + matchLabels: + ozg-component: eingangsadapter + + egress: + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: elastic-system + podSelector: + matchLabels: + elasticsearch.k8s.elastic.co/cluster-name : ozg-search-cluster + ports: + - port: 9200 + protocol: TCP + - to: + - podSelector: + matchLabels: + component: ozg-mongodb + ports: + - port: 27017 + protocol: TCP + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: kube-system + podSelector: + matchLabels: + k8s-app: kube-dns + ports: + - port: 53 + protocol: UDP + - port: 53 + protocol: TCP + + - it: add ingress rule by values + set: + network_policy: + additional_ingress_config: + - podSelector: + matchLabels: + component: client2 + asserts: + - equal: + path: spec.ingress + value: + - ports: + - port: 9090 + from: + - podSelector: + matchLabels: + component: goofy + - podSelector: + matchLabels: + ozg-component: eingangsadapter + - from: + - podSelector: + matchLabels: + component: client2 + + - it: test network policy disabled + set: + network_policy: + disabled: true + asserts: + - hasDocuments: + count: 0 + + - it: test network policy unset should be disabled + set: + network_policy: + disabled: false + asserts: + - hasDocuments: + count: 1 \ No newline at end of file