Skip to content

Commit

Permalink
feat: ingress rules for server networkPolicy (#877)
Browse files Browse the repository at this point in the history
* feat: allow server netPol to specify podSelector

* feat(test): add podSelector NetworkPolicy unittest

* chore: introduce server.networkPolicy.ingress

As suggested let users template the whole ingress object for the
networkPolicy than only the podSelector.

Co-authored-by: tvoran <444265+tvoran@users.noreply.github.com>

---------

Co-authored-by: tvoran <444265+tvoran@users.noreply.github.com>
  • Loading branch information
fty4 and tvoran authored Nov 16, 2023
1 parent 97166e5 commit e77dce3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
9 changes: 1 addition & 8 deletions templates/server-network-policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ spec:
matchLabels:
app.kubernetes.io/name: {{ template "vault.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
ingress:
- from:
- namespaceSelector: {}
ports:
- port: 8200
protocol: TCP
- port: 8201
protocol: TCP
ingress: {{- toYaml .Values.server.networkPolicy.ingress | nindent 4 }}
{{- if .Values.server.networkPolicy.egress }}
egress:
{{- toYaml .Values.server.networkPolicy.egress | nindent 4 }}
Expand Down
11 changes: 11 additions & 0 deletions test/unit/server-network-policy.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ load _helpers
[ "${actual}" = "true" ]
}

@test "server/network-policy: ingress changed by server.networkPolicy.ingress" {
cd `chart_dir`
local actual=$(helm template \
--set 'server.networkPolicy.enabled=true' \
--set 'server.networkPolicy.ingress[0].from[0].podSelector.matchLabels.foo=bar' \
--show-only templates/server-network-policy.yaml \
. | tee /dev/stderr |
yq -r '.spec.ingress[0].from[0].podSelector.matchLabels.foo' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}

@test "server/network-policy: egress enabled by server.networkPolicy.egress" {
cd `chart_dir`
local actual=$(helm template \
Expand Down
8 changes: 8 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,14 @@ server:
# ports:
# - protocol: TCP
# port: 443
ingress:
- from:
- namespaceSelector: {}
ports:
- port: 8200
protocol: TCP
- port: 8201
protocol: TCP

# Priority class for server pods
priorityClassName: ""
Expand Down

0 comments on commit e77dce3

Please sign in to comment.