No more netpols fo pods in open namespaces.

This commit is contained in:
Erik Brakkee 2025-01-02 18:24:02 +01:00
parent 6d05f0501f
commit 933b46c68c
4 changed files with 6 additions and 6 deletions

View File

@ -56,7 +56,7 @@ type Application struct {
Name string `yaml:"name"`
Ports []Port `yaml:"ports,omitempty"`
MatchLabels map[string]string `yaml:"matchLabels"`
Namespace string `yaml:"-"`
Namespace *Namespace `yaml:"-"`
}
type Namespace struct {
@ -180,7 +180,7 @@ func LoadConfig(file string) (*Config, error) {
// every application must have its namespace field set
for _, ns := range config.Namespaces {
for _, app := range ns.Applications {
app.Namespace = ns.Name
app.Namespace = ns
}
}

View File

@ -43,7 +43,6 @@ func (g NetworkPolicyGenerrator) GenerateCommunicationRule(
log.Printf("Found template %v for pod %s", tmpl, app.Name)
if tmpl != nil {
log.Printf("EXECUTING %s", app.Namespace)
err := tmpl.Execute(writer, map[string]any{
"app": app,
"ingress": ingress,

View File

@ -35,11 +35,12 @@
{{- end }}
{{- end }}
{{- if not .app.Namespace.Open }}
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: "{{.app.Name}}"
namespace: "{{.app.Namespace}}"
namespace: "{{.app.Namespace.Name }}"
labels: {{ .labels | toYaml | nindent 4 }}
spec:
podSelector: {{ .app.MatchLabels | toYaml | nindent 4 }}
@ -65,4 +66,4 @@ spec:
{{- template "networks" .egress }}
{{- end }}
THEEND
{{- end }}

View File

@ -14,7 +14,7 @@ networks:
namespaces:
- name: wamblee-org
open: true
open: false
capabilities:
- linkerd
applications: