Skip to content

Commit dbdecb1

Browse files
authored
Merge pull request #343 from jgehrcke/jp/remove-pbdevice
Replace `drapbv1.Device` in CD+GPU plugins
2 parents 97b02f0 + 7140ea1 commit dbdecb1

File tree

7 files changed

+35
-58
lines changed

7 files changed

+35
-58
lines changed

cmd/compute-domain-kubelet-plugin/device_state.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424

2525
resourceapi "k8s.io/api/resource/v1beta1"
2626
"k8s.io/apimachinery/pkg/runtime"
27+
"k8s.io/dynamic-resource-allocation/kubeletplugin"
2728
"k8s.io/klog/v2"
28-
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1beta1"
2929
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
3030
cdiapi "tags.cncf.io/container-device-interface/pkg/cdi"
3131

@@ -128,7 +128,7 @@ func NewDeviceState(ctx context.Context, config *Config) (*DeviceState, error) {
128128
return state, nil
129129
}
130130

131-
func (s *DeviceState) Prepare(ctx context.Context, claim *resourceapi.ResourceClaim) ([]*drapbv1.Device, error) {
131+
func (s *DeviceState) Prepare(ctx context.Context, claim *resourceapi.ResourceClaim) ([]kubeletplugin.Device, error) {
132132
s.Lock()
133133
defer s.Unlock()
134134

@@ -254,8 +254,8 @@ func (s *DeviceState) prepareDevices(ctx context.Context, claim *resourceapi.Res
254254
cdiDevices = append(cdiDevices, d)
255255
}
256256

257-
device := &drapbv1.Device{
258-
RequestNames: []string{result.Request},
257+
device := kubeletplugin.Device{
258+
Requests: []string{result.Request},
259259
PoolName: result.Pool,
260260
DeviceName: result.Device,
261261
CDIDeviceIDs: cdiDevices,
@@ -266,12 +266,12 @@ func (s *DeviceState) prepareDevices(ctx context.Context, claim *resourceapi.Res
266266
case ComputeDomainChannelType:
267267
preparedDevice.Channel = &PreparedComputeDomainChannel{
268268
Info: s.allocatable[result.Device].Channel,
269-
Device: device,
269+
Device: &device,
270270
}
271271
case ComputeDomainDaemonType:
272272
preparedDevice.Daemon = &PreparedComputeDomainDaemon{
273273
Info: s.allocatable[result.Device].Daemon,
274-
Device: device,
274+
Device: &device,
275275
}
276276
}
277277

cmd/compute-domain-kubelet-plugin/driver.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,8 @@ func (d *driver) nodePrepareResource(ctx context.Context, claim *resourceapi.Res
196196
return isPermanentError(err), res
197197
}
198198

199-
// TODO: change return type of state.Prepare()
200-
var prepDevs []kubeletplugin.Device
201-
for _, d := range devs {
202-
device := kubeletplugin.Device{
203-
Requests: d.RequestNames,
204-
PoolName: d.PoolName,
205-
DeviceName: d.DeviceName,
206-
CDIDeviceIDs: d.CDIDeviceIDs,
207-
}
208-
prepDevs = append(prepDevs, device)
209-
}
210-
211-
klog.Infof("Returning newly prepared devices for claim '%v': %v", claim.UID, prepDevs)
212-
return true, kubeletplugin.PrepareResult{Devices: prepDevs}
199+
klog.Infof("Returning newly prepared devices for claim '%v': %v", claim.UID, devs)
200+
return true, kubeletplugin.PrepareResult{Devices: devs}
213201
}
214202

215203
func (d *driver) nodeUnprepareResource(ctx context.Context, claimRef kubeletplugin.NamespacedObject) (bool, error) {

cmd/compute-domain-kubelet-plugin/prepared.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package main
1818

1919
import (
20-
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1beta1"
20+
"k8s.io/dynamic-resource-allocation/kubeletplugin"
2121
)
2222

2323
type PreparedDeviceList []PreparedDevice
@@ -31,12 +31,12 @@ type PreparedDevice struct {
3131

3232
type PreparedComputeDomainChannel struct {
3333
Info *ComputeDomainChannelInfo `json:"info"`
34-
Device *drapbv1.Device `json:"device"`
34+
Device *kubeletplugin.Device `json:"device"`
3535
}
3636

3737
type PreparedComputeDomainDaemon struct {
3838
Info *ComputeDomainDaemonInfo `json:"info"`
39-
Device *drapbv1.Device `json:"device"`
39+
Device *kubeletplugin.Device `json:"device"`
4040
}
4141

4242
type PreparedDeviceGroup struct {
@@ -94,22 +94,22 @@ func (l PreparedDeviceList) ComputeDomainDaemons() PreparedDeviceList {
9494
return devices
9595
}
9696

97-
func (d PreparedDevices) GetDevices() []*drapbv1.Device {
98-
var devices []*drapbv1.Device
97+
func (d PreparedDevices) GetDevices() []kubeletplugin.Device {
98+
var devices []kubeletplugin.Device
9999
for _, group := range d {
100100
devices = append(devices, group.GetDevices()...)
101101
}
102102
return devices
103103
}
104104

105-
func (g *PreparedDeviceGroup) GetDevices() []*drapbv1.Device {
106-
var devices []*drapbv1.Device
105+
func (g *PreparedDeviceGroup) GetDevices() []kubeletplugin.Device {
106+
var devices []kubeletplugin.Device
107107
for _, device := range g.Devices {
108108
switch device.Type() {
109109
case ComputeDomainChannelType:
110-
devices = append(devices, device.Channel.Device)
110+
devices = append(devices, *device.Channel.Device)
111111
case ComputeDomainDaemonType:
112-
devices = append(devices, device.Daemon.Device)
112+
devices = append(devices, *device.Daemon.Device)
113113
}
114114
}
115115
return devices

cmd/gpu-kubelet-plugin/device_state.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424

2525
resourceapi "k8s.io/api/resource/v1beta1"
2626
"k8s.io/apimachinery/pkg/runtime"
27+
"k8s.io/dynamic-resource-allocation/kubeletplugin"
2728
"k8s.io/klog/v2"
28-
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1beta1"
2929
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
3030
cdiapi "tags.cncf.io/container-device-interface/pkg/cdi"
3131

@@ -125,7 +125,7 @@ func NewDeviceState(ctx context.Context, config *Config) (*DeviceState, error) {
125125
return state, nil
126126
}
127127

128-
func (s *DeviceState) Prepare(ctx context.Context, claim *resourceapi.ResourceClaim) ([]*drapbv1.Device, error) {
128+
func (s *DeviceState) Prepare(ctx context.Context, claim *resourceapi.ResourceClaim) ([]kubeletplugin.Device, error) {
129129
s.Lock()
130130
defer s.Unlock()
131131

@@ -301,8 +301,8 @@ func (s *DeviceState) prepareDevices(ctx context.Context, claim *resourceapi.Res
301301
cdiDevices = append(cdiDevices, d)
302302
}
303303

304-
device := &drapbv1.Device{
305-
RequestNames: []string{result.Request},
304+
device := &kubeletplugin.Device{
305+
Requests: []string{result.Request},
306306
PoolName: result.Pool,
307307
DeviceName: result.Device,
308308
CDIDeviceIDs: cdiDevices,

cmd/gpu-kubelet-plugin/driver.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,8 @@ func (d *driver) nodePrepareResource(ctx context.Context, claim *resourceapi.Res
120120
}
121121
}
122122

123-
var prepDevs []kubeletplugin.Device
124-
for _, d := range devs {
125-
device := kubeletplugin.Device{
126-
Requests: d.RequestNames,
127-
PoolName: d.PoolName,
128-
DeviceName: d.DeviceName,
129-
CDIDeviceIDs: d.CDIDeviceIDs,
130-
}
131-
prepDevs = append(prepDevs, device)
132-
}
133-
134-
klog.Infof("Returning newly prepared devices for claim '%v': %v", claim.UID, prepDevs)
135-
return kubeletplugin.PrepareResult{Devices: prepDevs}
123+
klog.Infof("Returning newly prepared devices for claim '%v': %v", claim.UID, devs)
124+
return kubeletplugin.PrepareResult{Devices: devs}
136125
}
137126

138127
func (d *driver) nodeUnprepareResource(ctx context.Context, claimNs kubeletplugin.NamespacedObject) error {

cmd/gpu-kubelet-plugin/prepared.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package main
1919
import (
2020
"slices"
2121

22-
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1beta1"
22+
"k8s.io/dynamic-resource-allocation/kubeletplugin"
2323
)
2424

2525
type PreparedDeviceList []PreparedDevice
@@ -32,13 +32,13 @@ type PreparedDevice struct {
3232
}
3333

3434
type PreparedGpu struct {
35-
Info *GpuInfo `json:"info"`
36-
Device *drapbv1.Device `json:"device"`
35+
Info *GpuInfo `json:"info"`
36+
Device *kubeletplugin.Device `json:"device"`
3737
}
3838

3939
type PreparedMigDevice struct {
40-
Info *MigDeviceInfo `json:"info"`
41-
Device *drapbv1.Device `json:"device"`
40+
Info *MigDeviceInfo `json:"info"`
41+
Device *kubeletplugin.Device `json:"device"`
4242
}
4343

4444
type PreparedDeviceGroup struct {
@@ -96,22 +96,22 @@ func (l PreparedDeviceList) MigDevices() PreparedDeviceList {
9696
return devices
9797
}
9898

99-
func (d PreparedDevices) GetDevices() []*drapbv1.Device {
100-
var devices []*drapbv1.Device
99+
func (d PreparedDevices) GetDevices() []kubeletplugin.Device {
100+
var devices []kubeletplugin.Device
101101
for _, group := range d {
102102
devices = append(devices, group.GetDevices()...)
103103
}
104104
return devices
105105
}
106106

107-
func (g *PreparedDeviceGroup) GetDevices() []*drapbv1.Device {
108-
var devices []*drapbv1.Device
107+
func (g *PreparedDeviceGroup) GetDevices() []kubeletplugin.Device {
108+
var devices []kubeletplugin.Device
109109
for _, device := range g.Devices {
110110
switch device.Type() {
111111
case GpuDeviceType:
112-
devices = append(devices, device.Gpu.Device)
112+
devices = append(devices, *device.Gpu.Device)
113113
case MigDeviceType:
114-
devices = append(devices, device.Mig.Device)
114+
devices = append(devices, *device.Mig.Device)
115115
}
116116
}
117117
return devices

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ require (
2222
k8s.io/component-base v0.33.0
2323
k8s.io/dynamic-resource-allocation v0.33.0
2424
k8s.io/klog/v2 v2.130.1
25-
k8s.io/kubelet v0.33.0
2625
k8s.io/kubernetes v1.33.0
2726
k8s.io/mount-utils v0.33.0
2827
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
@@ -85,6 +84,7 @@ require (
8584
gopkg.in/inf.v0 v0.9.1 // indirect
8685
gopkg.in/yaml.v3 v3.0.1 // indirect
8786
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
87+
k8s.io/kubelet v0.33.0 // indirect
8888
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
8989
sigs.k8s.io/randfill v1.0.0 // indirect
9090
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect

0 commit comments

Comments
 (0)