Skip to content

Commit f428881

Browse files
committed
Update pkg/kubelet/status/state/state_checkpoint_test.go
1 parent 05493c0 commit f428881

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

pkg/kubelet/status/state/checkpoint.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ package state
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"k8s.io/api/core/v1"
22+
23+
v1 "k8s.io/api/core/v1"
2324
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
2425
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum"
2526
)

pkg/kubelet/status/state/state_checkpoint_test.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,7 @@ import (
3131
const testCheckpoint = "pod_status_manager_state"
3232

3333
func newTestStateCheckpoint(t *testing.T) *stateCheckpoint {
34-
// create temp dir
35-
testingDir, err := os.MkdirTemp("", "pod_resource_allocation_state_test")
36-
if err != nil {
37-
t.Fatal(err)
38-
}
39-
t.Cleanup(func() {
40-
if err := os.RemoveAll(testingDir); err != nil {
41-
t.Fatal(err)
42-
}
43-
})
34+
testingDir := getTestDir(t)
4435
cache := NewStateMemory()
4536
checkpointManager, err := checkpointmanager.NewCheckpointManager(testingDir)
4637
require.NoError(t, err, "failed to create checkpoint manager")
@@ -55,9 +46,7 @@ func newTestStateCheckpoint(t *testing.T) *stateCheckpoint {
5546

5647
func getTestDir(t *testing.T) string {
5748
testingDir, err := os.MkdirTemp("", "pod_resource_allocation_state_test")
58-
if err != nil {
59-
t.Fatal(err)
60-
}
49+
require.NoError(t, err, "failed to create temp dir")
6150
t.Cleanup(func() {
6251
if err := os.RemoveAll(testingDir); err != nil {
6352
t.Fatal(err)
@@ -146,16 +135,6 @@ func Test_stateCheckpoint_formatUpgraded(t *testing.T) {
146135
// prepare old checkpoint, ResizeStatusEntries is unset,
147136
// pretend that the old checkpoint is unaware for the field ResizeStatusEntries
148137
const checkpointContent = `{"data":"{\"allocationEntries\":{\"pod1\":{\"container1\":{\"requests\":{\"cpu\":\"1Ki\",\"memory\":\"1Ki\"}}}}}","checksum":1555601526}`
149-
checkpoint := &Checkpoint{}
150-
err := checkpoint.UnmarshalCheckpoint([]byte(checkpointContent))
151-
require.NoError(t, err, "failed to unmarshal checkpoint")
152-
153-
err = sc.checkpointManager.CreateCheckpoint(sc.checkpointName, checkpoint)
154-
require.NoError(t, err, "failed to create old checkpoint")
155-
156-
err = sc.restoreState()
157-
require.NoError(t, err, "failed to restore state")
158-
159138
expectedPodResourceAllocationInfo := &PodResourceAllocationInfo{
160139
AllocationEntries: map[string]map[string]v1.ResourceRequirements{
161140
"pod1": {
@@ -169,6 +148,16 @@ func Test_stateCheckpoint_formatUpgraded(t *testing.T) {
169148
},
170149
ResizeStatusEntries: map[string]v1.PodResizeStatus{},
171150
}
151+
checkpoint := &Checkpoint{}
152+
err := checkpoint.UnmarshalCheckpoint([]byte(checkpointContent))
153+
require.NoError(t, err, "failed to unmarshal checkpoint")
154+
155+
err = sc.checkpointManager.CreateCheckpoint(sc.checkpointName, checkpoint)
156+
require.NoError(t, err, "failed to create old checkpoint")
157+
158+
err = sc.restoreState()
159+
require.NoError(t, err, "failed to restore state")
160+
172161
actualPodResourceAllocationInfo := &PodResourceAllocationInfo{}
173162
actualPodResourceAllocationInfo.AllocationEntries = sc.cache.GetPodResourceAllocation()
174163
actualPodResourceAllocationInfo.ResizeStatusEntries = sc.cache.GetResizeStatus()

0 commit comments

Comments
 (0)