mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
node: cpumgr: address golint
complains
Add docstrings and trivial fixes. Signed-off-by: Francesco Romani <fromani@redhat.com>
This commit is contained in:
parent
ff44dc1932
commit
5e12338a22
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user