mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Merge pull request #86689 from klueska/upstream-fix-cpumanager-v1-state-checksum
Lock checksum calculation for v1 CPUManager state to pre 1.18 logic
This commit is contained in:
commit
fd0358fd21
@ -17,6 +17,7 @@ go_library(
|
||||
"//pkg/kubelet/checkpointmanager/errors:go_default_library",
|
||||
"//pkg/kubelet/cm/cpumanager/containermap:go_default_library",
|
||||
"//pkg/kubelet/cm/cpuset:go_default_library",
|
||||
"//vendor/github.com/davecgh/go-spew/spew:go_default_library",
|
||||
"//vendor/k8s.io/klog:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -18,16 +18,27 @@ package state
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"hash/fnv"
|
||||
"strings"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum"
|
||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors"
|
||||
)
|
||||
|
||||
// CPUManagerCheckpoint struct is used to store cpu/pod assignments in a checkpoint
|
||||
type CPUManagerCheckpoint = CPUManagerCheckpointV2
|
||||
|
||||
var _ checkpointmanager.Checkpoint = &CPUManagerCheckpointV1{}
|
||||
var _ checkpointmanager.Checkpoint = &CPUManagerCheckpointV2{}
|
||||
var _ checkpointmanager.Checkpoint = &CPUManagerCheckpoint{}
|
||||
|
||||
// CPUManagerCheckpoint struct is used to store cpu/pod assignments in a checkpoint in v2 format
|
||||
type CPUManagerCheckpoint struct {
|
||||
PolicyName string `json:"policyName"`
|
||||
DefaultCPUSet string `json:"defaultCpuSet"`
|
||||
Entries map[string]map[string]string `json:"entries,omitempty"`
|
||||
Checksum checksum.Checksum `json:"checksum"`
|
||||
}
|
||||
|
||||
// CPUManagerCheckpointV1 struct is used to store cpu/pod assignments in a checkpoint in v1 format
|
||||
type CPUManagerCheckpointV1 struct {
|
||||
@ -38,12 +49,7 @@ type CPUManagerCheckpointV1 struct {
|
||||
}
|
||||
|
||||
// CPUManagerCheckpointV2 struct is used to store cpu/pod assignments in a checkpoint in v2 format
|
||||
type CPUManagerCheckpointV2 struct {
|
||||
PolicyName string `json:"policyName"`
|
||||
DefaultCPUSet string `json:"defaultCpuSet"`
|
||||
Entries map[string]map[string]string `json:"entries,omitempty"`
|
||||
Checksum checksum.Checksum `json:"checksum"`
|
||||
}
|
||||
type CPUManagerCheckpointV2 = CPUManagerCheckpoint
|
||||
|
||||
// NewCPUManagerCheckpoint returns an instance of Checkpoint
|
||||
func NewCPUManagerCheckpoint() *CPUManagerCheckpoint {
|
||||
@ -95,11 +101,27 @@ func (cp *CPUManagerCheckpointV1) VerifyChecksum() error {
|
||||
// accept empty checksum for compatibility with old file backend
|
||||
return nil
|
||||
}
|
||||
|
||||
printer := spew.ConfigState{
|
||||
Indent: " ",
|
||||
SortKeys: true,
|
||||
DisableMethods: true,
|
||||
SpewKeys: true,
|
||||
}
|
||||
|
||||
ck := cp.Checksum
|
||||
cp.Checksum = 0
|
||||
err := ck.Verify(cp)
|
||||
object := printer.Sprintf("%#v", cp)
|
||||
object = strings.Replace(object, "CPUManagerCheckpointV1", "CPUManagerCheckpoint", 1)
|
||||
cp.Checksum = ck
|
||||
return err
|
||||
|
||||
hash := fnv.New32a()
|
||||
printer.Fprintf(hash, "%v", object)
|
||||
if cp.Checksum != checksum.Checksum(hash.Sum32()) {
|
||||
return errors.ErrCorruptCheckpoint
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// VerifyChecksum verifies that current checksum of checkpoint is valid in v2 format
|
||||
|
@ -54,7 +54,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
"policyName": "none",
|
||||
"defaultCPUSet": "4-6",
|
||||
"entries": {},
|
||||
"checksum": 2655485041
|
||||
"checksum": 354655845
|
||||
}`,
|
||||
"none",
|
||||
containermap.ContainerMap{},
|
||||
@ -74,7 +74,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
"container2": "1-3"
|
||||
}
|
||||
},
|
||||
"checksum": 3415933391
|
||||
"checksum": 3610638499
|
||||
}`,
|
||||
"none",
|
||||
containermap.ContainerMap{},
|
||||
@ -116,7 +116,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
"policyName": "other",
|
||||
"defaultCPUSet": "1-3",
|
||||
"entries": {},
|
||||
"checksum": 698611581
|
||||
"checksum": 1394507217
|
||||
}`,
|
||||
"none",
|
||||
containermap.ContainerMap{},
|
||||
@ -129,7 +129,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
"policyName": "none",
|
||||
"defaultCPUSet": "1.3",
|
||||
"entries": {},
|
||||
"checksum": 1966990140
|
||||
"checksum": 3021697696
|
||||
}`,
|
||||
"none",
|
||||
containermap.ContainerMap{},
|
||||
@ -147,13 +147,27 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
"container2": "asd"
|
||||
}
|
||||
},
|
||||
"checksum": 3082925826
|
||||
"checksum": 962272150
|
||||
}`,
|
||||
"none",
|
||||
containermap.ContainerMap{},
|
||||
`could not parse cpuset "asd" for container "container2" in pod "pod": strconv.Atoi: parsing "asd": invalid syntax`,
|
||||
&stateMemory{},
|
||||
},
|
||||
{
|
||||
"Restore checkpoint from checkpoint with v1 checksum",
|
||||
`{
|
||||
"policyName": "none",
|
||||
"defaultCPUSet": "1-3",
|
||||
"checksum": 1694838852
|
||||
}`,
|
||||
"none",
|
||||
containermap.ContainerMap{},
|
||||
"",
|
||||
&stateMemory{
|
||||
defaultCPUSet: cpuset.NewCPUSet(1, 2, 3),
|
||||
},
|
||||
},
|
||||
{
|
||||
"Restore checkpoint with migration",
|
||||
`{
|
||||
@ -163,7 +177,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
"containerID1": "4-6",
|
||||
"containerID2": "1-3"
|
||||
},
|
||||
"checksum": 2832947348
|
||||
"checksum": 3680390589
|
||||
}`,
|
||||
"none",
|
||||
func() containermap.ContainerMap {
|
||||
|
Loading…
Reference in New Issue
Block a user