Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add user custom network policy #2078

Merged
merged 11 commits into from
Jun 21, 2023
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
}
},
"postCreateCommand": "go version",
"postAttachCommand": "sudo ln -s $(pwd)/cmd/agent/core/ngt/sample.yaml /etc/server/config.yaml"
"postAttachCommand": "sudo ln -s $(pwd)/cmd/agent/core/ngt/sample.yaml /etc/server/config.yaml",
"appPort": "3000:3000"
}
2 changes: 2 additions & 0 deletions .github/helm/values/values-lb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
defaults:
logging:
level: info
networkPolicy:
enabled: true

gateway:
lb:
Expand Down
2 changes: 2 additions & 0 deletions .github/valdrelease/valdrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ spec:
defaults:
logging:
level: info
networkPolicy:
enabled: true

gateway:
lb:
Expand Down
1 change: 1 addition & 0 deletions charts/vald-helm-operator/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ rules:
- networking.k8s.io
resources:
- ingresses
- networkpolicies
verbs:
- create
- delete
Expand Down
11 changes: 11 additions & 0 deletions charts/vald/templates/agent/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ spec:
podSelector:
matchLabels:
app: {{ $index.name }}
{{- if .Values.defaults.networkPolicy.custom.ingress }}
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.egress }}
{{- toYaml .Values.defaults.networkPolicy.custom.egress | nindent 4 }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions charts/vald/templates/discoverer/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ spec:
podSelector:
matchLabels:
app: {{ $index.name }}
{{- if .Values.defaults.networkPolicy.custom.ingress }}
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.egress }}
{{- toYaml .Values.defaults.networkPolicy.custom.egress | nindent 4 }}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions charts/vald/templates/gateway/filter/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ spec:
matchLabels:
app: {{ $filter.name }}
policyTypes:
{{- if .Values.defaults.networkPolicy.custom.ingress }}
- Ingress
{{- end }}
- Egress
{{- if .Values.defaults.networkPolicy.custom.ingress }}
ingress:
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
# allow all the egress to communicate with user-defined filters
- {}
Expand Down
6 changes: 6 additions & 0 deletions charts/vald/templates/gateway/lb/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ spec:
podSelector:
matchLabels:
app: {{ $filter.name }}
{{- if .Values.defaults.networkPolicy.custom.ingress }}
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
- to:
- namespaceSelector:
Expand All @@ -58,4 +61,7 @@ spec:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.egress }}
{{- toYaml .Values.defaults.networkPolicy.custom.egress | nindent 4 }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions charts/vald/templates/manager/index/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ spec:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.ingress }}
{{- toYaml .Values.defaults.networkPolicy.custom.ingress | nindent 4 }}
{{- end }}
egress:
- to:
- namespaceSelector:
Expand All @@ -51,4 +54,7 @@ spec:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
{{- if .Values.defaults.networkPolicy.custom.egress }}
{{- toYaml .Values.defaults.networkPolicy.custom.egress | nindent 4 }}
{{- end }}
{{- end }}
10 changes: 9 additions & 1 deletion charts/vald/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,16 @@ defaults:
networkPolicy:
# @schema {"name": "defaults.networkPolicy.enabled", "type": "boolean"}
# defaults.networkPolicy.enabled -- if network policy enabled
# TODO: Change this to true after implementing user custom network policy parser
enabled: false
# @schema {"name": "defaults.networkPolicy.custom", "type": "object"}
# defaults.networkPolicy.custom -- custom network policies that a user can add
custom:
# @schema {"name": "defaults.networkPolicy.custom.ingress", "type": "object"}
# defaults.networkPolicy.custom.ingress -- custom ingress network policies that a user can add
ingress: {}
# @schema {"name": "defaults.networkPolicy.custom.egress", "type": "object"}
# defaults.networkPolicy.custom.egress -- custom egress network policies that a user can add
egress: {}

# @schema {"name": "gateway", "type": "object"}
gateway:
Expand Down
8 changes: 8 additions & 0 deletions charts/vald/values/dev-observability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ defaults:
collector_endpoint: "opentelemetry-collector-collector.default.svc.cluster.local:4317"
trace:
enabled: true
networkPolicy:
enabled: true
custom:
egress:
- to:
- podSelector:
matchLabels:
app.kubernetes.io/name: opentelemetry-collector-collector

gateway:
lb:
Expand Down
2 changes: 1 addition & 1 deletion dockers/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ USER vscode
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -sS https://webinstall.dev/k9s | bash

WORKDIR ${GOPATH}
RUN go install github.com/stern/stern@latest