Skip to content

Commit 0b0ce03

Browse files
authored
Chart: Rework network policies. (#10238)
1 parent c3194dd commit 0b0ce03

File tree

6 files changed

+87
-26
lines changed

6 files changed

+87
-26
lines changed

charts/ingress-nginx/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ As of version `1.26.0` of this chart, by simply not providing any clusterIP valu
249249
| controller.admissionWebhooks.key | string | `"/usr/local/certificates/key"` | |
250250
| controller.admissionWebhooks.labels | object | `{}` | Labels to be added to admission webhooks |
251251
| controller.admissionWebhooks.namespaceSelector | object | `{}` | |
252-
| controller.admissionWebhooks.networkPolicyEnabled | bool | `false` | |
253252
| controller.admissionWebhooks.objectSelector | object | `{}` | |
254253
| controller.admissionWebhooks.patch.enabled | bool | `true` | |
255254
| controller.admissionWebhooks.patch.image.digest | string | `"sha256:543c40fd093964bc9ab509d3e791f9989963021f1e9e4c9c7b6700b02bfb227b"` | |
@@ -374,6 +373,7 @@ As of version `1.26.0` of this chart, by simply not providing any clusterIP valu
374373
| controller.minAvailable | int | `1` | Minimum available pods set in PodDisruptionBudget. Define either 'minAvailable' or 'maxUnavailable', never both. |
375374
| controller.minReadySeconds | int | `0` | `minReadySeconds` to avoid killing pods before we are ready # |
376375
| controller.name | string | `"controller"` | |
376+
| controller.networkPolicy.enabled | bool | `false` | Enable 'networkPolicy' or not |
377377
| controller.nodeSelector | object | `{"kubernetes.io/os":"linux"}` | Node labels for controller pod assignment # Ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/ # |
378378
| controller.opentelemetry.containerSecurityContext.allowPrivilegeEscalation | bool | `false` | |
379379
| controller.opentelemetry.enabled | bool | `false` | |
@@ -472,6 +472,7 @@ As of version `1.26.0` of this chart, by simply not providing any clusterIP valu
472472
| defaultBackend.minAvailable | int | `1` | |
473473
| defaultBackend.minReadySeconds | int | `0` | `minReadySeconds` to avoid killing pods before we are ready # |
474474
| defaultBackend.name | string | `"defaultbackend"` | |
475+
| defaultBackend.networkPolicy.enabled | bool | `false` | Enable 'networkPolicy' or not |
475476
| defaultBackend.nodeSelector | object | `{"kubernetes.io/os":"linux"}` | Node labels for default backend pod assignment # Ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/ # |
476477
| defaultBackend.podAnnotations | object | `{}` | Annotations to be added to default backend pods # |
477478
| defaultBackend.podLabels | object | `{}` | Labels to add to the pod container metadata |

charts/ingress-nginx/templates/admission-webhooks/job-patch/networkpolicy.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.controller.admissionWebhooks.enabled .Values.controller.admissionWebhooks.networkPolicyEnabled }}
1+
{{- if and .Values.controller.admissionWebhooks.enabled .Values.controller.admissionWebhooks.patch.enabled (not .Values.controller.admissionWebhooks.certManager.enabled) -}}
22
apiVersion: networking.k8s.io/v1
33
kind: NetworkPolicy
44
metadata:
@@ -16,11 +16,11 @@ metadata:
1616
spec:
1717
podSelector:
1818
matchLabels:
19-
{{- include "ingress-nginx.labels" . | nindent 6 }}
19+
{{- include "ingress-nginx.selectorLabels" . | nindent 6 }}
2020
app.kubernetes.io/component: admission-webhook
2121
policyTypes:
22-
- Ingress
23-
- Egress
22+
- Ingress
23+
- Egress
2424
egress:
25-
- {}
25+
- {}
2626
{{- end }}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{- if .Values.controller.networkPolicy.enabled }}
2+
apiVersion: networking.k8s.io/v1
3+
kind: NetworkPolicy
4+
metadata:
5+
labels:
6+
{{- include "ingress-nginx.labels" . | nindent 4 }}
7+
app.kubernetes.io/component: controller
8+
{{- with .Values.controller.labels }}
9+
{{- toYaml . | nindent 4 }}
10+
{{- end }}
11+
name: {{ include "ingress-nginx.controller.fullname" . }}
12+
namespace: {{ .Release.Namespace }}
13+
spec:
14+
podSelector:
15+
matchLabels:
16+
{{- include "ingress-nginx.selectorLabels" . | nindent 6 }}
17+
app.kubernetes.io/component: controller
18+
policyTypes:
19+
- Ingress
20+
- Egress
21+
ingress:
22+
- ports:
23+
{{- range $key, $value := .Values.controller.containerPort }}
24+
- protocol: TCP
25+
port: {{ $value }}
26+
{{- end }}
27+
{{- if .Values.controller.metrics.enabled }}
28+
- protocol: TCP
29+
port: {{ .Values.controller.metrics.port }}
30+
{{- end }}
31+
{{- if .Values.controller.admissionWebhooks.enabled }}
32+
- protocol: TCP
33+
port: {{ .Values.controller.admissionWebhooks.port }}
34+
{{- end }}
35+
{{- range $key, $value := .Values.tcp }}
36+
- protocol: TCP
37+
port: {{ $key }}
38+
{{- end }}
39+
{{- range $key, $value := .Values.udp }}
40+
- protocol: UDP
41+
port: {{ $key }}
42+
{{- end }}
43+
egress:
44+
- {}
45+
{{- end }}

