Skip to content

Commit b93fb47

Browse files
committed
refactor: Simplify resource manager construction
In order to prepare for the WSL changes, we remove the tegra resource manager and pull the basic function implementations into the base type. This means that the base type is essentially a resource manager that does not support health checking and always uses distributed allocation. Signed-off-by: Evan Lezar <[email protected]>
1 parent 51f7ece commit b93fb47

3 files changed

Lines changed: 23 additions & 31 deletions

File tree

internal/rm/nvml_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (r *nvmlResourceManager) GetDevicePaths(ids []string) []string {
8787
"/dev/nvidia-modeset",
8888
}
8989

90-
return append(paths, r.Devices().Subset(ids).GetPaths()...)
90+
return append(paths, r.resourceManager.GetDevicePaths(ids)...)
9191
}
9292

9393
// CheckHealth performs health checks on a set of devices, writing to the 'unhealthy' channel with any unhealthy devices

internal/rm/rm.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ type ResourceManager interface {
4848
ValidateRequest(AnnotatedIDs) error
4949
}
5050

51+
var _ ResourceManager = (*resourceManager)(nil)
52+
53+
// CheckHealth is disabled on the base resourceManager.
54+
func (r *resourceManager) CheckHealth(stop <-chan interface{}, unhealthy chan<- *Device) error {
55+
return nil
56+
}
57+
58+
// GetDevicePaths returns the paths for the devices associated with the resource manager.
59+
func (r *resourceManager) GetDevicePaths(ids []string) []string {
60+
return r.Devices().Subset(ids).GetPaths()
61+
}
62+
63+
// GetPreferredAllocation runs an allocation algorithm over the inputs.
64+
func (r *resourceManager) GetPreferredAllocation(available, required []string, size int) ([]string, error) {
65+
return r.distributedAlloc(available, required, size)
66+
}
67+
5168
// Resource gets the resource name associated with the ResourceManager
5269
func (r *resourceManager) Resource() spec.ResourceName {
5370
return r.resource

internal/rm/tegra_manager.go

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ import (
2222
spec "github.com/NVIDIA/k8s-device-plugin/api/config/v1"
2323
)
2424

25-
type tegraResourceManager struct {
26-
resourceManager
27-
}
28-
29-
var _ ResourceManager = (*tegraResourceManager)(nil)
30-
3125
// NewTegraResourceManagers returns a set of ResourceManagers for tegra resources
3226
func NewTegraResourceManagers(config *spec.Config) ([]ResourceManager, error) {
3327
deviceMap, err := buildTegraDeviceMap(config)
@@ -45,32 +39,13 @@ func NewTegraResourceManagers(config *spec.Config) ([]ResourceManager, error) {
4539
if len(devices) == 0 {
4640
continue
4741
}
48-
r := &tegraResourceManager{
49-
resourceManager: resourceManager{
50-
config: config,
51-
resource: resourceName,
52-
devices: devices,
53-
},
54-
}
55-
if len(devices) != 0 {
56-
rms = append(rms, r)
42+
r := &resourceManager{
43+
config: config,
44+
resource: resourceName,
45+
devices: devices,
5746
}
47+
rms = append(rms, r)
5848
}
5949

6050
return rms, nil
6151
}
62-
63-
// GetPreferredAllocation returns a standard allocation for the Tegra resource manager.
64-
func (r *tegraResourceManager) GetPreferredAllocation(available, required []string, size int) ([]string, error) {
65-
return r.distributedAlloc(available, required, size)
66-
}
67-
68-
// GetDevicePaths returns an empty slice for the tegraResourceManager
69-
func (r *tegraResourceManager) GetDevicePaths(ids []string) []string {
70-
return nil
71-
}
72-
73-
// CheckHealth is disabled for the tegraResourceManager
74-
func (r *tegraResourceManager) CheckHealth(stop <-chan interface{}, unhealthy chan<- *Device) error {
75-
return nil
76-
}

0 commit comments

Comments
 (0)