Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/dra-example-kubeletplugin/cdi.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ func (cdi *CDIHandler) CreateClaimSpecFile(claimUID string, devices profiles.Pre
},
}
claimEdits.Append(device.ContainerEdits)

deviceId := cdi.getCDIDeviceID(device.DeviceName, device.ShareId)
cdiDevice := cdispec.Device{
Name: fmt.Sprintf("%s-%s", claimUID, device.DeviceName),
Name: fmt.Sprintf("%s-%s", claimUID, deviceId),
ContainerEdits: *claimEdits.ContainerEdits,
}

Expand Down Expand Up @@ -146,3 +146,10 @@ func (cdi *CDIHandler) kind() string {
func (cdi *CDIHandler) vendor() string {
return "k8s." + cdi.driverName
}

func (cdi *CDIHandler) getCDIDeviceID(device string, shareId *string) string {
if shareId != nil {
return fmt.Sprintf("%s-%s", device, *shareId)
}
return device
}
9 changes: 7 additions & 2 deletions cmd/dra-example-kubeletplugin/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
coreclientset "k8s.io/client-go/kubernetes"
"k8s.io/dynamic-resource-allocation/kubeletplugin"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
)

type driver struct {
Expand Down Expand Up @@ -103,12 +104,16 @@ func (d *driver) prepareResourceClaim(_ context.Context, claim *resourceapi.Reso
}
var prepared []kubeletplugin.Device
for _, preparedPB := range preparedPBs {
prepared = append(prepared, kubeletplugin.Device{
device := kubeletplugin.Device{
Requests: preparedPB.GetRequestNames(),
PoolName: preparedPB.GetPoolName(),
DeviceName: preparedPB.GetDeviceName(),
CDIDeviceIDs: preparedPB.GetCdiDeviceIds(),
})
}
if shareIdStr := preparedPB.GetShareId(); shareIdStr != "" {
device.ShareID = ptr.To(types.UID(shareIdStr))
}
prepared = append(prepared, device)
}

klog.Infof("Returning newly prepared devices for claim '%v': %v", claim.UID, prepared)
Expand Down
7 changes: 5 additions & 2 deletions cmd/dra-example-kubeletplugin/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/dynamic-resource-allocation/resourceslice"
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1beta1"
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember choosing not to do this sooner since it changes the format of checkpoints on disk: #123 (comment). I'm not really sure what the implications of that are, especially w.r.t. driver upgrades.

@bart0sh @klueska @pohly How should drivers generally be utilizing checkpoints? Is this the right way to integrate the share_id of a device into the checkpoint?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should use a format that is entirely under their own control, ideally using versioning to enable conversion if the driver needs to change the format.

The kubelet checkpointing code is seriously flawed because it checksums the in-memory representation. See discussion in #90 (comment).

"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"

"sigs.k8s.io/dra-example-driver/internal/profiles"
Expand Down Expand Up @@ -249,12 +249,15 @@ func (s *DeviceState) prepareDevices(claim *resourceapi.ResourceClaim) (profiles
var preparedDevices profiles.PreparedDevices
for _, results := range configResultsMap {
for _, result := range results {
shareId := (*string)(result.ShareID)
deviceId := s.cdi.getCDIDeviceID(result.Device, shareId)
device := &profiles.PreparedDevice{
Device: drapbv1.Device{
RequestNames: []string{result.Request},
PoolName: result.Pool,
DeviceName: result.Device,
CdiDeviceIds: s.cdi.GetClaimDevices(string(claim.UID), []string{result.Device}),
CdiDeviceIds: s.cdi.GetClaimDevices(string(claim.UID), []string{deviceId}),
ShareId: shareId,
},
ContainerEdits: perDeviceCDIContainerEdits[result.Device],
}
Expand Down
16 changes: 15 additions & 1 deletion cmd/dra-example-kubeletplugin/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import (

"sigs.k8s.io/dra-example-driver/internal/profiles"

drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1beta1"
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1"
)

var (
testShareId = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
)

func TestPreparedDevicesGetDevices(t *testing.T) {
Expand All @@ -47,6 +51,16 @@ func TestPreparedDevicesGetDevices(t *testing.T) {
{DeviceName: "dev3"},
},
},
"preparedDevice with shareId": {
preparedDevices: profiles.PreparedDevices{
{Device: drapbv1.Device{DeviceName: "dev1", ShareId: &testShareId}},
{Device: drapbv1.Device{DeviceName: "dev2", ShareId: &testShareId}},
},
expected: []*drapbv1.Device{
{DeviceName: "dev1", ShareId: &testShareId},
{DeviceName: "dev2", ShareId: &testShareId},
},
},
}

for name, test := range tests {
Expand Down
2 changes: 1 addition & 1 deletion internal/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
resourceapi "k8s.io/api/resource/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/dynamic-resource-allocation/resourceslice"
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1beta1"
drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1"
cdiapi "tags.cncf.io/container-device-interface/pkg/cdi"
)

Expand Down
Loading