mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Update pkg/kubelet/status/state/state_checkpoint_test.go
This commit is contained in:
parent
05493c0924
commit
f428881ec0
@ -19,7 +19,8 @@ package state
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"k8s.io/api/core/v1"
|
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum"
|
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum"
|
||||||
)
|
)
|
||||||
|
@ -31,16 +31,7 @@ import (
|
|||||||
const testCheckpoint = "pod_status_manager_state"
|
const testCheckpoint = "pod_status_manager_state"
|
||||||
|
|
||||||
func newTestStateCheckpoint(t *testing.T) *stateCheckpoint {
|
func newTestStateCheckpoint(t *testing.T) *stateCheckpoint {
|
||||||
// create temp dir
|
testingDir := getTestDir(t)
|
||||||
testingDir, err := os.MkdirTemp("", "pod_resource_allocation_state_test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
t.Cleanup(func() {
|
|
||||||
if err := os.RemoveAll(testingDir); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
cache := NewStateMemory()
|
cache := NewStateMemory()
|
||||||
checkpointManager, err := checkpointmanager.NewCheckpointManager(testingDir)
|
checkpointManager, err := checkpointmanager.NewCheckpointManager(testingDir)
|
||||||
require.NoError(t, err, "failed to create checkpoint manager")
|
require.NoError(t, err, "failed to create checkpoint manager")
|
||||||
@ -55,9 +46,7 @@ func newTestStateCheckpoint(t *testing.T) *stateCheckpoint {
|
|||||||
|
|
||||||
func getTestDir(t *testing.T) string {
|
func getTestDir(t *testing.T) string {
|
||||||
testingDir, err := os.MkdirTemp("", "pod_resource_allocation_state_test")
|
testingDir, err := os.MkdirTemp("", "pod_resource_allocation_state_test")
|
||||||
if err != nil {
|
require.NoError(t, err, "failed to create temp dir")
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
if err := os.RemoveAll(testingDir); err != nil {
|
if err := os.RemoveAll(testingDir); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -146,16 +135,6 @@ func Test_stateCheckpoint_formatUpgraded(t *testing.T) {
|
|||||||
// prepare old checkpoint, ResizeStatusEntries is unset,
|
// prepare old checkpoint, ResizeStatusEntries is unset,
|
||||||
// pretend that the old checkpoint is unaware for the field ResizeStatusEntries
|
// pretend that the old checkpoint is unaware for the field ResizeStatusEntries
|
||||||
const checkpointContent = `{"data":"{\"allocationEntries\":{\"pod1\":{\"container1\":{\"requests\":{\"cpu\":\"1Ki\",\"memory\":\"1Ki\"}}}}}","checksum":1555601526}`
|
const checkpointContent = `{"data":"{\"allocationEntries\":{\"pod1\":{\"container1\":{\"requests\":{\"cpu\":\"1Ki\",\"memory\":\"1Ki\"}}}}}","checksum":1555601526}`
|
||||||
checkpoint := &Checkpoint{}
|
|
||||||
err := checkpoint.UnmarshalCheckpoint([]byte(checkpointContent))
|
|
||||||
require.NoError(t, err, "failed to unmarshal checkpoint")
|
|
||||||
|
|
||||||
err = sc.checkpointManager.CreateCheckpoint(sc.checkpointName, checkpoint)
|
|
||||||
require.NoError(t, err, "failed to create old checkpoint")
|
|
||||||
|
|
||||||
err = sc.restoreState()
|
|
||||||
require.NoError(t, err, "failed to restore state")
|
|
||||||
|
|
||||||
expectedPodResourceAllocationInfo := &PodResourceAllocationInfo{
|
expectedPodResourceAllocationInfo := &PodResourceAllocationInfo{
|
||||||
AllocationEntries: map[string]map[string]v1.ResourceRequirements{
|
AllocationEntries: map[string]map[string]v1.ResourceRequirements{
|
||||||
"pod1": {
|
"pod1": {
|
||||||
@ -169,6 +148,16 @@ func Test_stateCheckpoint_formatUpgraded(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ResizeStatusEntries: map[string]v1.PodResizeStatus{},
|
ResizeStatusEntries: map[string]v1.PodResizeStatus{},
|
||||||
}
|
}
|
||||||
|
checkpoint := &Checkpoint{}
|
||||||
|
err := checkpoint.UnmarshalCheckpoint([]byte(checkpointContent))
|
||||||
|
require.NoError(t, err, "failed to unmarshal checkpoint")
|
||||||
|
|
||||||
|
err = sc.checkpointManager.CreateCheckpoint(sc.checkpointName, checkpoint)
|
||||||
|
require.NoError(t, err, "failed to create old checkpoint")
|
||||||
|
|
||||||
|
err = sc.restoreState()
|
||||||
|
require.NoError(t, err, "failed to restore state")
|
||||||
|
|
||||||
actualPodResourceAllocationInfo := &PodResourceAllocationInfo{}
|
actualPodResourceAllocationInfo := &PodResourceAllocationInfo{}
|
||||||
actualPodResourceAllocationInfo.AllocationEntries = sc.cache.GetPodResourceAllocation()
|
actualPodResourceAllocationInfo.AllocationEntries = sc.cache.GetPodResourceAllocation()
|
||||||
actualPodResourceAllocationInfo.ResizeStatusEntries = sc.cache.GetResizeStatus()
|
actualPodResourceAllocationInfo.ResizeStatusEntries = sc.cache.GetResizeStatus()
|
||||||
|
Loading…
Reference in New Issue
Block a user