From b373121a146528913d90137184ebec8f608e65e3 Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Sat, 28 Dec 2019 19:19:59 +0100 Subject: [PATCH] Make CPUManagerCheckpointV2 type an alias of CPUManagerCheckpoint This change is to prevent problems when we remove the V1->V2 migration code in the future. Without this, the checksums of all checkpoints would be hashed with the name CPUManagerCheckpointV2 embedded inside of them, which is undesirable. We want the checkpoints to be hashed with the name CPUManagerCheckpoint instead. --- pkg/kubelet/cm/cpumanager/state/checkpoint.go | 19 ++++++++++--------- .../cpumanager/state/state_checkpoint_test.go | 10 +++++----- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/kubelet/cm/cpumanager/state/checkpoint.go b/pkg/kubelet/cm/cpumanager/state/checkpoint.go index f817de24a7e..e7df594efc5 100644 --- a/pkg/kubelet/cm/cpumanager/state/checkpoint.go +++ b/pkg/kubelet/cm/cpumanager/state/checkpoint.go @@ -28,11 +28,17 @@ import ( "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 { @@ -43,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 { diff --git a/pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go b/pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go index e81eaddd75a..fc96da2931e 100644 --- a/pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go +++ b/pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go @@ -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,7 +147,7 @@ func TestCheckpointStateRestore(t *testing.T) { "container2": "asd" } }, - "checksum": 3082925826 + "checksum": 962272150 }`, "none", containermap.ContainerMap{},