From 5e12338a22b471d22edf4fa8e40ec64d84cb825e Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 25 Oct 2022 10:24:06 +0200 Subject: [PATCH] node: cpumgr: address `golint` complains Add docstrings and trivial fixes. Signed-off-by: Francesco Romani --- pkg/kubelet/cm/cpumanager/cpu_assignment.go | 2 ++ pkg/kubelet/cm/cpumanager/policy_options.go | 6 ++++++ pkg/kubelet/cm/cpumanager/policy_static.go | 1 + pkg/kubelet/cm/cpumanager/topology_hints_test.go | 4 ++-- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/kubelet/cm/cpumanager/cpu_assignment.go b/pkg/kubelet/cm/cpumanager/cpu_assignment.go index 7628769d5df..e8d02ca4ab8 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_assignment.go +++ b/pkg/kubelet/cm/cpumanager/cpu_assignment.go @@ -27,8 +27,10 @@ import ( "k8s.io/kubernetes/pkg/kubelet/cm/cpuset" ) +// LoopControl controls the behavior of the cpu accumulator loop logic type LoopControl int +// Possible loop control outcomes const ( Continue LoopControl = iota Break diff --git a/pkg/kubelet/cm/cpumanager/policy_options.go b/pkg/kubelet/cm/cpumanager/policy_options.go index d04b60420e1..2e275254c33 100644 --- a/pkg/kubelet/cm/cpumanager/policy_options.go +++ b/pkg/kubelet/cm/cpumanager/policy_options.go @@ -27,6 +27,7 @@ import ( "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" ) +// Names of the options, as part of the user interface. const ( FullPCPUsOnlyOption string = "full-pcpus-only" DistributeCPUsAcrossNUMAOption string = "distribute-cpus-across-numa" @@ -44,6 +45,8 @@ var ( 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 { if !alphaOptions.Has(option) && !betaOptions.Has(option) && !stableOptions.Has(option) { return fmt.Errorf("unknown CPU Manager Policy option: %q", option) @@ -60,6 +63,7 @@ func CheckPolicyOptionAvailable(option string) error { return nil } +// StaticPolicyOptions holds the parsed value of the policy options, ready to be consumed internally. type StaticPolicyOptions struct { // flag to enable extra allocation restrictions to avoid // different containers to possibly end up on the same core. @@ -78,6 +82,7 @@ type StaticPolicyOptions struct { AlignBySocket bool } +// NewStaticPolicyOptions creates a StaticPolicyOptions struct from the user configuration. func NewStaticPolicyOptions(policyOptions map[string]string) (StaticPolicyOptions, error) { opts := StaticPolicyOptions{} for name, value := range policyOptions { @@ -113,6 +118,7 @@ func NewStaticPolicyOptions(policyOptions map[string]string) (StaticPolicyOption 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 { if opts.AlignBySocket { // Not compatible with topology manager single-numa-node policy option. diff --git a/pkg/kubelet/cm/cpumanager/policy_static.go b/pkg/kubelet/cm/cpumanager/policy_static.go index bb82c53406e..4d7f7c0b0de 100644 --- a/pkg/kubelet/cm/cpumanager/policy_static.go +++ b/pkg/kubelet/cm/cpumanager/policy_static.go @@ -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) } +// Type returns human-readable type of this error. Used in the admission control to populate Admission Failure reason. func (e SMTAlignmentError) Type() string { return ErrorSMTAlignment } diff --git a/pkg/kubelet/cm/cpumanager/topology_hints_test.go b/pkg/kubelet/cm/cpumanager/topology_hints_test.go index 02d064e71e3..5b6951cb2d7 100644 --- a/pkg/kubelet/cm/cpumanager/topology_hints_test.go +++ b/pkg/kubelet/cm/cpumanager/topology_hints_test.go @@ -264,7 +264,7 @@ func TestGetPodTopologyHintsWithPolicyOptions(t *testing.T) { testPod2 := makePod("fakePod", "fakeContainer", "41", "41") 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) 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", pod: *testPod2, container: *testContainer2, - defaultCPUSet: cpu_set_across_socket, + defaultCPUSet: cpuSetAcrossSocket, topology: topoDualSocketMultiNumaPerSocketHT, policyOptions: map[string]string{AlignBySocketOption: "true"}, expectedHints: []topologymanager.TopologyHint{