Skip to content

Commit

Permalink
add test for adding pod and container security context
Browse files Browse the repository at this point in the history
  • Loading branch information
djkhl committed Nov 22, 2024
1 parent 7e69bba commit 5b4f7c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions charts/logprep/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ spec:
{{- end }}
containers:
- name: logprep
{{- if .Values.containerSecruityContext.enabled }}
securityContext: {{- omit .Values.containerSecruityContext "enabled" | toYaml | nindent 12 }}
{{- if .Values.containerSecurityContext.enabled }}
securityContext: {{- omit .Values.containerSecurityContext "enabled" | toYaml | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/logprep/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ podSecurityContext:
runAsUser: 1000

# if enabled: the default security context for the container
containerSecruityContext:
containerSecurityContext:
enabled: true
runAsNonRoot: true
readOnlyRootFilesystem: true
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/charts/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ def test_security_context(self):
assert security_context["readOnlyRootFilesystem"] is True
assert security_context["runAsNonRoot"] is True

def test_add_security_context(self):
self.manifests = self.render_chart(
"logprep",
{
"containerSecurityContext": {"allowPriviledgeEscalation": "false"},
"podSecurityContext": {"supplementalGroups": [4000]},
},
)
assert self.deployment["spec.template.spec.securityContext"]
security_context = self.deployment["spec.template.spec.securityContext"]
assert security_context["supplementalGroups"] == [4000]
security_context = self.deployment["spec.template.spec.containers.0.securityContext"]
assert security_context["allowPriviledgeEscalation"] == "false"

def test_resources(self):
assert self.deployment["spec.template.spec.containers.0.resources"]
resources = self.deployment["spec.template.spec.containers.0.resources"]
Expand Down

0 comments on commit 5b4f7c6

Please sign in to comment.