Skip to content

Commit 3a37806

Browse files
refactor(rm): migrate CheckHealth interface to context.Context
Update ResourceManager interface and implementations to use context.Context for cancellation instead of a stop channel. This is more idiomatic Go and allows for better lifecycle control. Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
1 parent 84a3f93 commit 3a37806

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

internal/rm/nvml_manager.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package rm
1818

1919
import (
20+
"context"
2021
"fmt"
2122

2223
"github.com/NVIDIA/go-gpuallocator/gpuallocator"
@@ -91,8 +92,8 @@ func (r *nvmlResourceManager) GetDevicePaths(ids []string) []string {
9192
}
9293

9394
// CheckHealth performs health checks on a set of devices, writing to the 'unhealthy' channel with any unhealthy devices
94-
func (r *nvmlResourceManager) CheckHealth(stop <-chan interface{}, unhealthy chan<- *Device) error {
95-
return r.checkHealth(stop, r.devices, unhealthy)
95+
func (r *nvmlResourceManager) CheckHealth(ctx context.Context, unhealthy chan<- *Device) error {
96+
return r.checkHealth(ctx, r.devices, unhealthy)
9697
}
9798

9899
// getPreferredAllocation runs an allocation algorithm over the inputs.

internal/rm/rm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package rm
1818

1919
import (
20+
"context"
2021
"errors"
2122
"fmt"
2223
"strings"
@@ -44,7 +45,7 @@ type ResourceManager interface {
4445
Devices() Devices
4546
GetDevicePaths([]string) []string
4647
GetPreferredAllocation(available, required []string, size int) ([]string, error)
47-
CheckHealth(stop <-chan interface{}, unhealthy chan<- *Device) error
48+
CheckHealth(ctx context.Context, unhealthy chan<- *Device) error
4849
ValidateRequest(AnnotatedIDs) error
4950
}
5051

internal/rm/rm_mock.go

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/rm/tegra_manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package rm
1818

1919
import (
20+
"context"
2021
"fmt"
2122

2223
spec "github.com/NVIDIA/k8s-device-plugin/api/config/v1"
@@ -71,6 +72,6 @@ func (r *tegraResourceManager) GetDevicePaths(ids []string) []string {
7172
}
7273

7374
// CheckHealth is disabled for the tegraResourceManager
74-
func (r *tegraResourceManager) CheckHealth(stop <-chan interface{}, unhealthy chan<- *Device) error {
75+
func (r *tegraResourceManager) CheckHealth(_ context.Context, _ chan<- *Device) error {
7576
return nil
7677
}

0 commit comments

Comments
 (0)