mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 07:39:22 +00:00
Rebase and backward compatibility
This commit is contained in:
parent
ba8d82c96a
commit
7bb047ec75
@ -13,10 +13,9 @@ go_library(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/kubelet/checkpointmanager:go_default_library",
|
"//pkg/kubelet/checkpointmanager:go_default_library",
|
||||||
|
"//pkg/kubelet/checkpointmanager/checksum:go_default_library",
|
||||||
"//pkg/kubelet/checkpointmanager/errors:go_default_library",
|
"//pkg/kubelet/checkpointmanager/errors:go_default_library",
|
||||||
"//pkg/kubelet/cm/cpuset:go_default_library",
|
"//pkg/kubelet/cm/cpuset:go_default_library",
|
||||||
"//pkg/kubelet/util/store:go_default_library",
|
|
||||||
"//pkg/util/hash:go_default_library",
|
|
||||||
"//vendor/github.com/golang/glog:go_default_library",
|
"//vendor/github.com/golang/glog:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -18,55 +18,50 @@ package state
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"hash/fnv"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors"
|
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum"
|
||||||
hashutil "k8s.io/kubernetes/pkg/util/hash"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ checkpointmanager.Checkpoint = &CPUManagerCheckpoint{}
|
var _ checkpointmanager.Checkpoint = &CPUManagerCheckpoint{}
|
||||||
|
|
||||||
// CPUManagerCheckpoint struct is used to store cpu/pod assignments in a checkpoint
|
// CPUManagerCheckpoint struct is used to store cpu/pod assignments in a checkpoint
|
||||||
type CPUManagerCheckpoint struct {
|
type CPUManagerCheckpoint struct {
|
||||||
PolicyName string
|
PolicyName string `json:"policyName"`
|
||||||
DefaultCPUSet string
|
DefaultCPUSet string `json:"defaultCpuSet"`
|
||||||
Entries map[string]string
|
Entries map[string]string `json:"entries,omitempty"`
|
||||||
Checksum uint64
|
Checksum checksum.Checksum `json:"checksum"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCPUManagerCheckpoint returns an instance of Checkpoint
|
// NewCPUManagerCheckpoint returns an instance of Checkpoint
|
||||||
func NewCPUManagerCheckpoint() *CPUManagerCheckpoint {
|
func NewCPUManagerCheckpoint() *CPUManagerCheckpoint {
|
||||||
return &CPUManagerCheckpoint{Entries: make(map[string]string)}
|
return &CPUManagerCheckpoint{
|
||||||
|
Entries: make(map[string]string),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalCheckpoint returns marshalled checkpoint
|
// MarshalCheckpoint returns marshalled checkpoint
|
||||||
func (cp *CPUManagerCheckpoint) MarshalCheckpoint() ([]byte, error) {
|
func (cp *CPUManagerCheckpoint) MarshalCheckpoint() ([]byte, error) {
|
||||||
|
// make sure checksum wasn't set before so it doesn't affect output checksum
|
||||||
|
cp.Checksum = 0
|
||||||
|
cp.Checksum = checksum.New(cp)
|
||||||
return json.Marshal(*cp)
|
return json.Marshal(*cp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalCheckpoint tries to unmarshal passed bytes to checkpoint
|
// UnmarshalCheckpoint tries to unmarshal passed bytes to checkpoint
|
||||||
func (cp *CPUManagerCheckpoint) UnmarshalCheckpoint(blob []byte) error {
|
func (cp *CPUManagerCheckpoint) UnmarshalCheckpoint(blob []byte) error {
|
||||||
if err := json.Unmarshal(blob, cp); err != nil {
|
return json.Unmarshal(blob, cp)
|
||||||
return err
|
|
||||||
}
|
|
||||||
if cp.Checksum != cp.GetChecksum() {
|
|
||||||
return errors.ErrCorruptCheckpoint
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChecksum returns calculated checksum of checkpoint
|
// VerifyChecksum verifies that current checksum of checkpoint is valid
|
||||||
func (cp *CPUManagerCheckpoint) GetChecksum() uint64 {
|
func (cp *CPUManagerCheckpoint) VerifyChecksum() error {
|
||||||
orig := cp.Checksum
|
if cp.Checksum == 0 {
|
||||||
|
// accept empty checksum for compatibility with old file backend
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
ck := cp.Checksum
|
||||||
cp.Checksum = 0
|
cp.Checksum = 0
|
||||||
hash := fnv.New32a()
|
err := ck.Verify(cp)
|
||||||
hashutil.DeepHashObject(hash, *cp)
|
cp.Checksum = ck
|
||||||
cp.Checksum = orig
|
return err
|
||||||
return uint64(hash.Sum32())
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateChecksum calculates and updates checksum of the checkpoint
|
|
||||||
func (cp *CPUManagerCheckpoint) UpdateChecksum() {
|
|
||||||
cp.Checksum = cp.GetChecksum()
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors"
|
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
|
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
|
||||||
utilstore "k8s.io/kubernetes/pkg/kubelet/util/store"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// cpuManagerCheckpointName is the name of checkpoint file
|
// cpuManagerCheckpointName is the name of checkpoint file
|
||||||
|
@ -48,7 +48,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
|||||||
"PolicyName": "none",
|
"PolicyName": "none",
|
||||||
"DefaultCPUSet": "4-6",
|
"DefaultCPUSet": "4-6",
|
||||||
"Entries": {},
|
"Entries": {},
|
||||||
"Checksum": 861251554
|
"Checksum": 2912033808
|
||||||
}`,
|
}`,
|
||||||
"none",
|
"none",
|
||||||
"",
|
"",
|
||||||
@ -65,7 +65,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
|||||||
"container1": "4-6",
|
"container1": "4-6",
|
||||||
"container2": "1-3"
|
"container2": "1-3"
|
||||||
},
|
},
|
||||||
"Checksum": 2604807655
|
"Checksum": 1535905563
|
||||||
}`,
|
}`,
|
||||||
"none",
|
"none",
|
||||||
"",
|
"",
|
||||||
@ -102,7 +102,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
|||||||
"PolicyName": "other",
|
"PolicyName": "other",
|
||||||
"DefaultCPUSet": "1-3",
|
"DefaultCPUSet": "1-3",
|
||||||
"Entries": {},
|
"Entries": {},
|
||||||
"Checksum": 4266067046
|
"Checksum": 4195836012
|
||||||
}`,
|
}`,
|
||||||
"none",
|
"none",
|
||||||
`configured policy "none" differs from state checkpoint policy "other"`,
|
`configured policy "none" differs from state checkpoint policy "other"`,
|
||||||
@ -114,7 +114,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
|||||||
"PolicyName": "none",
|
"PolicyName": "none",
|
||||||
"DefaultCPUSet": "1.3",
|
"DefaultCPUSet": "1.3",
|
||||||
"Entries": {},
|
"Entries": {},
|
||||||
"Checksum": 4073769779
|
"Checksum": 1025273327
|
||||||
}`,
|
}`,
|
||||||
"none",
|
"none",
|
||||||
`could not parse default cpu set "1.3": strconv.Atoi: parsing "1.3": invalid syntax`,
|
`could not parse default cpu set "1.3": strconv.Atoi: parsing "1.3": invalid syntax`,
|
||||||
@ -129,7 +129,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
|||||||
"container1": "4-6",
|
"container1": "4-6",
|
||||||
"container2": "asd"
|
"container2": "asd"
|
||||||
},
|
},
|
||||||
"Checksum": 3835486974
|
"Checksum": 2764213924
|
||||||
}`,
|
}`,
|
||||||
"none",
|
"none",
|
||||||
`could not parse cpuset "asd" for container id "container2": strconv.Atoi: parsing "asd": invalid syntax`,
|
`could not parse cpuset "asd" for container id "container2": strconv.Atoi: parsing "asd": invalid syntax`,
|
||||||
|
@ -35,10 +35,7 @@ func (mc *MockCheckpoint) UnmarshalCheckpoint(blob []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChecksum fakes getting checksum
|
// VerifyChecksum fakes verifying checksum
|
||||||
func (mc *MockCheckpoint) GetChecksum() uint64 {
|
func (mc *MockCheckpoint) VerifyChecksum() error {
|
||||||
return 0
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateChecksum fakes updating cheksum
|
|
||||||
func (mc *MockCheckpoint) UpdateChecksum() {}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user