Skip to content

Commit 6bdb873

Browse files
committed
DRA: refactor checkpointing
1 parent 68ad8b2 commit 6bdb873

12 files changed

+389
-253
lines changed

pkg/kubelet/checkpointmanager/checkpoint_manager.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ func (manager *impl) GetCheckpoint(checkpointKey string, checkpoint Checkpoint)
8585
return err
8686
}
8787
err = checkpoint.UnmarshalCheckpoint(blob)
88-
if err == nil {
89-
err = checkpoint.VerifyChecksum()
90-
}
9188
return err
9289
}
9390

pkg/kubelet/cm/dra/claiminfo.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ import (
2626
"k8s.io/apimachinery/pkg/types"
2727
"k8s.io/apimachinery/pkg/util/sets"
2828
"k8s.io/kubernetes/pkg/kubelet/cm/dra/state"
29+
"k8s.io/kubernetes/pkg/kubelet/cm/dra/state/checkpoint/v1alpha1"
2930
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
3031
)
3132

3233
// ClaimInfo holds information required
3334
// to prepare and unprepare a resource claim.
3435
// +k8s:deepcopy-gen=true
3536
type ClaimInfo struct {
36-
state.ClaimInfoState
37+
v1alpha1.ClaimInfoState
3738
prepared bool
3839
}
3940

