Skip to content

Commit 12f028d

Browse files
committed
feat(chart): add securityContext, priorityClassName, and standard labels
Add support for Kubernetes security and scheduling best practices: - Add configurable `podSecurityContext` (default: `fsGroup: 1000`, preserving existing behavior) and `securityContext` for the container (default: `{}`, no change for existing users) - Add `priorityClassName` value (default: empty, field not emitted) - Add standard `app.kubernetes.io/*` labels via helpers while keeping the existing `app: <name>` selector labels for backwards compatibility These changes allow deployments to comply with Kubernetes PodSecurity "restricted" profile and common policy engines (Kyverno, OPA/Gatekeeper) without breaking existing installations. Selector labels (`spec.selector.matchLabels`) are intentionally left unchanged to avoid breaking rolling updates on existing deployments. Example values for PodSecurity "restricted" compliance: securityContext: runAsNonRoot: true allowPrivilegeEscalation: false capabilities: drop: ["ALL"] seccompProfile: type: RuntimeDefault priorityClassName: my-priority-class
1 parent ca832e8 commit 12f028d

5 files changed

Lines changed: 60 additions & 1 deletion

File tree

charts/trek/templates/_helpers.tpl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,30 @@ Create a default fully qualified app name.
1616
{{- printf "%s" $name | trunc 63 | trimSuffix "-" -}}
1717
{{- end -}}
1818
{{- end -}}
19+
20+
{{/*
21+
Create chart name and version as used by the chart label.
22+
*/}}
23+
{{- define "trek.chart" -}}
24+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Common labels
29+
*/}}
30+
{{- define "trek.labels" -}}
31+
helm.sh/chart: {{ include "trek.chart" . }}
32+
{{ include "trek.selectorLabels" . }}
33+
{{- if .Chart.AppVersion }}
34+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
35+
{{- end }}
36+
app.kubernetes.io/managed-by: {{ .Release.Service }}
37+
{{- end -}}
38+
39+
{{/*
40+
Selector labels
41+
*/}}
42+
{{- define "trek.selectorLabels" -}}
43+
app.kubernetes.io/name: {{ include "trek.name" . }}
44+
app.kubernetes.io/instance: {{ .Release.Name }}
45+
{{- end -}}

charts/trek/templates/deployment.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: {{ include "trek.fullname" . }}
55
labels:
66
app: {{ include "trek.name" . }}
7+
{{- include "trek.labels" . | nindent 4 }}
78
spec:
89
replicas: 1
910
selector:
@@ -16,19 +17,29 @@ spec:
1617
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
1718
labels:
1819
app: {{ include "trek.name" . }}
20+
{{- include "trek.selectorLabels" . | nindent 8 }}
1921
spec:
2022
{{- if .Values.imagePullSecrets }}
2123
imagePullSecrets:
2224
{{- range .Values.imagePullSecrets }}
2325
- name: {{ .name }}
2426
{{- end }}
2527
{{- end }}
28+
{{- with .Values.podSecurityContext }}
2629
securityContext:
27-
fsGroup: 1000
30+
{{- toYaml . | nindent 8 }}
31+
{{- end }}
32+
{{- if .Values.priorityClassName }}
33+
priorityClassName: {{ .Values.priorityClassName }}
34+
{{- end }}
2835
containers:
2936
- name: trek
3037
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
3138
imagePullPolicy: {{ .Values.image.pullPolicy }}
39+
{{- with .Values.securityContext }}
40+
securityContext:
41+
{{- toYaml . | nindent 12 }}
42+
{{- end }}
3243
{{- with .Values.resources }}
3344
resources:
3445
{{- toYaml . | nindent 12 }}

charts/trek/templates/ingress.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ metadata:
55
name: {{ include "trek.fullname" . }}
66
labels:
77
app: {{ include "trek.name" . }}
8+
{{- include "trek.labels" . | nindent 4 }}
89
{{- with .Values.ingress.annotations }}
910
annotations:
1011
{{- toYaml . | nindent 4 }}

charts/trek/templates/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: {{ include "trek.fullname" . }}
55
labels:
66
app: {{ include "trek.name" . }}
7+
{{- include "trek.labels" . | nindent 4 }}
78
spec:
89
type: {{ .Values.service.type }}
910
ports:

charts/trek/values.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ generateEncryptionKey: false
9090
existingSecret: ""
9191
existingSecretKey: ENCRYPTION_KEY
9292

93+
# Pod-level security context (applied to the pod spec)
94+
podSecurityContext:
95+
fsGroup: 1000
96+
97+
# Container-level security context (applied to the trek container)
98+
# Example for PodSecurity "restricted" compliance:
99+
# runAsNonRoot: true
100+
# allowPrivilegeEscalation: false
101+
# capabilities:
102+
# drop:
103+
# - ALL
104+
# seccompProfile:
105+
# type: RuntimeDefault
106+
securityContext: {}
107+
108+
# Priority class name for the pod
109+
# See: https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/
110+
priorityClassName: ""
111+
93112
persistence:
94113
enabled: true
95114
data:

0 commit comments

Comments
 (0)