Update the cpumanager to error out if an invalid policy is given

Previously, the cpumanager would simply fall back to the None() policy
if an invalid policy was specified. This patch updates this to return an
error when an invalid policy is passed, forcing the kubelet to fail
fast when this occurs.

These semantics should be preferable because an invalid policy likely
indicates operator error in setting the policy flag on the kubelet
correctly (e.g. misspelling 'static' as 'statiic'). In this case it is
better to fail fast so the operator can detect this and correct the
mistake, than to mask the error and essentially disable the cpumanager
unexpectedly.
This commit is contained in:
Kevin Klues 2019-07-18 13:12:30 +02:00
parent ce80aeaac5
commit 5dc5f1de06
2 changed files with 2 additions and 3 deletions

View File

@ -132,8 +132,7 @@ func NewManager(cpuPolicyName string, reconcilePeriod time.Duration, machineInfo
policy = NewStaticPolicy(topo, numReservedCPUs)
default:
klog.Errorf("[cpumanager] Unknown policy \"%s\", falling back to default policy \"%s\"", cpuPolicyName, PolicyNone)
policy = NewNonePolicy()
return nil, fmt.Errorf("unknown policy: \"%s\"", cpuPolicyName)
}
stateImpl, err := state.NewCheckpointState(stateFileDirectory, cpuManagerStateFileName, policy.Name())

View File

@ -232,7 +232,7 @@ func TestCPUManagerGenerate(t *testing.T) {
description: "invalid policy name",
cpuPolicyName: "invalid",
nodeAllocatableReservation: nil,
expectedPolicy: "none",
expectedError: fmt.Errorf("unknown policy: \"invalid\""),
},
{
description: "static policy",