Skip to content

Commit

Permalink
Merge pull request #17 from gitops-bridge-dev/teams-netpols
Browse files Browse the repository at this point in the history
[feat] unique network policy names
  • Loading branch information
csantanapr committed Jul 28, 2024
2 parents 40daf29 + 27fa5f1 commit 1758b08
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion charts/teams/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: team
description: A Helm Chart to bootstrap a Namespace in a Multi-Tenancy setup
version: 1.0.0
version: 2.0.0
type: application

22 changes: 0 additions & 22 deletions charts/teams/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,3 @@ helm.sh/chart: {{ include "team.chart" . }}
{{- end }}
{{- end }}


{{/*
Create the name of the NetworkPolicy to deny all outgoing traffic
*/}}
{{- define "team.networkPolicy.egress.deny.all.name" }}
{{- printf "%s-%s" ((include "team.fullname" .) | trunc 47 | trimSuffix "-") "egress-deny-all" }}
{{- end }}

{{/*
Create the name of the NetworkPolicy to allow outgoing traffic to the Kubernetes DNS
*/}}
{{- define "team.networkPolicy.egress.allow.dns.name" }}
{{- printf "%s-%s" ((include "team.fullname" .) | trunc 47 | trimSuffix "-") "egress-allow-dns" }}
{{- end }}

{{/*
Create the name of the NetworkPolicy to deny all incoming traffic
*/}}
{{- define "team.networkPolicy.ingress.deny.all.name" }}
{{- printf "%s-%s" ((include "team.fullname" .) | trunc 46 | trimSuffix "-") "ingress-deny-all" }}
{{- end }}

2 changes: 1 addition & 1 deletion charts/teams/templates/networkpolicy/egress/allow-dns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
name: {{ include "team.networkPolicy.egress.allow.dns.name" $ | quote }}
name: {{ $.Values.networkPolicies.egress.allow.dns.name }}
namespace: {{ $name }}
spec:
{{- if $.Values.networkPolicies.egress.allow.dns.podSelector }}
Expand Down
4 changes: 2 additions & 2 deletions charts/teams/templates/networkpolicy/egress/deny-all.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and (.Values.networkPolicies.enabled) (.Values.networkPolicies.egress.deny.all) }}
{{- if and (.Values.networkPolicies.enabled) (.Values.networkPolicies.egress.deny.all.enabled) }}
{{- range $name, $tenant := .Values.namespaces }}
---
apiVersion: networking.k8s.io/v1
Expand All @@ -18,7 +18,7 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
name: {{ include "team.networkPolicy.egress.deny.all.name" $ | quote }}
name: {{ $.Values.networkPolicies.egress.deny.all.name }}
namespace: {{ $name }}
spec:
{{- if $.Values.networkPolicies.egress.deny.all.podSelector }}
Expand Down
4 changes: 2 additions & 2 deletions charts/teams/templates/networkpolicy/ingress/deny-all.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and (.Values.networkPolicies.enabled) (.Values.networkPolicies.ingress.deny.all) }}
{{- if and (.Values.networkPolicies.enabled) (.Values.networkPolicies.ingress.deny.all.enabled) }}
{{- range $name, $tenant := .Values.namespaces }}
---
apiVersion: networking.k8s.io/v1
Expand All @@ -18,7 +18,7 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
name: {{ include "team.networkPolicy.ingress.deny.all.name" $ | quote }}
name: {{ $.Values.networkPolicies.ingress.deny.all.name }}
namespace: {{ $name }}
spec:
{{- if $.Values.networkPolicies.ingress.deny.all.podSelector }}
Expand Down
3 changes: 3 additions & 0 deletions charts/teams/values-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ networkPolicies:
egress:
deny:
all:
name: egress-deny-all
# -- create a NetworkPolicy that denies all outgoing traffic
enabled: true
# -- define a PodSelector that should be used. Uses all Pods by default
podSelector: {}
allow:
dns:
name: egress-allow-dns
# -- create a NetworkPolicy that allows outgoing traffic to the Kubernetes DNS
enabled: true
# -- The namespace where the Kubneretes DNS is running
Expand All @@ -30,6 +32,7 @@ networkPolicies:
ingress:
deny:
all:
name: ingress-deny-all
# -- create a NetworkPolicy that denies all incoming traffic
enabled: true
# -- define a PodSelector that should be used. Uses all Pods by default
Expand Down
3 changes: 3 additions & 0 deletions charts/teams/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ networkPolicies:
egress:
deny:
all:
name: egress-deny-all
# -- create a NetworkPolicy that denies all outgoing traffic
enabled: true
# -- define a PodSelector that should be used. Uses all Pods by default
podSelector: {}
allow:
dns:
name: egress-allow-dns
# -- create a NetworkPolicy that allows outgoing traffic to the Kubernetes DNS
enabled: true
# -- The namespace where the Kubneretes DNS is running
Expand All @@ -26,6 +28,7 @@ networkPolicies:
ingress:
deny:
all:
name: ingress-deny-all
# -- create a NetworkPolicy that denies all incoming traffic
enabled: true
# -- define a PodSelector that should be used. Uses all Pods by default
Expand Down

0 comments on commit 1758b08

Please sign in to comment.