Skip to content

Commit

Permalink
Added custom pod annotation test (#3802)
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-tim-sumo authored Jul 17, 2024
1 parent 4e68f0c commit 8c9a6bf
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changelog/3802.changed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: Added custom pod annotation tests for global configuration attributes
2 changes: 2 additions & 0 deletions deploy/helm/sumologic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ The following table lists the configurable parameters of the Sumo Logic chart an
| `prometheus-windows-exporter` | Configuration for Prometheus Windows Exporter. [See external documentation.](https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-windows-exporter#configuring) | See [values.yaml] |
| `falco.enabled` | Flag to control deploying Falco Helm sub-chart. | `false` |
| `falco.podLabels` | Used to set podLabels for falco | `{}` |
| `falco.podAnnotations` | Used to set podAnnotations for falco | `{}` |
| `falco.fullnameOverride` | Used to override the chart's full name. | `Nil` |
| `falco.addKernelDevel` | Flag to control installation of `kernel-devel` on nodes using MachineConfig, required to build falco modules (only for OpenShift) | `true` |
| `falco.extra.initContainers` | InitContainers for Falco pod | See [values.yaml] |
Expand Down Expand Up @@ -331,6 +332,7 @@ The following table lists the configurable parameters of the Sumo Logic chart an
| `opentelemetry-operator.admissionWebhooks` | Admission webhooks make sure only requests with correctly formatted rules will get into the Operator. They also enable the sidecar injection for OpenTelemetryCollector and Instrumentation CR's. | See [values.yaml] |
| `opentelemetry-operator.manager.env` | Additional environment variables for opentelemetry-operator helm chart. | `{"ENABLE_WEBHOOKS": "true"}` |
| `opentelemetry-operator.manager.podLabels` | Used to set podLabels for OpenTelemetry-Operator Manager. | `{}` |
| `opentelemetry-operator.manager.podAnnotations` | Used to set podAnnotations for OpenTelemetry-Operator Manager. | `{}` |
| `opentelemetry-operator.kubeRBACProxy.image.repository` | Container repository for Kube RBAC Proxy. | `public.ecr.aws/sumologic/kube-rbac-proxy` |
| `opentelemetry-operator.testFramework.image.repository` | The default operator image repository for OpenTelemetry test framework. | `public.ecr.aws/sumologic/busybox` |
| `otelcolInstrumentation.enabled` | Enables Sumo Otel Distro Collector StatefulSet to collect telemetry data. [See docs for more information.](/docs/opentelemetry-collector/traces.md) | `true` |
Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/sumologic/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,7 @@ falco:
enabled: false

podLabels: {}
podAnnotations: {}

## Put here the new name if you want to override the full name used for Falco components.
# fullnameOverride: ""
Expand Down Expand Up @@ -2508,6 +2509,7 @@ opentelemetry-operator:
cpu: 150m
memory: 256Mi
podLabels: {}
podAnnotations: {}

kubeRBACProxy:
image:
Expand Down
31 changes: 26 additions & 5 deletions tests/helm/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ func TestServiceAccountPullSecrets(t *testing.T) {
}
}

func TestCustomPodLabels(t *testing.T) {
// tests podLabels and podAnnotations
func TestCustomPodData(t *testing.T) {
t.Parallel()
valuesFilePath := path.Join(testDataDirectory, "custom-podData.yaml")
renderedYamlString := RenderTemplate(
Expand Down Expand Up @@ -596,14 +597,15 @@ func TestCustomPodLabels(t *testing.T) {
continue
}

require.NoError(t, err)

labels := podTemplateSpec.Labels
labelValue, ok := labels[customLabelKey]
labelValue, labelOk := labels[customLabelKey]

annotations := podTemplateSpec.Annotations
annotationsValue, annotationsOk := annotations[customAnnotationsKey]

assert.True(
t,
ok,
labelOk,
"%s should have label %s",
renderedObject.GetName(),
customLabelKey,
Expand All @@ -619,5 +621,24 @@ func TestCustomPodLabels(t *testing.T) {
customLabelValue,
labelValue,
)

assert.True(
t,
annotationsOk,
"%s should have annotations %s",
renderedObject.GetName(),
customAnnotationsKey,
)

assert.Equal(
t,
customAnnotationsValue,
annotationsValue,
"%s should have annotations %s set to %s, found %s instead",
renderedObject.GetName(),
customAnnotationsKey,
customAnnotationsValue,
annotationsValue,
)
}
}
2 changes: 2 additions & 0 deletions tests/helm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
k8sMaxLabelLength = 63 // see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
customLabelKey = "customLabelKey"
customLabelValue = "customLabelValue"
customAnnotationsKey = "customAnnotationsKey"
customAnnotationsValue = "customAnnotationsValue"
)

var subChartNames []string = []string{
Expand Down
14 changes: 14 additions & 0 deletions tests/helm/testdata/custom-podData.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,46 @@ sumologic:

podLabels:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue

kube-prometheus-stack:
kube-state-metrics:
customLabels:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue
prometheus:
enabled: true
prometheusSpec:
podMetadata:
labels:
customLabelKey: customLabelValue
annotations:
customAnnotationsKey: customAnnotationsValue
prometheus-node-exporter:
podLabels:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue

opentelemetry-operator:
manager:
podLabels:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue

falco:
enabled: true
podLabels:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue

prometheus-windows-exporter:
enabled: true
podLabels:
customLabelKey: customLabelValue
podAnnotations:
customAnnotationsKey: customAnnotationsValue

0 comments on commit 8c9a6bf

Please sign in to comment.