mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-16 23:29:21 +00:00
Tweaks
This commit is contained in:
parent
3991ed5d2f
commit
0fbd19bc06
@ -33,7 +33,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/status"
|
||||
"path"
|
||||
)
|
||||
|
||||
// ActivePodsFunc is a function that returns a list of pods to reconcile.
|
||||
|
@ -27,8 +27,8 @@ import (
|
||||
utilstore "k8s.io/kubernetes/pkg/kubelet/util/store"
|
||||
)
|
||||
|
||||
// CPUManagerCheckpointName is the name of checkpoint file
|
||||
const CPUManagerCheckpointName = "cpu_manager_state"
|
||||
// cpuManagerCheckpointName is the name of checkpoint file
|
||||
const cpuManagerCheckpointName = "cpu_manager_state"
|
||||
|
||||
var _ State = &stateCheckpoint{}
|
||||
|
||||
@ -54,7 +54,7 @@ func NewCheckpointState(stateDir string, policyName string) (State, error) {
|
||||
if err := stateCheckpoint.restoreState(); err != nil {
|
||||
return nil, fmt.Errorf("could not restore state from checkpoint: %v\n"+
|
||||
"Please drain this node and delete the CPU manager checkpoint file %q before restarting Kubelet.",
|
||||
err, path.Join(stateDir, CPUManagerCheckpointName))
|
||||
err, path.Join(stateDir, cpuManagerCheckpointName))
|
||||
}
|
||||
|
||||
return stateCheckpoint, nil
|
||||
@ -72,7 +72,7 @@ func (sc *stateCheckpoint) restoreState() error {
|
||||
tmpContainerCPUSet := cpuset.NewCPUSet()
|
||||
|
||||
checkpoint := NewCPUManagerCheckpoint()
|
||||
if err = sc.checkpointManager.GetCheckpoint(CPUManagerCheckpointName, checkpoint); err != nil {
|
||||
if err = sc.checkpointManager.GetCheckpoint(cpuManagerCheckpointName, checkpoint); err != nil {
|
||||
// TODO: change to errors.ErrCheckpointNotFound may be required after issue in checkpointing PR is resolved
|
||||
if err == utilstore.ErrKeyNotFound {
|
||||
sc.storeState()
|
||||
@ -115,7 +115,7 @@ func (sc *stateCheckpoint) storeState() {
|
||||
checkpoint.Entries[containerID] = cset.String()
|
||||
}
|
||||
|
||||
err := sc.checkpointManager.CreateCheckpoint(CPUManagerCheckpointName, checkpoint)
|
||||
err := sc.checkpointManager.CreateCheckpoint(cpuManagerCheckpointName, checkpoint)
|
||||
|
||||
if err != nil {
|
||||
panic("[cpumanager] could not save checkpoint: " + err.Error())
|
||||
|
@ -146,15 +146,12 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
// ensure there is no previous checkpoint
|
||||
cpm.RemoveCheckpoint(CPUManagerCheckpointName)
|
||||
cpm.RemoveCheckpoint(cpuManagerCheckpointName)
|
||||
|
||||
// prepare checkpoint for testing
|
||||
var checkpoint *testutil.MockCheckpoint = nil
|
||||
if strings.TrimSpace(tc.checkpointContent) != "" {
|
||||
checkpoint = &testutil.MockCheckpoint{Content: tc.checkpointContent}
|
||||
}
|
||||
if checkpoint != nil {
|
||||
if err := cpm.CreateCheckpoint(CPUManagerCheckpointName, checkpoint); err != nil {
|
||||
checkpoint := &testutil.MockCheckpoint{Content: tc.checkpointContent}
|
||||
if err := cpm.CreateCheckpoint(cpuManagerCheckpointName, checkpoint); err != nil {
|
||||
t.Fatalf("could not create testing checkpoint: %v", err)
|
||||
}
|
||||
}
|
||||
@ -204,16 +201,18 @@ func TestCheckpointStateStore(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
// ensure there is no previous checkpoint
|
||||
cpm.RemoveCheckpoint(CPUManagerCheckpointName)
|
||||
cpm.RemoveCheckpoint(cpuManagerCheckpointName)
|
||||
|
||||
cs1, err := NewCheckpointState(testingDir, "none")
|
||||
if err != nil {
|
||||
t.Fatalf("could not create testing checkpointState instance: %v", err)
|
||||
}
|
||||
|
||||
// set values of cs1 instance so they are stored in checkpoint and can be read by cs2
|
||||
cs1.SetDefaultCPUSet(tc.expectedState.defaultCPUSet)
|
||||
cs1.SetCPUAssignments(tc.expectedState.assignments)
|
||||
|
||||
// restore checkpoint with previously stored values
|
||||
cs2, err := NewCheckpointState(testingDir, "none")
|
||||
if err != nil {
|
||||
t.Fatalf("could not create testing checkpointState instance: %v", err)
|
||||
@ -262,7 +261,7 @@ func TestCheckpointStateHelpers(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
// ensure there is no previous checkpoint
|
||||
cpm.RemoveCheckpoint(CPUManagerCheckpointName)
|
||||
cpm.RemoveCheckpoint(cpuManagerCheckpointName)
|
||||
|
||||
state, err := NewCheckpointState(testingDir, "none")
|
||||
if err != nil {
|
||||
@ -277,11 +276,10 @@ func TestCheckpointStateHelpers(t *testing.T) {
|
||||
}
|
||||
|
||||
state.Delete(container)
|
||||
if cpus := state.GetCPUSetOrDefault(container); !cpus.Equals(tc.defaultCPUset) {
|
||||
if _, ok := state.GetCPUSet(container); ok {
|
||||
t.Fatal("deleted container still existing in state")
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -316,7 +314,7 @@ func TestCheckpointStateClear(t *testing.T) {
|
||||
t.Fatal("cleared state with non-empty default cpu set")
|
||||
}
|
||||
for container := range tc.containers {
|
||||
if !cpuset.NewCPUSet().Equals(state.GetCPUSetOrDefault(container)) {
|
||||
if _, ok := state.GetCPUSet(container); ok {
|
||||
t.Fatalf("container %q with non-default cpu set in cleared state", container)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user