Skip to content

Commit

Permalink
Merge pull request #415 from slok/slok/prepare-helm-release
Browse files Browse the repository at this point in the history
  • Loading branch information
slok authored Oct 26, 2022
2 parents 162a75d + c89c774 commit 4027a0a
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 185 deletions.
2 changes: 1 addition & 1 deletion deploy/kubernetes/helm/sloth/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ description: Base chart for Sloth.
type: application
home: https://github.com/slok/sloth
kubeVersion: ">= 1.19.0-0"
version: 0.6.2
version: 0.6.3
12 changes: 6 additions & 6 deletions deploy/kubernetes/helm/sloth/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ spec:
{{- end }}
spec:
serviceAccountName: {{ include "sloth.fullname" . }}
{{- with .Values.securityContext.pod }}
securityContext:
{{- with .Values.securityContext.pod }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
containers:
- name: sloth
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
Expand Down Expand Up @@ -79,10 +79,10 @@ spec:
mountPath: {{ .Values.customSloConfig.path }}
{{- end }}
{{- end }}
{{- with .Values.securityContext.container }}
securityContext:
{{- with .Values.securityContext.container }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.tolerations }}
Expand All @@ -101,10 +101,10 @@ spec:
- name: sloth-common-sli-plugins
# Default path for git-sync.
mountPath: /tmp/git
{{- with .Values.securityContext.container }}
securityContext:
{{- with .Values.securityContext.container }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.commonPlugins.gitRepo.resources | nindent 12 }}
{{- end }}
Expand Down
63 changes: 2 additions & 61 deletions deploy/kubernetes/helm/sloth/tests/helm_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func TestChartServiceAccount(t *testing.T) {
}

func TestChartDeployment(t *testing.T) {
checksumNormalizer := regexp.MustCompile(`checksum/config: [a-z0-9]+`)

tests := map[string]struct {
name string
namespace string
Expand Down Expand Up @@ -121,8 +123,6 @@ func TestChartDeployment(t *testing.T) {
},
}

checksumNormalizer := regexp.MustCompile(`checksum/config: [a-z0-9]+`)

for name, test := range tests {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
Expand Down Expand Up @@ -373,62 +373,3 @@ func TestChartConfigMap(t *testing.T) {
})
}
}

func TestChartSecurityContext(t *testing.T) {
tests := map[string]struct {
name string
namespace string
values func() map[string]interface{}
expErr bool
expTplFile string
}{
"A chart without security values should render correctly.": {
name: "sloth",
namespace: "default",
values: defaultValues,
expTplFile: "testdata/output/deployment_default.yaml",
},

"A chart with custom security values should render correctly.": {
name: "test",
namespace: "custom",
values: func() map[string]interface{} {
v := securityValues()
v["securityContext"].(msi)["enabled"] = true

return v
},
expTplFile: "testdata/output/deployment_securityContext.yaml",
},
}

checksumNormalizer := regexp.MustCompile(`checksum/config: [a-z0-9]+`)

for name, test := range tests {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

gotTpl, err := helm.Template(context.TODO(), helm.TemplateConfig{
Chart: slothChart,
Namespace: test.namespace,
ReleaseName: test.name,
Values: test.values(),
ShowFiles: []string{"templates/deployment.yaml"},
})

// Check.
if test.expErr {
assert.Error(err)
} else if assert.NoError(err) {
gotTpl := checksumNormalizer.ReplaceAllString(gotTpl, "checksum/config: <checksum>")

expTpl, err := os.ReadFile(test.expTplFile)
require.NoError(err)
expTplS := strings.TrimSpace(string(expTpl))

assert.Equal(expTplS, normalizeVersion(gotTpl))
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ spec:
spec:
serviceAccountName: sloth-test
securityContext:
fsGroup: 100
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 100
containers:
- name: sloth
image: slok/sloth-test:v1.42.42
Expand All @@ -54,6 +58,7 @@ spec:
- name: sloth-common-sli-plugins
mountPath: /plugins/sloth-common-sli-plugins
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: 50m
Expand All @@ -73,6 +78,7 @@ spec:
# Default path for git-sync.
mountPath: /tmp/git
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: 50m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ spec:
spec:
serviceAccountName: sloth-test
securityContext:
fsGroup: 100
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 100
containers:
- name: sloth
image: slok/sloth-test:v1.42.42
Expand All @@ -46,6 +50,7 @@ spec:
- --extra-labels=k2=v2
- --disable-optimized-rules
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: 50m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ spec:
spec:
serviceAccountName: sloth-test
securityContext:
fsGroup: 100
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 100
containers:
- name: sloth
image: slok/sloth-test:v1.42.42
Expand All @@ -55,6 +59,7 @@ spec:
- name: sloth-windows
mountPath: /windows
securityContext:
allowPrivilegeEscalation: false
resources:
limits:
cpu: 50m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ spec:
kubectl.kubernetes.io/default-container: sloth
spec:
serviceAccountName: sloth
securityContext:
containers:
- name: sloth
image: ghcr.io/slok/sloth:v0.11.0
Expand All @@ -44,7 +43,6 @@ spec:
volumeMounts:
- name: sloth-common-sli-plugins
mountPath: /plugins/sloth-common-sli-plugins
securityContext:
resources:
limits:
cpu: 50m
Expand All @@ -63,7 +61,6 @@ spec:
- name: sloth-common-sli-plugins
# Default path for git-sync.
mountPath: /tmp/git
securityContext:
resources:
limits:
cpu: 50m
Expand Down

This file was deleted.

16 changes: 4 additions & 12 deletions deploy/kubernetes/helm/sloth/tests/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,16 @@ func customValues() msi {
"customKey": "customValue",
},
},
}
}

func securityValues() msi {
return msi{
"securityContext": msi{
"pod": msi{
"runAsNonRoot": true,
"runAsGroup": 1000,
"runAsUser": 100,
"fsGroup": 100,
"supplementalGroups": "100",
"runAsNonRoot": true,
"runAsGroup": 1000,
"runAsUser": 100,
"fsGroup": 100,
},
"container": msi{
"allowPrivilegeEscalation": false,
"capabilities": msi{
"drop": "ALL",
},
},
},
}
Expand Down
10 changes: 7 additions & 3 deletions deploy/kubernetes/helm/sloth/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ customSloConfig:
# value: spot
# effect: NoSchedule

# add securityContext for pod and container level
securityContext:
pod: {}
container: {}
pod: null
# fsGroup: 100
# runAsGroup: 1000
# runAsNonRoot: true
# runAsUser: 100
container: null
# allowPrivilegeEscalation: false
Loading

0 comments on commit 4027a0a

Please sign in to comment.