Skip to content

Commit

Permalink
use CamelCase
Browse files Browse the repository at this point in the history
  • Loading branch information
KunWuLuan committed Mar 25, 2024
1 parent 9da10b5 commit 1c97845
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 131 deletions.
34 changes: 17 additions & 17 deletions apis/extension/numa_aware.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ const (
// ResourceSpec describes extra attributes of the resource requirements.
type ResourceSpec struct {
// NumaTopologyPolicy represents the numa topology policy when schedule pod
NumaTopologyPolicy NUMATopologyPolicy `json:"numaTopologyPolicy,omitempty"`
NumaTopologyPolicy NumaTopologyPolicy `json:"numaTopologyPolicy,omitempty"`
// SingleNUMANodeExclusive represents whether a Pod that will use a single NUMA node/multiple NUMA nodes
// on a NUMA node can be scheduled to use the NUMA node when another Pod that uses multiple NUMA nodes/a single NUMA node
// is already running on the same node.
SingleNUMANodeExclusive NUMATopologyExclusive `json:"singleNUMANodeExclusive,omitempty"`
SingleNUMANodeExclusive NumaTopologyExclusive `json:"singleNUMANodeExclusive,omitempty"`
// RequiredCPUBindPolicy indicates that the CPU is allocated strictly
// according to the specified CPUBindPolicy, otherwise the scheduling fails
RequiredCPUBindPolicy CPUBindPolicy `json:"requiredCPUBindPolicy,omitempty"`
Expand Down Expand Up @@ -141,28 +141,28 @@ const (
NodeNUMAAllocateStrategyMostAllocated = NUMAMostAllocated
)

type NUMATopologyExclusive string
type NumaTopologyExclusive string

const (
NUMATopologyExclusivePreferred NUMATopologyExclusive = "Preferred"
NUMATopologyExclusiveRequired NUMATopologyExclusive = "Required"
NumaTopologyExclusivePreferred NumaTopologyExclusive = "Preferred"
NumaTopologyExclusiveRequired NumaTopologyExclusive = "Required"
)

type NUMANodeStatus string
type NumaNodeStatus string

const (
NUMANodeStatusIdle NUMANodeStatus = "idle"
NUMANodeStatusShared NUMANodeStatus = "shared"
NUMANodeStatusSingle NUMANodeStatus = "single"
NumaNodeStatusIdle NumaNodeStatus = "idle"
NumaNodeStatusShared NumaNodeStatus = "shared"
NumaNodeStatusSingle NumaNodeStatus = "single"
)

type NUMATopologyPolicy string
type NumaTopologyPolicy string

const (
NUMATopologyPolicyNone NUMATopologyPolicy = ""
NUMATopologyPolicyBestEffort NUMATopologyPolicy = "BestEffort"
NUMATopologyPolicyRestricted NUMATopologyPolicy = "Restricted"
NUMATopologyPolicySingleNUMANode NUMATopologyPolicy = "SingleNUMANode"
NumaTopologyPolicyNone NumaTopologyPolicy = ""
NumaTopologyPolicyBestEffort NumaTopologyPolicy = "BestEffort"
NumaTopologyPolicyRestricted NumaTopologyPolicy = "Restricted"
NumaTopologyPolicySingleNUMANode NumaTopologyPolicy = "SingleNUMANode"
)

const (
Expand Down Expand Up @@ -345,11 +345,11 @@ func GetNodeCPUBindPolicy(nodeLabels map[string]string, kubeletCPUPolicy *Kubele
return NodeCPUBindPolicyNone
}

func GetNodeNUMATopologyPolicy(labels map[string]string) NUMATopologyPolicy {
return NUMATopologyPolicy(labels[LabelNUMATopologyPolicy])
func GetNodeNUMATopologyPolicy(labels map[string]string) NumaTopologyPolicy {
return NumaTopologyPolicy(labels[LabelNUMATopologyPolicy])
}

func SetNodeNUMATopologyPolicy(obj metav1.Object, policy NUMATopologyPolicy) {
func SetNodeNUMATopologyPolicy(obj metav1.Object, policy NumaTopologyPolicy) {
labels := obj.GetLabels()
if labels == nil {
labels = map[string]string{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/frameworkext/framework_extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (ext *frameworkExtenderImpl) ForgetPod(pod *corev1.Pod) error {
return nil
}

func (ext *frameworkExtenderImpl) RunNUMATopologyManagerAdmit(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string, numaNodes []int, policyType apiext.NUMATopologyPolicy, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) *framework.Status {
func (ext *frameworkExtenderImpl) RunNUMATopologyManagerAdmit(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string, numaNodes []int, policyType apiext.NumaTopologyPolicy, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) *framework.Status {
return ext.topologyManager.Admit(ctx, cycleState, pod, nodeName, numaNodes, policyType, exclusivePolicy, allNUMANodeStatus)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/frameworkext/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type FrameworkExtender interface {
RunReservationFilterPlugins(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, reservationInfo *ReservationInfo, nodeName string) *framework.Status
RunReservationScorePlugins(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, reservationInfos []*ReservationInfo, nodeName string) (PluginToReservationScores, *framework.Status)

RunNUMATopologyManagerAdmit(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string, numaNodes []int, policyType apiext.NUMATopologyPolicy, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) *framework.Status
RunNUMATopologyManagerAdmit(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string, numaNodes []int, policyType apiext.NumaTopologyPolicy, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) *framework.Status

RunResizePod(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string) *framework.Status
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/scheduler/frameworkext/topologymanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

type Interface interface {
Admit(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string, numaNodes []int, policyType apiext.NUMATopologyPolicy, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) *framework.Status
Admit(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string, numaNodes []int, policyType apiext.NumaTopologyPolicy, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) *framework.Status
}

type NUMATopologyHintProvider interface {
Expand Down Expand Up @@ -55,7 +55,7 @@ func New(hintProviderFactory NUMATopologyHintProviderFactory) Interface {
}
}

func (m *topologyManager) Admit(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string, numaNodes []int, policyType apiext.NUMATopologyPolicy, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) *framework.Status {
func (m *topologyManager) Admit(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string, numaNodes []int, policyType apiext.NumaTopologyPolicy, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) *framework.Status {
s, err := cycleState.Read(affinityStateKey)
if err != nil {
return framework.AsStatus(err)
Expand All @@ -79,7 +79,7 @@ func (m *topologyManager) Admit(ctx context.Context, cycleState *framework.Cycle
return nil
}

func (m *topologyManager) calculateAffinity(ctx context.Context, cycleState *framework.CycleState, policy Policy, pod *corev1.Pod, nodeName string, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) (NUMATopologyHint, bool) {
func (m *topologyManager) calculateAffinity(ctx context.Context, cycleState *framework.CycleState, policy Policy, pod *corev1.Pod, nodeName string, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) (NUMATopologyHint, bool) {
providersHints := m.accumulateProvidersHints(ctx, cycleState, pod, nodeName)
bestHint, admit := policy.Merge(providersHints, exclusivePolicy, allNUMANodeStatus)
if !checkExclusivePolicy(bestHint, exclusivePolicy, allNUMANodeStatus) {
Expand Down Expand Up @@ -114,14 +114,14 @@ func (m *topologyManager) allocateResources(ctx context.Context, cycleState *fra
return nil
}

func createNUMATopologyPolicy(policyType apiext.NUMATopologyPolicy, numaNodes []int) Policy {
func createNUMATopologyPolicy(policyType apiext.NumaTopologyPolicy, numaNodes []int) Policy {
var p Policy
switch policyType {
case apiext.NUMATopologyPolicyBestEffort:
case apiext.NumaTopologyPolicyBestEffort:
p = NewBestEffortPolicy(numaNodes)
case apiext.NUMATopologyPolicyRestricted:
case apiext.NumaTopologyPolicyRestricted:
p = NewRestrictedPolicy(numaNodes)
case apiext.NUMATopologyPolicySingleNUMANode:
case apiext.NumaTopologyPolicySingleNUMANode:
p = NewSingleNumaNodePolicy(numaNodes)
}
return p
Expand Down
12 changes: 6 additions & 6 deletions pkg/scheduler/frameworkext/topologymanager/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Policy interface {
// Name returns Policy Name
Name() string
// Merge returns a merged NUMATopologyHint based on input from hint providers
Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) (NUMATopologyHint, bool)
Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) (NUMATopologyHint, bool)
}

// NUMATopologyHint is a struct containing the NUMANodeAffinity for a Container
Expand Down Expand Up @@ -64,18 +64,18 @@ func (th *NUMATopologyHint) LessThan(other NUMATopologyHint) bool {
}

// Check if the affinity match the exclusive policy, return true if match or false otherwise.
func checkExclusivePolicy(affinity NUMATopologyHint, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) bool {
func checkExclusivePolicy(affinity NUMATopologyHint, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) bool {
// check bestHint again if default hint is the best
if exclusivePolicy == apiext.NUMATopologyExclusiveRequired {
if exclusivePolicy == apiext.NumaTopologyExclusiveRequired {
if affinity.NUMANodeAffinity.Count() > 1 {
// we should make sure no numa is in single state
for _, nodeid := range affinity.NUMANodeAffinity.GetBits() {
if allNUMANodeStatus[nodeid] == apiext.NUMANodeStatusSingle {
if allNUMANodeStatus[nodeid] == apiext.NumaNodeStatusSingle {
return false
}
}
} else {
if allNUMANodeStatus[affinity.NUMANodeAffinity.GetBits()[0]] == apiext.NUMANodeStatusShared {
if allNUMANodeStatus[affinity.NUMANodeAffinity.GetBits()[0]] == apiext.NumaNodeStatusShared {
return false
}
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func filterProvidersHints(providersHints []map[string][]NUMATopologyHint) [][]NU
return allProviderHints
}

func mergeFilteredHints(numaNodes []int, filteredHints [][]NUMATopologyHint, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) NUMATopologyHint {
func mergeFilteredHints(numaNodes []int, filteredHints [][]NUMATopologyHint, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) NUMATopologyHint {
// Set the default affinity as an any-numa affinity containing the list
// of NUMA Nodes available on this machine.
defaultAffinity, _ := bitmask.NewBitMask(numaNodes...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (p *bestEffortPolicy) canAdmitPodResult(hint *NUMATopologyHint) bool {
return true
}

func (p *bestEffortPolicy) Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) (NUMATopologyHint, bool) {
func (p *bestEffortPolicy) Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) (NUMATopologyHint, bool) {
filteredProvidersHints := filterProvidersHints(providersHints)
bestHint := mergeFilteredHints(p.numaNodes, filteredProvidersHints, exclusivePolicy, allNUMANodeStatus)
admit := p.canAdmitPodResult(&bestHint)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/frameworkext/topologymanager/policy_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func (p *nonePolicy) canAdmitPodResult(hint *NUMATopologyHint) bool {
return true
}

func (p *nonePolicy) Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) (NUMATopologyHint, bool) {
func (p *nonePolicy) Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) (NUMATopologyHint, bool) {
return NUMATopologyHint{}, p.canAdmitPodResult(nil)
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestPolicyNoneMerge(t *testing.T) {

for _, tc := range tcases {
policy := NewNonePolicy()
result, admit := policy.Merge(tc.providersHints, apiext.NUMATopologyExclusivePreferred, []apiext.NUMANodeStatus{})
result, admit := policy.Merge(tc.providersHints, apiext.NumaTopologyExclusivePreferred, []apiext.NumaNodeStatus{})
if !result.IsEqual(tc.expectedHint) || admit != tc.expectedAdmit {
t.Errorf("Test Case: %s: Expected merge hint to be %v, got %v", tc.name, tc.expectedHint, result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (p *restrictedPolicy) canAdmitPodResult(hint *NUMATopologyHint) bool {
return hint.Preferred
}

func (p *restrictedPolicy) Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) (NUMATopologyHint, bool) {
func (p *restrictedPolicy) Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) (NUMATopologyHint, bool) {
filteredHints := filterProvidersHints(providersHints)
hint := mergeFilteredHints(p.numaNodes, filteredHints, exclusivePolicy, allNUMANodeStatus)
admit := p.canAdmitPodResult(&hint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func filterSingleNumaHints(allResourcesHints [][]NUMATopologyHint) [][]NUMATopol
return filteredResourcesHints
}

func (p *singleNumaNodePolicy) Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NUMATopologyExclusive, allNUMANodeStatus []apiext.NUMANodeStatus) (NUMATopologyHint, bool) {
func (p *singleNumaNodePolicy) Merge(providersHints []map[string][]NUMATopologyHint, exclusivePolicy apiext.NumaTopologyExclusive, allNUMANodeStatus []apiext.NumaNodeStatus) (NUMATopologyHint, bool) {
filteredHints := filterProvidersHints(providersHints)
// Filter to only include don't care and hints with a single NUMA node.
singleNumaHints := filterSingleNumaHints(filteredHints)
Expand Down
Loading

0 comments on commit 1c97845

Please sign in to comment.