@@ -47,18 +48,18 @@ type claimInfoCache struct {
4748
// newClaimInfoFromClaim creates a new claim info from a resource claim.
4849
// It verifies that the kubelet can handle the claim.
4950
func newClaimInfoFromClaim(claim *resourceapi.ResourceClaim) (*ClaimInfo, error) {
50-
claimInfoState := state.ClaimInfoState{
51+
claimInfoState := v1alpha1.ClaimInfoState{
5152
ClaimUID: claim.UID,
5253
ClaimName: claim.Name,
5354
Namespace: claim.Namespace,
5455
PodUIDs: sets.New[string](),
55-
DriverState: make(map[string]state.DriverState),
56+
DriverState: make(map[string]v1alpha1.DriverState),
5657
}
5758
if claim.Status.Allocation == nil {
5859
return nil, errors.New("not allocated")
5960
}
6061
for _, result := range claim.Status.Allocation.Devices.Results {
61-
claimInfoState.DriverState[result.Driver] = state.DriverState{}
62+
claimInfoState.DriverState[result.Driver] = v1alpha1.DriverState{}
6263
}
6364
info := &ClaimInfo{
6465
ClaimInfoState: claimInfoState,
@@ -68,7 +69,7 @@ func newClaimInfoFromClaim(claim *resourceapi.ResourceClaim) (*ClaimInfo, error)
6869
}
6970

7071
// newClaimInfoFromClaim creates a new claim info from a checkpointed claim info state object.
71-
func newClaimInfoFromState(state *state.ClaimInfoState) *ClaimInfo {
72+
func newClaimInfoFromState(state *v1alpha1.ClaimInfoState) *ClaimInfo {
7273
info := &ClaimInfo{
7374
ClaimInfoState: *state.DeepCopy(),
7475
prepared: false,
@@ -77,9 +78,9 @@ func newClaimInfoFromState(state *state.ClaimInfoState) *ClaimInfo {
7778
}
7879

7980
// setCDIDevices adds a set of CDI devices to the claim info.
80-
func (info *ClaimInfo) addDevice(driverName string, device state.Device) {
81+
func (info *ClaimInfo) addDevice(driverName string, device v1alpha1.Device) {
8182
if info.DriverState == nil {
82-
info.DriverState = make(map[string]state.DriverState)
83+
info.DriverState = make(map[string]v1alpha1.DriverState)
8384
}
8485
driverState := info.DriverState[driverName]
8586
driverState.Devices = append(driverState.Devices, device)

pkg/kubelet/cm/dra/claiminfo_test.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
"k8s.io/apimachinery/pkg/types"
3030
"k8s.io/apimachinery/pkg/util/sets"
31-
"k8s.io/kubernetes/pkg/kubelet/cm/dra/state"
31+
"k8s.io/kubernetes/pkg/kubelet/cm/dra/state/checkpoint/v1alpha1"
3232
)
3333

3434
// ClaimInfo test cases
@@ -48,13 +48,13 @@ const (
4848
)
4949

5050
var (
51-
device = state.Device{
51+
device = v1alpha1.Device{
5252
PoolName: poolName,
5353
DeviceName: deviceName,
5454
RequestNames: []string{requestName},
5555
CDIDeviceIDs: []string{cdiID},
5656
}
57-
devices = []state.Device{device}
57+
devices = []v1alpha1.Device{device}
5858
)
5959

6060
func TestNewClaimInfoFromClaim(t *testing.T) {
@@ -97,12 +97,12 @@ func TestNewClaimInfoFromClaim(t *testing.T) {
9797
},
9898
},
9999
expectedResult: &ClaimInfo{
100-
ClaimInfoState: state.ClaimInfoState{
100+
ClaimInfoState: v1alpha1.ClaimInfoState{
101101
ClaimUID: claimUID,
102102
ClaimName: claimName,
103103
Namespace: namespace,
104104
PodUIDs: sets.New[string](),
105-
DriverState: map[string]state.DriverState{
105+
DriverState: map[string]v1alpha1.DriverState{
106106
driverName: {},
107107
},
108108
},
@@ -123,12 +123,12 @@ func TestNewClaimInfoFromClaim(t *testing.T) {
123123
Spec: resourceapi.ResourceClaimSpec{},
124124
},
125125
expectedResult: &ClaimInfo{
126-
ClaimInfoState: state.ClaimInfoState{
126+
ClaimInfoState: v1alpha1.ClaimInfoState{
127127
ClaimUID: claimUID,
128128
ClaimName: claimName,
129129
Namespace: namespace,
130130
PodUIDs: sets.New[string](),
131-
DriverState: map[string]state.DriverState{},
131+
DriverState: map[string]v1alpha1.DriverState{},
132132
},
133133
prepared: false,
134134
},
@@ -149,29 +149,29 @@ func TestNewClaimInfoFromClaim(t *testing.T) {
149149
func TestNewClaimInfoFromState(t *testing.T) {
150150
for _, test := range []struct {
151151
description string
152-
state *state.ClaimInfoState
152+
state *v1alpha1.ClaimInfoState
153153
expectedResult *ClaimInfo
154154
}{
155155
{
156156
description: "successfully created object",
157-
state: &state.ClaimInfoState{
157+
state: &v1alpha1.ClaimInfoState{
158158
ClaimUID: claimUID,
159159
ClaimName: claimName,
160160
Namespace: namespace,
161161
PodUIDs: sets.New[string](podUID),
162-
DriverState: map[string]state.DriverState{
162+
DriverState: map[string]v1alpha1.DriverState{
163163
driverName: {
164164
Devices: devices,
165165
},
166166
},
167167
},
168168
expectedResult: &ClaimInfo{
169-
ClaimInfoState: state.ClaimInfoState{
169+
ClaimInfoState: v1alpha1.ClaimInfoState{
170170
ClaimUID: claimUID,
171171
ClaimName: claimName,
172172
Namespace: namespace,
173173
PodUIDs: sets.New[string](podUID),
174-
DriverState: map[string]state.DriverState{
174+
DriverState: map[string]v1alpha1.DriverState{
175175
driverName: {
176176
Devices: devices,
177177
},
@@ -194,12 +194,12 @@ func TestClaimInfoAddDevice(t *testing.T) {
194194
for _, test := range []struct {
195195
description string
196196
claimInfo *ClaimInfo
197-
device state.Device
197+
device v1alpha1.Device
198198
}{
199199
{
200200
description: "add new device",
201201
claimInfo: &ClaimInfo{
202-
ClaimInfoState: state.ClaimInfoState{
202+
ClaimInfoState: v1alpha1.ClaimInfoState{
203203
ClaimUID: claimUID,
204204
ClaimName: claimName,
205205
Namespace: namespace,
@@ -212,14 +212,14 @@ func TestClaimInfoAddDevice(t *testing.T) {
212212
{
213213
description: "other new device",
214214
claimInfo: &ClaimInfo{
215-
ClaimInfoState: state.ClaimInfoState{
215+
ClaimInfoState: v1alpha1.ClaimInfoState{
216216
ClaimUID: claimUID,
217217
ClaimName: claimName,
218218
Namespace: namespace,
219219
PodUIDs: sets.New[string](podUID),
220220
},
221221
},
222-
device: func() state.Device {
222+
device: func() v1alpha1.Device {
223223
device := device
224224
device.PoolName += "-2"
225225
device.DeviceName += "-2"
@@ -231,7 +231,7 @@ func TestClaimInfoAddDevice(t *testing.T) {
231231
} {
232232
t.Run(test.description, func(t *testing.T) {
233233
test.claimInfo.addDevice(driverName, test.device)
234-
assert.Equal(t, []state.Device{test.device}, test.claimInfo.DriverState[driverName].Devices)
234+
assert.Equal(t, []v1alpha1.Device{test.device}, test.claimInfo.DriverState[driverName].Devices)
235235
})
236236
}
237237
}
@@ -245,7 +245,7 @@ func TestClaimInfoAddPodReference(t *testing.T) {
245245
{
246246
description: "empty PodUIDs list",
247247
claimInfo: &ClaimInfo{
248-
ClaimInfoState: state.ClaimInfoState{
248+
ClaimInfoState: v1alpha1.ClaimInfoState{
249249
PodUIDs: sets.New[string](),
250250
},
251251
},
@@ -254,7 +254,7 @@ func TestClaimInfoAddPodReference(t *testing.T) {
254254
{
255255
description: "first pod reference",
256256
claimInfo: &ClaimInfo{
257-
ClaimInfoState: state.ClaimInfoState{
257+
ClaimInfoState: v1alpha1.ClaimInfoState{
258258
PodUIDs: sets.New[string](podUID),
259259
},
260260
},
@@ -263,7 +263,7 @@ func TestClaimInfoAddPodReference(t *testing.T) {
263263
{
264264
description: "second pod reference",
265265
claimInfo: &ClaimInfo{
266-
ClaimInfoState: state.ClaimInfoState{
266+
ClaimInfoState: v1alpha1.ClaimInfoState{
267267
PodUIDs: sets.New[string]("pod-uid1"),
268268
},
269269
},
@@ -287,15 +287,15 @@ func TestClaimInfoHasPodReference(t *testing.T) {
287287
{
288288
description: "claim doesn't reference pod",
289289
claimInfo: &ClaimInfo{
290-
ClaimInfoState: state.ClaimInfoState{
290+
ClaimInfoState: v1alpha1.ClaimInfoState{
291291
PodUIDs: sets.New[string](),
292292
},
293293
},
294294
},
295295
{
296296
description: "claim references pod",
297297
claimInfo: &ClaimInfo{
298-
ClaimInfoState: state.ClaimInfoState{
298+
ClaimInfoState: v1alpha1.ClaimInfoState{
299299
PodUIDs: sets.New[string](podUID),
300300
},
301301
},
@@ -320,15 +320,15 @@ func TestClaimInfoDeletePodReference(t *testing.T) {
320320
{
321321
description: "claim doesn't reference pod",
322322
claimInfo: &ClaimInfo{
323-
ClaimInfoState: state.ClaimInfoState{
323+
ClaimInfoState: v1alpha1.ClaimInfoState{
324324
PodUIDs: sets.New[string](),
325325
},
326326
},
327327
},
328328
{
329329
description: "claim references pod",
330330
claimInfo: &ClaimInfo{
331-
ClaimInfoState: state.ClaimInfoState{
331+
ClaimInfoState: v1alpha1.ClaimInfoState{
332332
PodUIDs: sets.New[string](podUID),
333333
},
334334
},
@@ -574,7 +574,7 @@ func TestClaimInfoCacheAdd(t *testing.T) {
574574
{
575575
description: "claimInfo successfully added",
576576
claimInfo: &ClaimInfo{
577-
ClaimInfoState: state.ClaimInfoState{
577+
ClaimInfoState: v1alpha1.ClaimInfoState{
578578
ClaimName: claimName,
579579
Namespace: namespace,
580580
},
@@ -603,15 +603,15 @@ func TestClaimInfoCacheContains(t *testing.T) {
603603
claimInfoCache: &claimInfoCache{
604604
claimInfo: map[string]*ClaimInfo{
605605
namespace + "/" + claimName: {
606-
ClaimInfoState: state.ClaimInfoState{
606+
ClaimInfoState: v1alpha1.ClaimInfoState{
607607
ClaimName: claimName,
608608
Namespace: namespace,
609609
},
610610
},
611611
},
612612
},
613613
claimInfo: &ClaimInfo{
614-
ClaimInfoState: state.ClaimInfoState{
614+
ClaimInfoState: v1alpha1.ClaimInfoState{
615615
ClaimName: claimName,
616616
Namespace: namespace,
617617
},
@@ -622,7 +622,7 @@ func TestClaimInfoCacheContains(t *testing.T) {
622622
description: "cache miss",
623623
claimInfoCache: &claimInfoCache{},
624624
claimInfo: &ClaimInfo{
625-
ClaimInfoState: state.ClaimInfoState{
625+
ClaimInfoState: v1alpha1.ClaimInfoState{
626626
ClaimName: claimName,
627627
Namespace: namespace,
628628
},
@@ -632,7 +632,7 @@ func TestClaimInfoCacheContains(t *testing.T) {
632632
description: "cache miss: empty cache and empty claim info",
633633
claimInfoCache: &claimInfoCache{},
634634
claimInfo: &ClaimInfo{
635-
ClaimInfoState: state.ClaimInfoState{},
635+
ClaimInfoState: v1alpha1.ClaimInfoState{},
636636
},
637637
},
638638
} {
@@ -654,7 +654,7 @@ func TestClaimInfoCacheGet(t *testing.T) {
654654
claimInfoCache: &claimInfoCache{
655655
claimInfo: map[string]*ClaimInfo{
656656
namespace + "/" + claimName: {
657-
ClaimInfoState: state.ClaimInfoState{
657+
ClaimInfoState: v1alpha1.ClaimInfoState{
658658
ClaimName: claimName,
659659
Namespace: namespace,
660660
},
@@ -687,7 +687,7 @@ func TestClaimInfoCacheDelete(t *testing.T) {
687687
claimInfoCache: &claimInfoCache{
688688
claimInfo: map[string]*ClaimInfo{
689689
claimName + namespace: {
690-
ClaimInfoState: state.ClaimInfoState{
690+
ClaimInfoState: v1alpha1.ClaimInfoState{
691691
ClaimName: claimName,
692692
Namespace: namespace,
693693
},
@@ -718,7 +718,7 @@ func TestClaimInfoCacheHasPodReference(t *testing.T) {
718718
claimInfoCache: &claimInfoCache{
719719
claimInfo: map[string]*ClaimInfo{
720720
claimName + namespace: {
721-
ClaimInfoState: state.ClaimInfoState{
721+
ClaimInfoState: v1alpha1.ClaimInfoState{
722722
ClaimName: claimName,
723723
Namespace: namespace,
724724
PodUIDs: sets.New[string](podUID),

pkg/kubelet/cm/dra/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"k8s.io/klog/v2"
3333
drapb "k8s.io/kubelet/pkg/apis/dra/v1alpha4"
3434
dra "k8s.io/kubernetes/pkg/kubelet/cm/dra/plugin"
35-
"k8s.io/kubernetes/pkg/kubelet/cm/dra/state"
35+
"k8s.io/kubernetes/pkg/kubelet/cm/dra/state/checkpoint/v1alpha1"
3636
"k8s.io/kubernetes/pkg/kubelet/config"
3737
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
3838
)
@@ -273,7 +273,7 @@ func (m *ManagerImpl) PrepareResources(pod *v1.Pod) error {
273273
return fmt.Errorf("unable to get claim info for claim %s in namespace %s", claim.Name, claim.Namespace)
274274
}
275275
for _, device := range result.GetDevices() {
276-
info.addDevice(driverName, state.Device{PoolName: device.PoolName, DeviceName: device.DeviceName, RequestNames: device.RequestNames, CDIDeviceIDs: device.CDIDeviceIDs})
276+
info.addDevice(driverName, v1alpha1.Device{PoolName: device.PoolName, DeviceName: device.DeviceName, RequestNames: device.RequestNames, CDIDeviceIDs: device.CDIDeviceIDs})
277277
}
278278
return nil
279279
})

0 commit comments

Comments
 (0)