-
Notifications
You must be signed in to change notification settings - Fork 1
fix: detect gpu metrics in k8 gpu delegated-executor sidecars #583
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
Merged
kaixi-wang
merged 8 commits into
release/v2.21.0
from
kacey/fix-k8-gpu-sidecar-detection
Jul 1, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dfe670d
chore(deps): bump actions/setup-python from 6.2.0 to 6.3.0 (#589)
dependabot[bot] 9a5fa20
fix: add env vars to k8 gpu executor sidecars like docker
kaixi-wang 0f3513b
fix: simplify and assume accept-nvidia-visible-devices-envvar-when-un…
kaixi-wang 42c44ba
fix: add env vars to DO job templates and add tests (#592)
mo-getter 5dd008f
Apply suggestion from @kevin-dimichel
kaixi-wang 7283cc1
chore: create shared utils and add negative test
kaixi-wang b5beed8
Merge remote-tracking branch 'refs/remotes/origin/kacey/fix-k8-gpu-si…
kaixi-wang eead2dc
chore: add telemetry disabled test to instance tests and update to us…
kaixi-wang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5711,16 +5711,6 @@ func (s *deploymentDelegatedOperatorInstanceTemplateTest) TestTelemetrySocketInj | |
| } | ||
| return n | ||
| } | ||
| // findContainer returns the named container (the main DO container, | ||
| // not the telemetry-sidecar) from a pod spec. | ||
| findContainer := func(containers []corev1.Container, name string) *corev1.Container { | ||
| for i, c := range containers { | ||
| if c.Name == name { | ||
| return &containers[i] | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
|
|
@@ -5783,3 +5773,123 @@ func (s *deploymentDelegatedOperatorInstanceTemplateTest) TestTelemetrySocketInj | |
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestTelemetryDisabledOmitsSidecar verifies that when telemetry is disabled | ||
| // the rendered DO deployment carries neither the telemetry-sidecar container nor | ||
| // the telemetry-socket volume/mount. The disabled shape is also covered | ||
| // indirectly by TestContainerCount (container count is 1, not 2) and the | ||
| // disableTelemetry-based volume/mount tests; this is the focused negative | ||
| // assertion living next to the positive cases above. | ||
| func (s *deploymentDelegatedOperatorInstanceTemplateTest) TestTelemetryDisabledOmitsSidecar() { | ||
| const socketName = "telemetry-socket" | ||
|
|
||
| options := &helm.Options{SetValues: map[string]string{ | ||
| "telemetry.enabled": "false", | ||
| "delegatedOperatorDeployments.deployments.teamsDoCpuDefault.enabled": "true", | ||
| }} | ||
| output := helm.RenderTemplate(s.T(), options, s.chartPath, s.releaseName, s.templates) | ||
|
|
||
| docs := strings.Split(output, "---") | ||
| s.Require().GreaterOrEqual(len(docs), 2, "expected at least one rendered deployment") | ||
|
|
||
| var deployment appsv1.Deployment | ||
| helm.UnmarshalK8SYaml(s.T(), docs[1], &deployment) | ||
|
|
||
| s.Nil(findContainer(deployment.Spec.Template.Spec.Containers, "telemetry-sidecar"), | ||
| "telemetry-sidecar container should be absent when telemetry is disabled") | ||
| s.Nil(findVolume(deployment.Spec.Template.Spec.Volumes, socketName), | ||
| "telemetry-socket volume should be absent when telemetry is disabled") | ||
|
|
||
| main := findContainer(deployment.Spec.Template.Spec.Containers, "teams-do-cpu-default") | ||
| s.Require().NotNil(main, "main DO container not found") | ||
| s.Nil(findVolumeMount(main.VolumeMounts, socketName), | ||
| "telemetry-socket volumeMount should be absent when telemetry is disabled") | ||
| } | ||
|
|
||
| // TestTelemetrySidecarGpuEnv verifies that when a delegated-operator executor | ||
| // requests a GPU (via resources.limits or resources.requests), its | ||
| // telemetry-sidecar is given the NVIDIA_* env vars needed to read GPU metrics, | ||
| // without the sidecar requesting its own nvidia.com/gpu allocation. When no GPU | ||
| // is requested, the sidecar receives no NVIDIA_* env vars. | ||
| func (s *deploymentDelegatedOperatorInstanceTemplateTest) TestTelemetrySidecarGpuEnv() { | ||
| const gpuResource = "nvidia.com/gpu" | ||
|
|
||
| // gpuKey escapes the dot in nvidia.com/gpu so helm --set treats the whole | ||
| // string as a single map key rather than a nested path. | ||
| gpuKey := func(section string) string { | ||
| return "delegatedOperatorDeployments.deployments.teamsDoCpuDefault.resources." + | ||
| section + ".nvidia\\.com/gpu" | ||
| } | ||
|
|
||
| testCases := []struct { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a test case for when |
||
| name string | ||
| values map[string]string | ||
| expectGpu bool | ||
| }{ | ||
| { | ||
| name: "gpuInLimitsExposesEnvToSidecar", | ||
| values: map[string]string{ | ||
| "telemetry.enabled": "true", | ||
| "delegatedOperatorDeployments.deployments.teamsDoCpuDefault.enabled": "true", | ||
| gpuKey("limits"): "1", | ||
| }, | ||
| expectGpu: true, | ||
| }, | ||
| { | ||
| name: "gpuInRequestsExposesEnvToSidecar", | ||
| values: map[string]string{ | ||
| "telemetry.enabled": "true", | ||
| "delegatedOperatorDeployments.deployments.teamsDoCpuDefault.enabled": "true", | ||
| gpuKey("requests"): "1", | ||
| }, | ||
| expectGpu: true, | ||
| }, | ||
| { | ||
| name: "noGpuOmitsEnvFromSidecar", | ||
| values: map[string]string{ | ||
| "telemetry.enabled": "true", | ||
| "delegatedOperatorDeployments.deployments.teamsDoCpuDefault.enabled": "true", | ||
| }, | ||
| expectGpu: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| tc := tc | ||
| s.Run(tc.name, func() { | ||
| subT := s.T() | ||
| subT.Parallel() | ||
|
|
||
| options := &helm.Options{SetValues: tc.values} | ||
| output := helm.RenderTemplate(subT, options, s.chartPath, s.releaseName, s.templates) | ||
|
|
||
| docs := strings.Split(output, "---") | ||
| s.Require().GreaterOrEqual(len(docs), 2, "expected at least one rendered deployment") | ||
|
|
||
| var deployment appsv1.Deployment | ||
| helm.UnmarshalK8SYaml(subT, docs[1], &deployment) | ||
|
|
||
| sidecar := findContainer(deployment.Spec.Template.Spec.Containers, "telemetry-sidecar") | ||
| s.Require().NotNil(sidecar, "telemetry-sidecar container not found") | ||
|
|
||
| visibleDevices, hasVisibleDevices := envValue(sidecar.Env, "NVIDIA_VISIBLE_DEVICES") | ||
| driverCaps, hasDriverCaps := envValue(sidecar.Env, "NVIDIA_DRIVER_CAPABILITIES") | ||
|
|
||
| if tc.expectGpu { | ||
| s.True(hasVisibleDevices, "sidecar should have NVIDIA_VISIBLE_DEVICES") | ||
| s.Equal("all", visibleDevices, "NVIDIA_VISIBLE_DEVICES value mismatch") | ||
| s.True(hasDriverCaps, "sidecar should have NVIDIA_DRIVER_CAPABILITIES") | ||
| s.Equal("compute,utility", driverCaps, "NVIDIA_DRIVER_CAPABILITIES value mismatch") | ||
|
|
||
| // The sidecar reads the executor's GPU; it must not request its own. | ||
| _, limitsHasGpu := sidecar.Resources.Limits[corev1.ResourceName(gpuResource)] | ||
| _, requestsHasGpu := sidecar.Resources.Requests[corev1.ResourceName(gpuResource)] | ||
| s.False(limitsHasGpu, "sidecar must not request nvidia.com/gpu in limits") | ||
| s.False(requestsHasGpu, "sidecar must not request nvidia.com/gpu in requests") | ||
| } else { | ||
| s.False(hasVisibleDevices, "sidecar should not have NVIDIA_VISIBLE_DEVICES when no GPU requested") | ||
| s.False(hasDriverCaps, "sidecar should not have NVIDIA_DRIVER_CAPABILITIES when no GPU requested") | ||
| } | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In the future, let's consider the tech debt of adding functions like this. Do we need to add tests for the test functions? Being declarative in tests is often preferred to these.
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.
moved to a shared file