-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(integration): Added custom pod label tests for global configuration attributes #3795
Conversation
cf2c39c
to
daf5cb7
Compare
Is that actually works? I'm trying to understand the flow and for me it looks like you are trying to check if rendered pod definition (which for example looks like this: https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/tests/helm/testdata/goldenfile/events_otc_statefulset/basic.output.yaml) contains The code should look like more like sumologic-kubernetes-collection/tests/helm/common_test.go Lines 129 to 180 in e52a34c
Because aim of the task is to check if all pods/serviceaccounts/etc have the labels set correctly The jira is not accessible outside of the organization so it would be much more Open Source to link correlated github issue instead I would also split this PR per individual change ( |
i see, i thought we needed to test to make sure labels are in the rendered objects, if it is to check if all pods/everything have the labels set correctly, i guess just need to check if the labels arent empty ? ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ if so, i'm confused, isn't there a test for labels on here? sumologic-kubernetes-collection/tests/helm/common_test.go Lines 48 to 83 in e52a34c
|
It tests for Helm built-in labels: sumologic-kubernetes-collection/tests/helm/common_test.go Lines 332 to 341 in e52a34c
Yes, but we want to check for exact value. We need to ensure that we are able to set additional pod labels, pod annotations and so on for every pod. Maybe we need to use multiple configuration keys to achieve it, but this is want we want to test and ensure. We want to test the following feature: https://help.sumologic.com/docs/send-data/kubernetes/best-practices/#pod-labels |
just to make sure i'm understanding this, if we want to check for EXACT values for ALL/additional pod labels, do you mean testing a custom pod label? since currently there is a test for BUILT-IN label only? 🤔 |
Yes, we want to check exact values for additional pod labels |
6ec82d0
to
6b01d3e
Compare
a1e6714
to
909ed9d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should enable optional components as well. see https://github.com/SumoLogic/sumologic-openshift-images/blob/main/scripts/values.yaml
tests/helm/common_test.go
Outdated
func GetPodTemplateSpec(object unstructured.Unstructured) (*corev1.PodTemplateSpec, error) { | ||
switch object.GetKind() { | ||
case "Deployment": | ||
deployment := &appsv1.Deployment{} | ||
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, deployment) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &deployment.Spec.Template, nil | ||
case "StatefulSet": | ||
statefulset := &appsv1.StatefulSet{} | ||
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, statefulset) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &statefulset.Spec.Template, nil | ||
case "DaemonSet": | ||
daemonset := &appsv1.DaemonSet{} | ||
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, daemonset) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &daemonset.Spec.Template, nil | ||
case "Job": | ||
job := &batchv1.Job{} | ||
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, job) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &job.Spec.Template, nil | ||
case "CronJob": | ||
cronJob := &batchv1.CronJob{} | ||
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, cronJob) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &cronJob.Spec.JobTemplate.Spec.Template, nil | ||
default: | ||
return nil, nil | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be simplified to something like this:
func GetPodTemplateSpec(object unstructured.Unstructured) (*corev1.PodTemplateSpec, error) { | |
switch object.GetKind() { | |
case "Deployment": | |
deployment := &appsv1.Deployment{} | |
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, deployment) | |
if err != nil { | |
return nil, err | |
} | |
return &deployment.Spec.Template, nil | |
case "StatefulSet": | |
statefulset := &appsv1.StatefulSet{} | |
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, statefulset) | |
if err != nil { | |
return nil, err | |
} | |
return &statefulset.Spec.Template, nil | |
case "DaemonSet": | |
daemonset := &appsv1.DaemonSet{} | |
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, daemonset) | |
if err != nil { | |
return nil, err | |
} | |
return &daemonset.Spec.Template, nil | |
case "Job": | |
job := &batchv1.Job{} | |
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, job) | |
if err != nil { | |
return nil, err | |
} | |
return &job.Spec.Template, nil | |
case "CronJob": | |
cronJob := &batchv1.CronJob{} | |
err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, cronJob) | |
if err != nil { | |
return nil, err | |
} | |
return &cronJob.Spec.JobTemplate.Spec.Template, nil | |
default: | |
return nil, nil | |
} | |
} | |
func GetPodTemplateSpec(object unstructured.Unstructured) (*corev1.PodTemplateSpec, error) { | |
spec, err := GetPodSpec(object) | |
if err != nil { | |
return nil, err | |
} | |
return spec.Template, nil | |
} | |
52bef0f
to
d5d5722
Compare
since most of the comments are here: another question i have is, I see pullSecrets and imagePullSecrets, are they the same? pod annotation and service account annotation is pretty intuitive. |
It seems like that. We cannot change the subcharts configuration keys :( |
d5d5722
to
94c296a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We should add missing configuration options (if any) to https://help.sumologic.com/docs/send-data/kubernetes/best-practices/#pod-labels
Overview
3 more to go:
Checklist