network policy now fully generated

This commit is contained in:
2025-01-02 18:16:24 +01:00
parent 207043d38f
commit 6d05f0501f
5 changed files with 55 additions and 34 deletions
+36 -24
View File
@@ -1,5 +1,14 @@
---
{{- define "peer" }}
{{- define "ports" }}
{{- range $port := . }}
- port: {{ $port.Port }}
{{- if $port.Protocol }}
protocol: {{ $port.Protocol }}
{{- end }}
{{- end }}
{{- end }}
{{- define "peers" }}
{{- range .Applications }}
- podSelector:
matchLabels: {{ .MatchLabels | toYaml | nindent 12 }}
namespaceSelector:
@@ -7,19 +16,24 @@
kubernetes.io/metadata.name: {{ .Namespace }}
{{- if .Ports }}
ports:
# TODO: add protocol
{{- range $port := .Ports }}
- port: {{ $port }}
{{- end }}
{{- template "ports" .Ports }}
{{- end }}
{{- end }}
{{- end }}
{{- define "networks" }}
{{- range .Networks }}
- ipBlock:
cidr: {{ .CIDR}}
except:
{{- range $except := .Except }}
- {{ $except }}
{{- end }}
{{- if .Ports }}
ports:
{{- template "ports" .Ports }}
{{- end }}
{{- end }}
{{- end }}
-
{{- define "ports" }}
{{- range $port := . }}
PORT {{ $port }}
{{- end }}
{{- end }}
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
@@ -40,17 +54,15 @@ spec:
{{- if or .ingress.Applications .ingress.Networks }}
ingress:
from:
{{- range $ingress := .ingress.Applications }}
{{- template "peer" $ingress }}
{{- template "ports" $ingress.Ports }}
{{- end }}
{{- range $ingress := .ingress.Networks }}
- ipBlock:
cidr: {{ $ingress.CIDR}}
except:
{{- range $except := $ingress.Except }}
- {{ $except }}
{{- end }}
{{- end }}
{{- template "peers" .ingress }}
{{- template "networks" .ingress }}
{{- end }}
{{- if or .egress.Applications .egress.Networks }}
egress:
tp:
{{- template "peers" .egress }}
{{- template "networks" .egress }}
{{- end }}
THEEND