Skip to content

Commit ec64b39

Browse files
MLE-16811: Helm: Missing values for specifying Egress definition in Network Policy (#300)
* refactored nwtwork pol to handle ingress and egress both.;
1 parent 755a930 commit ec64b39

File tree

4 files changed

+100
-31
lines changed

4 files changed

+100
-31
lines changed

charts/templates/networkPolicy.yaml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ metadata:
66
namespace: {{ .Release.Namespace }}
77
spec:
88
podSelector:
9-
matchLabels:
10-
{{- include "marklogic.selectorLabels" . | nindent 6 }}
9+
{{- if .Values.networkPolicy.podSelector }}
10+
{{- toYaml .Values.networkPolicy.podSelector | nindent 4 }}
11+
{{- end }}
1112
policyTypes:
12-
- Ingress
13-
ingress:
14-
{{- if .Values.networkPolicy.customRules }}
15-
- from:
16-
{{- toYaml .Values.networkPolicy.customRules | nindent 8 }}
13+
{{- range .Values.networkPolicy.policyTypes }}
14+
- {{ . }}
1715
{{- end }}
18-
- ports:
19-
{{- toYaml .Values.networkPolicy.ports | nindent 8 }}
16+
{{- if .Values.networkPolicy.ingress }}
17+
ingress:
18+
{{- toYaml .Values.networkPolicy.ingress | nindent 4 }}
19+
{{- end }}
20+
{{- if .Values.networkPolicy.egress }}
21+
egress:
22+
{{- toYaml .Values.networkPolicy.egress | nindent 4 }}
23+
{{- end }}
2024
{{- end }}

charts/values.yaml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,35 @@ priorityClassName: ""
235235
## ref: https://kubernetes.io/docs/concepts/services-networking/network-policies
236236
networkPolicy:
237237
enabled: false
238-
## @param networkPolicy.customRules. Additional NetworkPolicy rules
239-
## Note that all rules are OR-ed.
240-
customRules: {}
241-
# - matchLabels:
242-
# - role: frontend
243-
# - matchExpressions:
244-
# - key: role
245-
# operator: In
246-
# values:
247-
# - frontend
248-
## The endPort should be the last port exposed by an App Server
249-
ports:
250-
- port: 8000
251-
endPort: 8020
252-
protocol: TCP
238+
podSelector: {}
239+
# matchLabels:
240+
# app: marklogic
241+
policyTypes: []
242+
# - Ingress
243+
# - Egress
244+
# ingress:
245+
# - from:
246+
# - ipBlock:
247+
# cidr: ""
248+
# except: []
249+
# - namespaceSelector:
250+
# matchLabels:
251+
# project: marklogic
252+
# - podSelector:
253+
# matchLabels:
254+
# role: frontend
255+
# ## The endPort should be the last port exposed by an App Server
256+
# ports:
257+
# # - port: 8000
258+
# # endPort: 8020
259+
# protocol: TCP
260+
# egress:
261+
# - to:
262+
# - ipBlock:
263+
# cidr: ""
264+
# ports:
265+
# - protocol: TCP
266+
# port: 8000
253267

254268
## Below are the security configuration at POD level, by default security will be enabled
255269
## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#configure-volume-permission-and-ownership-change-policy-for-pods

test/template/network_templ_test.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package template_test
22

33
import (
4+
"os"
45
"path/filepath"
56
"strings"
67
"testing"
@@ -21,17 +22,28 @@ func TestChartTemplateNetworkPolicyEnabled(t *testing.T) {
2122
t.Log(helmChartPath, releaseName)
2223
require.NoError(t, err)
2324

25+
imageRepo, repoPres := os.LookupEnv("dockerRepository")
26+
imageTag, tagPres := os.LookupEnv("dockerVersion")
27+
if !repoPres {
28+
imageRepo = "progressofficial/marklogic-db"
29+
t.Logf("No imageRepo variable present, setting to default value: " + imageRepo)
30+
}
31+
32+
if !tagPres {
33+
imageTag = "latest-11"
34+
t.Logf("No imageTag variable present, setting to default value: " + imageTag)
35+
}
36+
2437
// Set up the namespace; confirm that the template renders the expected value for the namespace.
2538
namespaceName := "ml-" + strings.ToLower(random.UniqueId()) + "-network-policy"
2639
t.Logf("Namespace: %s\n", namespaceName)
2740

28-
// Setup the args for helm install
41+
// Setup the args for helm install using custom values.yaml file
2942
options := &helm.Options{
43+
ValuesFiles: []string{"../test_data/values/nwPolicy_templ_values.yaml"},
3044
SetValues: map[string]string{
31-
"image.repository": "progressofficial/marklogic-db",
32-
"image.tag": "latest",
33-
"persistence.enabled": "false",
34-
"networkPolicy.enabled": "true",
45+
"image.repository": imageRepo,
46+
"image.tag": imageTag,
3547
},
3648
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
3749
}
@@ -45,6 +57,6 @@ func TestChartTemplateNetworkPolicyEnabled(t *testing.T) {
4557

4658
// Verify the network policy type matches
4759
networkPolicies := networkpolicy.Spec
48-
expectedPolicyTypes := "Ingress"
49-
require.Equal(t, string(networkPolicies.PolicyTypes[0]), expectedPolicyTypes)
60+
require.Equal(t, string(networkPolicies.PolicyTypes[0]), "Ingress")
61+
require.Equal(t, string(networkPolicies.PolicyTypes[1]), "Egress")
5062
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This is a custom values files for template tests specific to TLS parameters
2+
replicaCount: 1
3+
4+
auth:
5+
adminPassword: admin
6+
adminUsername: admin
7+
8+
terminationGracePeriod: 10
9+
10+
persistence:
11+
enabled: false
12+
13+
networkPolicy:
14+
enabled: true
15+
policyTypes:
16+
- Ingress
17+
- Egress
18+
ingress:
19+
- from:
20+
- podSelector:
21+
matchLabels:
22+
app: marklogic
23+
ports:
24+
- protocol: TCP
25+
port: 7997
26+
namespaceSelector:
27+
matchLabels:
28+
name: marklogic
29+
egress:
30+
- to:
31+
- podSelector:
32+
matchLabels:
33+
app: marklogic
34+
ports:
35+
- protocol: TCP
36+
port: 7997
37+
namespaceSelector:
38+
matchLabels:
39+
name: marklogic

0 commit comments

Comments
 (0)