Skip to content

Commit 5c5c83d

Browse files
committed
Make pods/containers security context configurable
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
1 parent 0b57900 commit 5c5c83d

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

charts/ocg/templates/_helpers.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ longest resource name ("db-migrator-install" = 19 chars).
7878
Provide an init container to verify the database is accessible
7979
*/}}
8080
{{- define "chart.checkDbIsReadyInitContainer" -}}
81+
{{- $securityContext := default (dict) .Values.checkDbIsReadyInitContainer.securityContext }}
8182
name: check-db-ready
8283
{{ if .Values.postgresql.image.registry -}}
8384
image: {{ .Values.postgresql.image.registry }}/{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}
@@ -92,6 +93,11 @@ env:
9293
value: "{{ .Values.db.port }}"
9394
- name: PGUSER
9495
value: "{{ .Values.db.user }}"
96+
{{- if $securityContext }}
97+
securityContext:{{- toYaml $securityContext | nindent 2 }}
98+
{{- else }}
99+
securityContext: {}
100+
{{- end }}
95101
command: ['sh', '-c', 'until pg_isready; do echo waiting for database; sleep 2; done;']
96102
{{- end -}}
97103

charts/ocg/templates/db_migrator_job.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ metadata:
1313
spec:
1414
template:
1515
spec:
16+
{{- with .Values.dbmigrator.job.podSecurityContext }}
17+
securityContext:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
1620
{{- with .Values.imagePullSecrets }}
1721
imagePullSecrets:
1822
{{- toYaml . | nindent 8 }}
@@ -24,6 +28,10 @@ spec:
2428
- name: dbmigrator
2529
image: {{ .Values.dbmigrator.job.image.repository }}:{{ .Values.imageTag | default (printf "v%s" .Chart.AppVersion) }}
2630
imagePullPolicy: {{ .Values.pullPolicy }}
31+
{{- with .Values.dbmigrator.job.containerSecurityContext }}
32+
securityContext:
33+
{{- toYaml . | nindent 12 }}
34+
{{- end }}
2735
env:
2836
- name: TERN_CONF
2937
value: {{ .Values.configDir }}/tern.conf

charts/ocg/templates/server_deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ spec:
1717
app.kubernetes.io/component: server
1818
{{- include "chart.selectorLabels" . | nindent 8 }}
1919
spec:
20+
{{- with .Values.server.deploy.podSecurityContext }}
21+
securityContext:
22+
{{- toYaml . | nindent 8 }}
23+
{{- end }}
2024
{{- with .Values.imagePullSecrets }}
2125
imagePullSecrets:
2226
{{- toYaml . | nindent 8 }}
@@ -38,6 +42,10 @@ spec:
3842
- name: server
3943
image: {{ .Values.server.deploy.image.repository }}:{{ .Values.imageTag | default (printf "v%s" .Chart.AppVersion) }}
4044
imagePullPolicy: {{ .Values.pullPolicy }}
45+
{{- with .Values.server.deploy.containerSecurityContext }}
46+
securityContext:
47+
{{- toYaml . | nindent 12 }}
48+
{{- end }}
4149
volumeMounts:
4250
- name: server-config
4351
mountPath: {{ .Values.configDir | quote }}

charts/ocg/values.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ fullnameOverride: ""
1818
# Directory path where the configuration files should be mounted
1919
configDir: "/home/ocg/.config/ocg"
2020

21+
# Check database readiness init container configuration
22+
checkDbIsReadyInitContainer:
23+
securityContext: {}
24+
2125
# Database configuration
2226
db:
2327
host: ""
@@ -53,9 +57,11 @@ log:
5357
# Database migrator configuration
5458
dbmigrator:
5559
job:
60+
containerSecurityContext: {}
5661
image:
5762
# Database migrator image repository (without the tag)
5863
repository: ocg/dbmigrator
64+
podSecurityContext: {}
5965

6066
# Server configuration
6167
server:
@@ -137,10 +143,12 @@ server:
137143

138144
# Deployment configuration
139145
deploy:
140-
replicaCount: 1
146+
containerSecurityContext: {}
141147
image:
142148
# Database migrator image repository (without the tag)
143149
repository: ocg/server
150+
podSecurityContext: {}
151+
replicaCount: 1
144152
resources: {}
145153

146154
# PostgreSQL configuration

database/tests/scripts/ocg_db_tests

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env bash
22

33
# Database configuration
4-
export PGHOST="${PGHOST:-localhost}"
4+
export PGHOST="${PGHOST:-/private/tmp}"
55
export PGPORT="${PGPORT:-5432}"
66
export PGUSER="${PGUSER:-postgres}"
77
export PGDATABASE="${PGDATABASE:-ocg_tests}"
88
export PGSSLMODE="${PGSSLMODE:-disable}"
99

1010
# Prepare tern config file
11-
tern_config=$(mktemp /tmp/tern.conf.XXXXXX)
11+
export TERN_CONF_TESTS_PATH="${TERN_CONF_TESTS_PATH:-/tmp/ocg/tern.conf.XXXXXX}"
12+
tern_config=$(mktemp $TERN_CONF_TESTS_PATH)
1213
cat > "$tern_config" <<EOF
1314
[database]
1415
host=$PGHOST

0 commit comments

Comments
 (0)