node: cpumgr: address golint complains

Add docstrings and trivial fixes.

Signed-off-by: Francesco Romani <fromani@redhat.com>
This commit is contained in:
Francesco Romani 2022-10-25 10:24:06 +02:00
parent ff44dc1932
commit 5e12338a22
4 changed files with 11 additions and 2 deletions

View File

@ -27,8 +27,10 @@ import (
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset" "k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
) )
// LoopControl controls the behavior of the cpu accumulator loop logic
type LoopControl int type LoopControl int
// Possible loop control outcomes
const ( const (
Continue LoopControl = iota Continue LoopControl = iota
Break Break

View File

@ -27,6 +27,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
) )
// Names of the options, as part of the user interface.
const ( const (
FullPCPUsOnlyOption string = "full-pcpus-only" FullPCPUsOnlyOption string = "full-pcpus-only"
DistributeCPUsAcrossNUMAOption string = "distribute-cpus-across-numa" DistributeCPUsAcrossNUMAOption string = "distribute-cpus-across-numa"
@ -44,6 +45,8 @@ var (
stableOptions = sets.NewString() stableOptions = sets.NewString()
) )
// CheckPolicyOptionAvailable verifies if the given option can be used depending on the Feature Gate Settings.
// returns nil on success, or an error describing the failure on error.
func CheckPolicyOptionAvailable(option string) error { func CheckPolicyOptionAvailable(option string) error {
if !alphaOptions.Has(option) && !betaOptions.Has(option) && !stableOptions.Has(option) { if !alphaOptions.Has(option) && !betaOptions.Has(option) && !stableOptions.Has(option) {
return fmt.Errorf("unknown CPU Manager Policy option: %q", option) return fmt.Errorf("unknown CPU Manager Policy option: %q", option)
@ -60,6 +63,7 @@ func CheckPolicyOptionAvailable(option string) error {
return nil return nil
} }
// StaticPolicyOptions holds the parsed value of the policy options, ready to be consumed internally.
type StaticPolicyOptions struct { type StaticPolicyOptions struct {
// flag to enable extra allocation restrictions to avoid // flag to enable extra allocation restrictions to avoid
// different containers to possibly end up on the same core. // different containers to possibly end up on the same core.
@ -78,6 +82,7 @@ type StaticPolicyOptions struct {
AlignBySocket bool AlignBySocket bool
} }
// NewStaticPolicyOptions creates a StaticPolicyOptions struct from the user configuration.
func NewStaticPolicyOptions(policyOptions map[string]string) (StaticPolicyOptions, error) { func NewStaticPolicyOptions(policyOptions map[string]string) (StaticPolicyOptions, error) {
opts := StaticPolicyOptions{} opts := StaticPolicyOptions{}
for name, value := range policyOptions { for name, value := range policyOptions {
@ -113,6 +118,7 @@ func NewStaticPolicyOptions(policyOptions map[string]string) (StaticPolicyOption
return opts, nil return opts, nil
} }
// ValidateStaticPolicyOptions ensures that the requested policy options are compatible with the machine on which the CPUManager is running.
func ValidateStaticPolicyOptions(opts StaticPolicyOptions, topology *topology.CPUTopology, topologyManager topologymanager.Store) error { func ValidateStaticPolicyOptions(opts StaticPolicyOptions, topology *topology.CPUTopology, topologyManager topologymanager.Store) error {
if opts.AlignBySocket { if opts.AlignBySocket {
// Not compatible with topology manager single-numa-node policy option. // Not compatible with topology manager single-numa-node policy option.

View File

@ -51,6 +51,7 @@ func (e SMTAlignmentError) Error() string {
return fmt.Sprintf("SMT Alignment Error: requested %d cpus not multiple cpus per core = %d", e.RequestedCPUs, e.CpusPerCore) return fmt.Sprintf("SMT Alignment Error: requested %d cpus not multiple cpus per core = %d", e.RequestedCPUs, e.CpusPerCore)
} }
// Type returns human-readable type of this error. Used in the admission control to populate Admission Failure reason.
func (e SMTAlignmentError) Type() string { func (e SMTAlignmentError) Type() string {
return ErrorSMTAlignment return ErrorSMTAlignment
} }

View File

@ -264,7 +264,7 @@ func TestGetPodTopologyHintsWithPolicyOptions(t *testing.T) {
testPod2 := makePod("fakePod", "fakeContainer", "41", "41") testPod2 := makePod("fakePod", "fakeContainer", "41", "41")
testContainer2 := &testPod1.Spec.Containers[0] testContainer2 := &testPod1.Spec.Containers[0]
cpu_set_across_socket, _ := cpuset.Parse("0-28,40-57") cpuSetAcrossSocket, _ := cpuset.Parse("0-28,40-57")
m0001, _ := bitmask.NewBitMask(0) m0001, _ := bitmask.NewBitMask(0)
m0011, _ := bitmask.NewBitMask(0, 1) m0011, _ := bitmask.NewBitMask(0, 1)
@ -376,7 +376,7 @@ func TestGetPodTopologyHintsWithPolicyOptions(t *testing.T) {
description: "AlignBySocket:true Preferred hints are spread across socket since 2 sockets are required", description: "AlignBySocket:true Preferred hints are spread across socket since 2 sockets are required",
pod: *testPod2, pod: *testPod2,
container: *testContainer2, container: *testContainer2,
defaultCPUSet: cpu_set_across_socket, defaultCPUSet: cpuSetAcrossSocket,
topology: topoDualSocketMultiNumaPerSocketHT, topology: topoDualSocketMultiNumaPerSocketHT,
policyOptions: map[string]string{AlignBySocketOption: "true"}, policyOptions: map[string]string{AlignBySocketOption: "true"},
expectedHints: []topologymanager.TopologyHint{ expectedHints: []topologymanager.TopologyHint{