mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
memory manager: remove unused variable under stateCheckpoint
This commit is contained in:
parent
ff2a110920
commit
d0089db2ec
@ -97,7 +97,7 @@ type manager struct {
|
||||
containerRuntime runtimeService
|
||||
|
||||
// activePods is a method for listing active pods on the node
|
||||
// so all the containers can be updated in the reconciliation loop.
|
||||
// so all the containers can be updated during call to the removeStaleState.
|
||||
activePods ActivePodsFunc
|
||||
|
||||
// podStatusProvider provides a method for obtaining pod statuses
|
||||
@ -159,7 +159,7 @@ func (m *manager) Start(activePods ActivePodsFunc, sourcesReady config.SourcesRe
|
||||
m.containerRuntime = containerRuntime
|
||||
m.containerMap = initialContainers
|
||||
|
||||
stateImpl, err := state.NewCheckpointState(m.stateFileDirectory, memoryManagerStateFileName, m.policy.Name(), m.containerMap)
|
||||
stateImpl, err := state.NewCheckpointState(m.stateFileDirectory, memoryManagerStateFileName, m.policy.Name())
|
||||
if err != nil {
|
||||
klog.Errorf("[memorymanager] could not initialize checkpoint manager: %v, please drain node and remove policy state file", err)
|
||||
return err
|
||||
|
@ -14,7 +14,6 @@ go_library(
|
||||
"//pkg/kubelet/checkpointmanager:go_default_library",
|
||||
"//pkg/kubelet/checkpointmanager/checksum:go_default_library",
|
||||
"//pkg/kubelet/checkpointmanager/errors:go_default_library",
|
||||
"//pkg/kubelet/cm/containermap:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/klog/v2:go_default_library",
|
||||
],
|
||||
@ -26,7 +25,6 @@ go_test(
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/kubelet/checkpointmanager:go_default_library",
|
||||
"//pkg/kubelet/cm/containermap:go_default_library",
|
||||
"//pkg/kubelet/cm/cpumanager/state/testing:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm/containermap"
|
||||
)
|
||||
|
||||
var _ State = &stateCheckpoint{}
|
||||
@ -35,11 +34,10 @@ type stateCheckpoint struct {
|
||||
policyName string
|
||||
checkpointManager checkpointmanager.CheckpointManager
|
||||
checkpointName string
|
||||
initialContainers containermap.ContainerMap
|
||||
}
|
||||
|
||||
// NewCheckpointState creates new State for keeping track of memory/pod assignment with checkpoint backend
|
||||
func NewCheckpointState(stateDir, checkpointName, policyName string, initialContainers containermap.ContainerMap) (State, error) {
|
||||
func NewCheckpointState(stateDir, checkpointName, policyName string) (State, error) {
|
||||
checkpointManager, err := checkpointmanager.NewCheckpointManager(stateDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize checkpoint manager: %v", err)
|
||||
@ -49,7 +47,6 @@ func NewCheckpointState(stateDir, checkpointName, policyName string, initialCont
|
||||
policyName: policyName,
|
||||
checkpointManager: checkpointManager,
|
||||
checkpointName: checkpointName,
|
||||
initialContainers: initialContainers,
|
||||
}
|
||||
|
||||
if err := stateCheckpoint.restoreState(); err != nil {
|
||||
|
@ -26,7 +26,6 @@ import (
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm/containermap"
|
||||
testutil "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state/testing"
|
||||
)
|
||||
|
||||
@ -47,14 +46,12 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
checkpointContent string
|
||||
initialContainers containermap.ContainerMap
|
||||
expectedError string
|
||||
expectedState *stateMemory
|
||||
}{
|
||||
{
|
||||
"Restore non-existing checkpoint",
|
||||
"",
|
||||
containermap.ContainerMap{},
|
||||
"",
|
||||
&stateMemory{},
|
||||
},
|
||||
@ -66,7 +63,6 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
"entries":{"pod":{"container1":[{"numaAffinity":[0],"type":"memory","size":512}]}},
|
||||
"checksum": 4215593881
|
||||
}`,
|
||||
containermap.ContainerMap{},
|
||||
"",
|
||||
&stateMemory{
|
||||
assignments: ContainerMemoryAssignments{
|
||||
@ -103,14 +99,12 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
"entries":{"pod":{"container1":[{"affinity":[0],"type":"memory","size":512}]}},
|
||||
"checksum": 101010
|
||||
}`,
|
||||
containermap.ContainerMap{},
|
||||
"checkpoint is corrupted",
|
||||
&stateMemory{},
|
||||
},
|
||||
{
|
||||
"Restore checkpoint with invalid JSON",
|
||||
`{`,
|
||||
containermap.ContainerMap{},
|
||||
"unexpected end of JSON input",
|
||||
&stateMemory{},
|
||||
},
|
||||
@ -138,7 +132,7 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
assert.NoError(t, cpm.CreateCheckpoint(testingCheckpoint, checkpoint), "could not create testing checkpoint")
|
||||
}
|
||||
|
||||
restoredState, err := NewCheckpointState(testingDir, testingCheckpoint, "static", tc.initialContainers)
|
||||
restoredState, err := NewCheckpointState(testingDir, testingCheckpoint, "static")
|
||||
if strings.TrimSpace(tc.expectedError) != "" {
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "could not restore state from checkpoint: "+tc.expectedError)
|
||||
@ -191,7 +185,7 @@ func TestCheckpointStateStore(t *testing.T) {
|
||||
|
||||
assert.NoError(t, cpm.RemoveCheckpoint(testingCheckpoint), "could not remove testing checkpoint")
|
||||
|
||||
cs1, err := NewCheckpointState(testingDir, testingCheckpoint, "static", nil)
|
||||
cs1, err := NewCheckpointState(testingDir, testingCheckpoint, "static")
|
||||
assert.NoError(t, err, "could not create testing checkpointState instance")
|
||||
|
||||
// set values of cs1 instance so they are stored in checkpoint and can be read by cs2
|
||||
@ -199,7 +193,7 @@ func TestCheckpointStateStore(t *testing.T) {
|
||||
cs1.SetMemoryAssignments(expectedState.assignments)
|
||||
|
||||
// restore checkpoint with previously stored values
|
||||
cs2, err := NewCheckpointState(testingDir, testingCheckpoint, "static", nil)
|
||||
cs2, err := NewCheckpointState(testingDir, testingCheckpoint, "static")
|
||||
assert.NoError(t, err, "could not create testing checkpointState instance")
|
||||
|
||||
assertStateEqual(t, cs2, expectedState)
|
||||
@ -313,7 +307,7 @@ func TestCheckpointStateHelpers(t *testing.T) {
|
||||
// ensure there is no previous checkpoint
|
||||
assert.NoError(t, cpm.RemoveCheckpoint(testingCheckpoint), "could not remove testing checkpoint")
|
||||
|
||||
state, err := NewCheckpointState(testingDir, testingCheckpoint, "static", nil)
|
||||
state, err := NewCheckpointState(testingDir, testingCheckpoint, "static")
|
||||
assert.NoError(t, err, "could not create testing checkpoint manager")
|
||||
|
||||
state.SetMachineState(tc.machineState)
|
||||
@ -376,7 +370,7 @@ func TestCheckpointStateClear(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
state, err := NewCheckpointState(testingDir, testingCheckpoint, "static", nil)
|
||||
state, err := NewCheckpointState(testingDir, testingCheckpoint, "static")
|
||||
assert.NoError(t, err, "could not create testing checkpoint manager")
|
||||
|
||||
state.SetMachineState(tc.machineState)
|
||||
|
Loading…
Reference in New Issue
Block a user