Skip to content

Commit eead2dc

Browse files
committed
chore: add telemetry disabled test to instance tests and update to use helpers
1 parent b5beed8 commit eead2dc

3 files changed

Lines changed: 43 additions & 36 deletions

File tree

tests/unit/helm/delegated-operator-instance-deployment_test.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5711,16 +5711,6 @@ func (s *deploymentDelegatedOperatorInstanceTemplateTest) TestTelemetrySocketInj
57115711
}
57125712
return n
57135713
}
5714-
// findContainer returns the named container (the main DO container,
5715-
// not the telemetry-sidecar) from a pod spec.
5716-
findContainer := func(containers []corev1.Container, name string) *corev1.Container {
5717-
for i, c := range containers {
5718-
if c.Name == name {
5719-
return &containers[i]
5720-
}
5721-
}
5722-
return nil
5723-
}
57245714

57255715
testCases := []struct {
57265716
name string
@@ -5784,6 +5774,38 @@ func (s *deploymentDelegatedOperatorInstanceTemplateTest) TestTelemetrySocketInj
57845774
}
57855775
}
57865776

5777+
// TestTelemetryDisabledOmitsSidecar verifies that when telemetry is disabled
5778+
// the rendered DO deployment carries neither the telemetry-sidecar container nor
5779+
// the telemetry-socket volume/mount. The disabled shape is also covered
5780+
// indirectly by TestContainerCount (container count is 1, not 2) and the
5781+
// disableTelemetry-based volume/mount tests; this is the focused negative
5782+
// assertion living next to the positive cases above.
5783+
func (s *deploymentDelegatedOperatorInstanceTemplateTest) TestTelemetryDisabledOmitsSidecar() {
5784+
const socketName = "telemetry-socket"
5785+
5786+
options := &helm.Options{SetValues: map[string]string{
5787+
"telemetry.enabled": "false",
5788+
"delegatedOperatorDeployments.deployments.teamsDoCpuDefault.enabled": "true",
5789+
}}
5790+
output := helm.RenderTemplate(s.T(), options, s.chartPath, s.releaseName, s.templates)
5791+
5792+
docs := strings.Split(output, "---")
5793+
s.Require().GreaterOrEqual(len(docs), 2, "expected at least one rendered deployment")
5794+
5795+
var deployment appsv1.Deployment
5796+
helm.UnmarshalK8SYaml(s.T(), docs[1], &deployment)
5797+
5798+
s.Nil(findContainer(deployment.Spec.Template.Spec.Containers, "telemetry-sidecar"),
5799+
"telemetry-sidecar container should be absent when telemetry is disabled")
5800+
s.Nil(findVolume(deployment.Spec.Template.Spec.Volumes, socketName),
5801+
"telemetry-socket volume should be absent when telemetry is disabled")
5802+
5803+
main := findContainer(deployment.Spec.Template.Spec.Containers, "teams-do-cpu-default")
5804+
s.Require().NotNil(main, "main DO container not found")
5805+
s.Nil(findVolumeMount(main.VolumeMounts, socketName),
5806+
"telemetry-socket volumeMount should be absent when telemetry is disabled")
5807+
}
5808+
57875809
// TestTelemetrySidecarGpuEnv verifies that when a delegated-operator executor
57885810
// requests a GPU (via resources.limits or resources.requests), its
57895811
// telemetry-sidecar is given the NVIDIA_* env vars needed to read GPU metrics,
@@ -5792,23 +5814,6 @@ func (s *deploymentDelegatedOperatorInstanceTemplateTest) TestTelemetrySocketInj
57925814
func (s *deploymentDelegatedOperatorInstanceTemplateTest) TestTelemetrySidecarGpuEnv() {
57935815
const gpuResource = "nvidia.com/gpu"
57945816

5795-
findContainer := func(containers []corev1.Container, name string) *corev1.Container {
5796-
for i, c := range containers {
5797-
if c.Name == name {
5798-
return &containers[i]
5799-
}
5800-
}
5801-
return nil
5802-
}
5803-
envValue := func(env []corev1.EnvVar, name string) (string, bool) {
5804-
for _, e := range env {
5805-
if e.Name == name {
5806-
return e.Value, true
5807-
}
5808-
}
5809-
return "", false
5810-
}
5811-
58125817
// gpuKey escapes the dot in nvidia.com/gpu so helm --set treats the whole
58135818
// string as a single map key rather than a nested path.
58145819
gpuKey := func(section string) string {

tests/unit/helm/delegated-operator-job-configmap_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -792,15 +792,6 @@ func (s *doK8sConfigMapTemplateTest) TestTelemetrySidecarGpuEnv() {
792792
const gpuResource = "nvidia.com/gpu"
793793
jobKey := "cpuDefault.yaml"
794794

795-
envValue := func(env []corev1.EnvVar, name string) (string, bool) {
796-
for _, e := range env {
797-
if e.Name == name {
798-
return e.Value, true
799-
}
800-
}
801-
return "", false
802-
}
803-
804795
// gpuKey escapes the dot in nvidia.com/gpu so helm --set treats the whole
805796
// string as a single map key rather than a nested path.
806797
gpuKey := func(section string) string {

tests/unit/helm/k8s_helpers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,14 @@ func findVolumeMount(mounts []corev1.VolumeMount, name string) *corev1.VolumeMou
3232
}
3333
return nil
3434
}
35+
36+
// envValue returns the value of the env var with the given name and whether it
37+
// was found.
38+
func envValue(env []corev1.EnvVar, name string) (string, bool) {
39+
for _, e := range env {
40+
if e.Name == name {
41+
return e.Value, true
42+
}
43+
}
44+
return "", false
45+
}

0 commit comments

Comments
 (0)