Skip to content

Commit

Permalink
Added custom image pull secrets integ test
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-tim-sumo committed Jul 31, 2024
1 parent 2ea0cff commit 366ae25
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 3 deletions.
1 change: 1 addition & 0 deletions .changelog/3808.1.changed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: Added image pull secrets support for statefulset
1 change: 1 addition & 0 deletions .changelog/3808.2.changed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: Added image pull secrets support for deployments
1 change: 1 addition & 0 deletions .changelog/3808.3.changed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: Added image pull secrets support for daemonset
1 change: 1 addition & 0 deletions .changelog/3808.4.changed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: Added image pull secrets support for jobs
1 change: 1 addition & 0 deletions .changelog/3808.changed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: Added custom image pull secrets tests for global configuration attributes
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ spec:
{{ toYaml .Values.otelevents.statefulset.podLabels | indent 8 }}
{{- end }}
spec:
{{- if $.Values.sumologic.pullSecrets }}
imagePullSecrets:
{{- range $.Values.sumologic.pullSecrets }}
- name: {{ .name }}
{{- end }}
{{- end }}
serviceAccountName: {{ template "sumologic.metadata.name.roles.serviceaccount" . }}
{{- if not (empty (include "events.statefulset.nodeSelector" .)) }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ spec:
{{ toYaml $otelcolInstrumentation.statefulset.podLabels | indent 8 }}
{{- end }}
spec:
{{- if $.Values.sumologic.pullSecrets }}
imagePullSecrets:
{{- range $.Values.sumologic.pullSecrets }}
- name: {{ .name }}
{{- end }}
{{- end }}
serviceAccountName: {{ template "sumologic.metadata.name.roles.serviceaccount" . }}
{{- if not (empty (include "otelcolInstrumentation.statefulset.nodeSelector" .)) }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ spec:
{{ toYaml $tracesGateway.deployment.podLabels | indent 8 }}
{{- end }}
spec:
{{- if $.Values.sumologic.pullSecrets }}
imagePullSecrets:
{{- range $.Values.sumologic.pullSecrets }}
- name: {{ .name }}
{{- end }}
{{- end }}
serviceAccountName: {{ template "sumologic.metadata.name.roles.serviceaccount" . }}
{{- if not (empty (include "tracesGateway.deployment.nodeSelector" .)) }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ spec:
{{ toYaml $tracesSampler.deployment.podLabels | indent 8 }}
{{- end }}
spec:
{{- if $.Values.sumologic.pullSecrets }}
imagePullSecrets:
{{- range $.Values.sumologic.pullSecrets }}
- name: {{ .name }}
{{- end }}
{{- end }}
serviceAccountName: {{ template "sumologic.metadata.name.roles.serviceaccount" . }}
{{- if not (empty (include "tracesSampler.deployment.nodeSelector" .)) }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ spec:
{{ toYaml $daemonset.podLabels | indent 8 }}
{{- end }}
spec:
{{- if $.Values.sumologic.pullSecrets }}
imagePullSecrets:
{{- range $.Values.sumologic.pullSecrets }}
- name: {{ .name }}
{{- end }}
{{- end }}
{{- if $nodeSelector }}
nodeSelector:
{{ $nodeSelector | indent 8 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ spec:
{{ toYaml $daemonset.podLabels | indent 8 }}
{{- end }}
spec:
{{- if $.Values.sumologic.pullSecrets }}
imagePullSecrets:
{{- range $.Values.sumologic.pullSecrets }}
- name: {{ .name }}
{{- end }}
{{- end }}
{{- if $nodeSelector }}
nodeSelector:
{{ $nodeSelector | indent 8 }}
Expand Down
6 changes: 6 additions & 0 deletions deploy/helm/sumologic/templates/logs/otelcol/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ spec:
{{ toYaml .Values.metadata.logs.statefulset.podLabels | indent 8 }}
{{- end }}
spec:
{{- if $.Values.sumologic.pullSecrets }}
imagePullSecrets:
{{- range $.Values.sumologic.pullSecrets }}
- name: {{ .name }}
{{- end }}
{{- end }}
serviceAccountName: {{ template "sumologic.metadata.name.roles.serviceaccount" . }}
{{- if not (empty (include "metadata.logs.statefulset.nodeSelector" .)) }}
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ spec:
{{ toYaml .Values.metadata.metrics.statefulset.podLabels | indent 8 }}
{{- end }}
spec:
{{- if $.Values.sumologic.pullSecrets }}
imagePullSecrets:
{{- range $.Values.sumologic.pullSecrets }}
- name: {{ .name }}
{{- end }}
{{- end }}
serviceAccountName: {{ template "sumologic.metadata.name.roles.serviceaccount" . }}
{{- if not (empty (include "metadata.metrics.statefulset.nodeSelector" .)) }}
nodeSelector:
Expand Down
6 changes: 6 additions & 0 deletions deploy/helm/sumologic/templates/setup/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ spec:
{{ toYaml .Values.sumologic.setup.job.podLabels | indent 8 }}
{{- end }}
spec:
{{- if $.Values.sumologic.pullSecrets }}
imagePullSecrets:
{{- range $.Values.sumologic.pullSecrets }}
- name: {{ .name }}
{{- end }}
{{- end }}
restartPolicy: OnFailure
serviceAccountName: {{ template "sumologic.metadata.name.setup.roles.serviceaccount" . }}
{{- if not (empty (include "setup.job.nodeSelector" .)) }}
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/sumologic/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@ telegraf-operator:
## Configure Falco
## Please note that Falco is embedded in this Helm Chart for user convenience only - Sumo Logic does not provide production support for it
## This is an experimental configuration and shouldn't be used in production environment
## https://github.com/falcosecurity/charts/tree/master/falco
## https://github.com/falcosecurity/charts/blob/master/charts/falco/values.yaml
falco:
enabled: false

Expand Down
2 changes: 1 addition & 1 deletion docs/working-with-container-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ kubectl create secret docker-registry ${SECRET_NAME} \
--docker-password=$(aws ecr-public --region us-east-1 get-login-password)
```

After creating the secret one can use it in the following way:
After creating the secret, one can use it in the following way:

```yaml
sumologic:
Expand Down
63 changes: 63 additions & 0 deletions tests/helm/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,15 @@ func GetTolerations(object unstructured.Unstructured) ([]corev1.Toleration, erro
return nil, nil
}

func ContainsImagePullSecret(imagePullSecrets []corev1.LocalObjectReference, expectedSecret string) bool {
for _, secret := range imagePullSecrets {
if secret.Name == expectedSecret {
return true
}
}
return false
}

func TestNamespaceOverride(t *testing.T) {
valuesFilePath := path.Join(testDataDirectory, "everything-enabled.yaml")
namespaceOverride := "override"
Expand Down Expand Up @@ -692,3 +701,57 @@ func TestCustomServiceAccountAnnotations(t *testing.T) {
}
}
}

func TestCustomImagePullSecrets(t *testing.T) {
t.Parallel()
valuesFilePath := path.Join(testDataDirectory, "custom-global-config-attributes.yaml")
renderedYamlString := RenderTemplate(
t,
&helm.Options{
ValuesFiles: []string{valuesFilePath},
SetStrValues: map[string]string{
"sumologic.accessId": "accessId",
"sumologic.accessKey": "accessKey",
},
Logger: logger.Discard,
},
chartDirectory,
releaseName,
[]string{},
true,
"--namespace",
defaultNamespace,
)

renderedObjects := UnmarshalMultipleFromYaml[unstructured.Unstructured](t, renderedYamlString)

for _, renderedObject := range renderedObjects {
kind := renderedObject.GetObjectKind().GroupVersionKind().Kind

// have a test for service account pull secrets: TestServiceAccountPullSecrets
if kind == "ServiceAccount" {
continue
}

podTemplateSpec, err := GetPodTemplateSpec(renderedObject)
if err != nil {
t.Logf("Error getting PodTemplateSpec for object %s: %v", renderedObject.GetName(), err)
continue
}

if podTemplateSpec == nil {
t.Logf("PodTemplateSpec is nil for object %s", renderedObject.GetName())
continue
}

require.NotEmpty(t, podTemplateSpec.Spec.ImagePullSecrets, "%s %s should have imagePullSecrets", kind, renderedObject.GetName())
assert.True(
t,
ContainsImagePullSecret(podTemplateSpec.Spec.ImagePullSecrets, customImagePullSecrets),
"Expected imagePullSecret %v not found in %s %s",
customImagePullSecrets,
kind,
renderedObject.GetName(),
)
}
}
2 changes: 2 additions & 0 deletions tests/helm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
customLabelValue = "customLabelValue"
customAnnotationsKey = "customAnnotationsKey"
customAnnotationsValue = "customAnnotationsValue"
customImagePullSecrets = "customImagePullSecrets"
customImagePullSecrets2 = "customImagePullSecrets2"
)

var subChartNames []string = []string{
Expand Down
28 changes: 27 additions & 1 deletion tests/helm/testdata/custom-global-config-attributes.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
sumologic:
pullSecrets:
- name: customImagePullSecrets
- name: customImagePullSecrets2
metrics:
remoteWriteProxy:
enabled: true

podLabels:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue
serviceAccount:
annotations:
customServiceAccountAnnotationKey: customServiceAccountAnnotationValue
setup:
job:
pullSecrets:
- name: customImagePullSecrets
- name: customImagePullSecrets2

kube-prometheus-stack:
global:
imagePullSecrets:
- name: customImagePullSecrets
- name: customImagePullSecrets2
kube-state-metrics:
customLabels:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue
imagePullSecrets:
- name: customImagePullSecrets
- name: customImagePullSecrets2
prometheus:
enabled: true
prometheusSpec:
Expand All @@ -26,6 +40,9 @@ kube-prometheus-stack:
annotations:
customAnnotationsKey: customAnnotationsValue
prometheus-node-exporter:
imagePullSecrets:
- name: customImagePullSecrets
- name: customImagePullSecrets2
podLabels:
customLabelKey: customLabelValue
podAnnotations:
Expand All @@ -37,9 +54,15 @@ opentelemetry-operator:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue
imagePullSecrets:
- name: customImagePullSecrets
- name: customImagePullSecrets2

falco:
enabled: true
imagePullSecrets:
- name: customImagePullSecrets
- name: customImagePullSecrets2
podLabels:
customLabelKey: customLabelValue
podAnnotations:
Expand All @@ -51,3 +74,6 @@ prometheus-windows-exporter:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue
imagePullSecrets:
- name: customImagePullSecrets
- name: customImagePullSecrets2

0 comments on commit 366ae25

Please sign in to comment.