charts/ingress-nginx/templates/controller-webhooks-networkpolicy.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{{- if and .Values.defaultBackend.enabled .Values.defaultBackend.networkPolicy.enabled }}
2+
apiVersion: networking.k8s.io/v1
3+
kind: NetworkPolicy
4+
metadata:
5+
labels:
6+
{{- include "ingress-nginx.labels" . | nindent 4 }}
7+
app.kubernetes.io/component: default-backend
8+
{{- with .Values.defaultBackend.labels }}
9+
{{- toYaml . | nindent 4 }}
10+
{{- end }}
11+
name: {{ include "ingress-nginx.defaultBackend.fullname" . }}
12+
namespace: {{ .Release.Namespace }}
13+
spec:
14+
podSelector:
15+
matchLabels:
16+
{{- include "ingress-nginx.selectorLabels" . | nindent 6 }}
17+
app.kubernetes.io/component: default-backend
18+
policyTypes:
19+
- Ingress
20+
- Egress
21+
ingress:
22+
- ports:
23+
- protocol: TCP
24+
port: {{ .Values.defaultBackend.port }}
25+
{{- end }}

charts/ingress-nginx/values.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ controller:
9696
http: 80
9797
# -- 'hostPort' https port
9898
https: 443
99+
# NetworkPolicy for controller component.
100+
networkPolicy:
101+
# -- Enable 'networkPolicy' or not
102+
enabled: false
99103
# -- Election ID to use for status update, by default it uses the controller name combined with a suffix of 'leader'
100104
electionID: ""
101105
## This section refers to the creation of the IngressClass resource
@@ -606,7 +610,6 @@ controller:
606610
labels: {}
607611
# -- Use an existing PSP instead of creating one
608612
existingPsp: ""
609-
networkPolicyEnabled: false
610613
service:
611614
annotations: {}
612615
# clusterIP: ""
@@ -872,6 +875,12 @@ defaultBackend:
872875
maxReplicas: 2
873876
targetCPUUtilizationPercentage: 50
874877
targetMemoryUtilizationPercentage: 50
878+
879+
# NetworkPolicy for default backend component.
880+
networkPolicy:
881+
# -- Enable 'networkPolicy' or not
882+
enabled: false
883+
875884
service:
876885
annotations: {}
877886
# clusterIP: ""

0 commit comments

Comments
 (0)