Skip to content

Commit

Permalink
Add tests for runtime class changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gjulianm committed Jan 8, 2025
1 parent 4337bc5 commit 60173ad
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions internal/controller/datadogagent/feature/gpu/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/test"
)

const alternativeRuntimeClass = "nvidia-like"

func Test_GPUMonitoringFeature_Configure(t *testing.T) {
ddaGPUMonitoringDisabled := v2alpha1.DatadogAgent{
Spec: v2alpha1.DatadogAgentSpec{
Expand All @@ -29,7 +31,13 @@ func Test_GPUMonitoringFeature_Configure(t *testing.T) {
ddaGPUMonitoringEnabled := ddaGPUMonitoringDisabled.DeepCopy()
ddaGPUMonitoringEnabled.Spec.Features.GPUMonitoring.Enabled = apiutils.NewBoolPointer(true)

GPUMonitoringAgentNodeWantFunc := func(t testing.TB, mgrInterface feature.PodTemplateManagers) {
ddaGPUMonitoringEnabledAlternativeRuntimeClass := ddaGPUMonitoringEnabled.DeepCopy()
ddaGPUMonitoringEnabledAlternativeRuntimeClass.Spec.Features.GPUMonitoring.PodRuntimeClassName = apiutils.NewStringPointer(alternativeRuntimeClass)

ddaGPUMonitoringEnabledANoRuntimeClass := ddaGPUMonitoringEnabled.DeepCopy()
ddaGPUMonitoringEnabledANoRuntimeClass.Spec.Features.GPUMonitoring.PodRuntimeClassName = apiutils.NewStringPointer("")

GPUMonitoringAgentNodeWantFunc := func(t testing.TB, mgrInterface feature.PodTemplateManagers, expectedRuntimeClass string) {
mgr := mgrInterface.(*fake.PodTemplateManagers)

// check security context capabilities
Expand Down Expand Up @@ -128,6 +136,13 @@ func Test_GPUMonitoringFeature_Configure(t *testing.T) {

systemProbeEnvVars := mgr.EnvVarMgr.EnvVarsByC[apicommon.SystemProbeContainerName]
assert.True(t, apiutils.IsEqualStruct(systemProbeEnvVars, wantEnvVars), "System Probe envvars \ndiff = %s", cmp.Diff(systemProbeEnvVars, wantEnvVars))

// Check runtime class
if expectedRuntimeClass == "" {
assert.Nil(t, mgr.PodTemplateSpec().Spec.RuntimeClassName)
} else {
assert.Equal(t, expectedRuntimeClass, *mgr.PodTemplateSpec().Spec.RuntimeClassName)
}
}

tests := test.FeatureTestSuite{
Expand All @@ -140,7 +155,20 @@ func Test_GPUMonitoringFeature_Configure(t *testing.T) {
Name: "gpu monitoring enabled",
DDA: ddaGPUMonitoringEnabled,
WantConfigure: true,
Agent: test.NewDefaultComponentTest().WithWantFunc(GPUMonitoringAgentNodeWantFunc),
Agent: test.NewDefaultComponentTest().WithWantFunc(func(t testing.TB, mgrInterface feature.PodTemplateManagers) { GPUMonitoringAgentNodeWantFunc(t, mgrInterface, v2alpha1.DefaultGPUMonitoringRuntimeClass) }),
},
{
Name: "gpu monitoring enabled, alternative runtime class",
DDA: ddaGPUMonitoringEnabledAlternativeRuntimeClass,
WantConfigure: true,
Agent: test.NewDefaultComponentTest().WithWantFunc(func(t testing.TB, mgrInterface feature.PodTemplateManagers) { GPUMonitoringAgentNodeWantFunc(t, mgrInterface, alternativeRuntimeClass) }),
},

{
Name: "gpu monitoring enabled, no runtime class",
DDA: ddaGPUMonitoringEnabledANoRuntimeClass,
WantConfigure: true,
Agent: test.NewDefaultComponentTest().WithWantFunc(func(t testing.TB, mgrInterface feature.PodTemplateManagers) { GPUMonitoringAgentNodeWantFunc(t, mgrInterface, "") }),
},
}

Expand Down

0 comments on commit 60173ad

Please sign in to comment.