Skip to content

Commit 3268c51

Browse files
committed
feat: Added Ingress SecurityContext and ServiceAccount
Signed-off-by: tomassatka <satka.tomas@gmail.com>
1 parent fd7a869 commit 3268c51

9 files changed

Lines changed: 310 additions & 160 deletions

templates/_utils.tpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,24 @@ helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | quote }}
8181
{{ include "opal.pgsqlSelectorLabels" . }}
8282
{{- end -}}
8383

84+
{{/*
85+
Create the name of the server service account to use
86+
*/}}
87+
{{- define "opal.serverServiceAccountName" -}}
88+
{{- if .Values.server.serviceAccount.create }}
89+
{{- default (include "opal.serverName" .) .Values.server.serviceAccount.name }}
90+
{{- else }}
91+
{{- default "default" .Values.server.serviceAccount.name }}
92+
{{- end }}
93+
{{- end }}
94+
95+
{{/*
96+
Create the name of the client service account to use
97+
*/}}
98+
{{- define "opal.clientServiceAccountName" -}}
99+
{{- if .Values.client.serviceAccount.create }}
100+
{{- default (include "opal.clientName" .) .Values.client.serviceAccount.name }}
101+
{{- else }}
102+
{{- default "default" .Values.client.serviceAccount.name }}
103+
{{- end }}
104+
{{- end }}

templates/deployment-client.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ spec:
2121
imagePullSecrets:
2222
{{- toYaml . | nindent 8 }}
2323
{{- end }}
24+
serviceAccountName: {{ include "opal.clientServiceAccountName" . }}
25+
{{- with .Values.client.podSecurityContext }}
26+
securityContext:
27+
{{- toYaml . | nindent 8 }}
28+
{{- end }}
2429
{{- if .Values.client.opaStartupData }}
2530
volumes:
2631
- name: opa-startup-data
@@ -30,6 +35,10 @@ spec:
3035
{{- end }}
3136
containers:
3237
- name: opal-client
38+
{{- with .Values.client.securityContext }}
39+
securityContext:
40+
{{- toYaml . | nindent 12 }}
41+
{{- end }}
3342
image: {{ include "opal.clientImage" . | quote }}
3443
imagePullPolicy: {{ .Values.client.imagePullPolicy | default "IfNotPresent" | quote }}
3544
ports:

templates/deployment-pgsql.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ spec:
2020
imagePullSecrets:
2121
{{- toYaml . | nindent 8 }}
2222
{{- end }}
23+
{{- with .Values.pgsql.podSecurityContext }}
24+
securityContext:
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
2327
containers:
2428
- name: pgsql
2529
image: {{ include "opal.pgsqlImage" . | quote }}
2630
imagePullPolicy: IfNotPresent
31+
{{- with .Values.pgsql.securityContext }}
32+
securityContext:
33+
{{- toYaml . | nindent 12 }}
34+
{{- end }}
2735
ports:
2836
- name: pgsql
2937
containerPort: 5432

templates/deployment-server.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ spec:
2121
imagePullSecrets:
2222
{{- toYaml . | nindent 8 }}
2323
{{- end }}
24+
serviceAccountName: {{ include "opal.serverServiceAccountName" . }}
25+
{{- with .Values.server.podSecurityContext }}
26+
securityContext:
27+
{{- toYaml . | nindent 8 }}
28+
{{- end }}
2429
{{- if .Values.e2e }}
2530
volumes:
2631
- name: e2e
@@ -34,6 +39,10 @@ spec:
3439
- name: git-init
3540
image: {{ include "opal.serverImage" . | quote }}
3641
imagePullPolicy: IfNotPresent
42+
{{- with .Values.server.securityContext }}
43+
securityContext:
44+
{{- toYaml . | nindent 12 }}
45+
{{- end }}
3746
volumeMounts:
3847
- mountPath: /opt/e2e
3948
name: e2e
@@ -63,6 +72,10 @@ spec:
6372
- name: opal-server
6473
image: {{ include "opal.serverImage" . | quote }}
6574
imagePullPolicy: {{ .Values.server.imagePullPolicy | default "IfNotPresent" | quote }}
75+
{{- with .Values.server.securityContext }}
76+
securityContext:
77+
{{- toYaml . | nindent 12 }}
78+
{{- end }}
6679
{{- if .Values.e2e }}
6780
volumeMounts:
6881
- mountPath: /opt/e2e/policy-repo-data

templates/ingress-client.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{{- if .Values.client.ingress.enabled -}}
2+
apiVersion: networking.k8s.io/v1
3+
kind: Ingress
4+
metadata:
5+
name: {{ include "opal.clientName" . }}
6+
labels:
7+
{{- include "opal.clientLabels" . | nindent 4 }}
8+
{{- with .Values.client.ingress.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
spec:
13+
{{- with .Values.client.ingress.className }}
14+
ingressClassName: {{ . }}
15+
{{- end }}
16+
{{- if .Values.client.ingress.tls }}
17+
tls:
18+
{{- range .Values.client.ingress.tls }}
19+
- hosts:
20+
{{- range .hosts }}
21+
- {{ . | quote }}
22+
{{- end }}
23+
secretName: {{ .secretName }}
24+
{{- end }}
25+
{{- end }}
26+
rules:
27+
{{- range .Values.client.ingress.hosts }}
28+
- host: {{ .host | quote }}
29+
http:
30+
paths:
31+
{{- range .paths }}
32+
- path: {{ .path }}
33+
{{- with .pathType }}
34+
pathType: {{ . }}
35+
{{- end }}
36+
backend:
37+
service:
38+
name: {{ include "opal.clientName" $ }}
39+
port:
40+
number: {{ .port }}
41+
{{- end }}
42+
{{- end }}
43+
{{- end }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if .Values.client.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "opal.clientServiceAccountName" . }}
6+
labels:
7+
{{- include "opal.clientLabels" . | nindent 4 }}
8+
{{- with .Values.client.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
automountServiceAccountToken: {{ .Values.client.serviceAccount.automount }}
13+
{{- end }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if .Values.server.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "opal.serverServiceAccountName" . }}
6+
labels:
7+
{{- include "opal.serverLabels" . | nindent 4 }}
8+
{{- with .Values.server.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
automountServiceAccountToken: {{ .Values.server.serviceAccount.automount }}
13+
{{- end }}

0 commit comments

Comments
 (0)