diff --git a/cmd/katalyst-agent/app/options/qrm/cpu_plugin.go b/cmd/katalyst-agent/app/options/qrm/cpu_plugin.go index d9f45d226..f07503cff 100644 --- a/cmd/katalyst-agent/app/options/qrm/cpu_plugin.go +++ b/cmd/katalyst-agent/app/options/qrm/cpu_plugin.go @@ -19,8 +19,8 @@ package qrm import ( cliflag "k8s.io/component-base/cli/flag" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" qrmconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/qrm" ) @@ -60,10 +60,10 @@ func NewCPUOptions() *CPUOptions { EnableCPUIdle: false, CPUNUMAHintPreferPolicy: cpuconsts.CPUNUMAHintPreferPolicySpreading, LoadPressureEvictionSkipPools: []string{ - state.PoolNameReclaim, - state.PoolNameDedicated, - state.PoolNameFallback, - state.PoolNameReserve, + commonstate.PoolNameReclaim, + commonstate.PoolNameDedicated, + commonstate.PoolNameFallback, + commonstate.PoolNameReserve, }, }, CPUNativePolicyOptions: CPUNativePolicyOptions{ diff --git a/cmd/katalyst-agent/app/options/sysadvisor/qosaware/resource/memory/plugins/numa_balancer.go b/cmd/katalyst-agent/app/options/sysadvisor/qosaware/resource/memory/plugins/numa_balancer.go index 6dcfb04fb..5c630cf6d 100644 --- a/cmd/katalyst-agent/app/options/sysadvisor/qosaware/resource/memory/plugins/numa_balancer.go +++ b/cmd/katalyst-agent/app/options/sysadvisor/qosaware/resource/memory/plugins/numa_balancer.go @@ -20,7 +20,7 @@ import ( "github.com/spf13/pflag" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/util" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/qosaware/resource/memory/plugins" "github.com/kubewharf/katalyst-core/pkg/consts" ) @@ -80,7 +80,7 @@ func NewNumaBalancerOptions() *NumaBalancerOptions { BalancedReclaimedPodsSingleRoundTotalRSSThreshold: 3 * 1024 * 1024 * 1024, - SupportedPools: []string{state.PoolNameShare}, + SupportedPools: []string{commonstate.PoolNameShare}, } } diff --git a/pkg/agent/qrm-plugins/commonstate/pool.go b/pkg/agent/qrm-plugins/commonstate/pool.go new file mode 100644 index 000000000..f3a838339 --- /dev/null +++ b/pkg/agent/qrm-plugins/commonstate/pool.go @@ -0,0 +1,90 @@ +/* +Copyright 2022 The Katalyst Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package commonstate + +import ( + "strings" + + apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" +) + +// notice that pool-name may not have direct mapping relations with qos-level, for instance +// - both isolated_shared_cores and dedicated_cores fall into PoolNameDedicated +const ( + PoolNameShare = "share" + PoolNameReclaim = "reclaim" + PoolNameDedicated = "dedicated" + PoolNameReserve = "reserve" + PoolNamePrefixIsolation = "isolation" + PoolNamePrefixSystem = "system" + + EmptyOwnerPoolName = "" + + // PoolNameFallback is not a real pool, and is a union of + // all none-reclaimed pools to put pod should have been isolated + PoolNameFallback = "fallback" +) + +// FakedContainerName represents a placeholder since pool entry has no container-level +// FakedNUMAID represents a placeholder since pools like shared/reclaimed will not contain a specific numa +const ( + FakedContainerName = "" + FakedNUMAID = -1 + NameSeparator = "#" + NUMAPoolInfix = "-NUMA" +) + +func IsIsolationPool(poolName string) bool { + return strings.HasPrefix(poolName, PoolNamePrefixIsolation) +} + +func IsSystemPool(poolName string) bool { + return strings.HasPrefix(poolName, PoolNamePrefixSystem) +} + +func GetPoolType(poolName string) string { + if IsIsolationPool(poolName) { + return PoolNamePrefixIsolation + } else if IsSystemPool(poolName) { + return PoolNamePrefixSystem + } + switch poolName { + case PoolNameReclaim, PoolNameDedicated, PoolNameReserve, PoolNameFallback: + return poolName + default: + return PoolNameShare + } +} + +// GetSpecifiedPoolName todo: this function (along with pool-name consts) should be moved to generic qos conf +func GetSpecifiedPoolName(qosLevel, cpusetEnhancementValue string) string { + switch qosLevel { + case apiconsts.PodAnnotationQoSLevelSharedCores: + if cpusetEnhancementValue != EmptyOwnerPoolName { + return cpusetEnhancementValue + } + return PoolNameShare + case apiconsts.PodAnnotationQoSLevelSystemCores: + return cpusetEnhancementValue + case apiconsts.PodAnnotationQoSLevelReclaimedCores: + return PoolNameReclaim + case apiconsts.PodAnnotationQoSLevelDedicatedCores: + return PoolNameDedicated + default: + return EmptyOwnerPoolName + } +} diff --git a/pkg/agent/qrm-plugins/commonstate/state.go b/pkg/agent/qrm-plugins/commonstate/state.go new file mode 100644 index 000000000..763b64ba8 --- /dev/null +++ b/pkg/agent/qrm-plugins/commonstate/state.go @@ -0,0 +1,232 @@ +/* +Copyright 2022 The Katalyst Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package commonstate + +import ( + "fmt" + + pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" + + "github.com/kubewharf/katalyst-api/pkg/consts" + cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" + "github.com/kubewharf/katalyst-core/pkg/util/general" + "github.com/kubewharf/katalyst-core/pkg/util/machine" +) + +type AllocationMeta struct { + PodUid string `json:"pod_uid,omitempty"` + PodNamespace string `json:"pod_namespace,omitempty"` + PodName string `json:"pod_name,omitempty"` + ContainerName string `json:"container_name,omitempty"` + ContainerType string `json:"container_type,omitempty"` + ContainerIndex uint64 `json:"container_index,omitempty"` + OwnerPoolName string `json:"owner_pool_name,omitempty"` + PodRole string `json:"pod_role,omitempty"` + PodType string `json:"pod_type,omitempty"` + + Labels map[string]string `json:"labels"` + Annotations map[string]string `json:"annotations"` + QoSLevel string `json:"qosLevel"` +} + +func (am *AllocationMeta) Clone() *AllocationMeta { + clone := &AllocationMeta{ + PodUid: am.PodUid, + PodNamespace: am.PodNamespace, + PodName: am.PodName, + ContainerName: am.ContainerName, + ContainerType: am.ContainerType, + ContainerIndex: am.ContainerIndex, + OwnerPoolName: am.OwnerPoolName, + PodRole: am.PodRole, + PodType: am.PodType, + QoSLevel: am.QoSLevel, + Labels: general.DeepCopyMap(am.Labels), + Annotations: general.DeepCopyMap(am.Annotations), + } + + return clone +} + +// GetPoolName parses the owner pool name for AllocationInfo +// if owner exists, just return; otherwise, parse from qos-level +func (am *AllocationMeta) GetPoolName() string { + if am == nil { + return EmptyOwnerPoolName + } + + if ownerPoolName := am.GetOwnerPoolName(); ownerPoolName != EmptyOwnerPoolName { + return ownerPoolName + } + return am.GetSpecifiedPoolName() +} + +// GetOwnerPoolName parses the owner pool name for AllocationInfo +func (am *AllocationMeta) GetOwnerPoolName() string { + if am == nil { + return EmptyOwnerPoolName + } + return am.OwnerPoolName +} + +// GetSpecifiedPoolName parses the owner pool name for AllocationInfo from qos-level +func (am *AllocationMeta) GetSpecifiedPoolName() string { + if am == nil { + return EmptyOwnerPoolName + } + + return GetSpecifiedPoolName(am.QoSLevel, am.Annotations[consts.PodAnnotationCPUEnhancementCPUSet]) +} + +// GetSpecifiedNUMABindingPoolName get numa_binding pool name +// for numa_binding shared_cores according to enhancements and NUMA hint +func (am *AllocationMeta) GetSpecifiedNUMABindingPoolName() (string, error) { + if !am.CheckSharedNUMABinding() { + return EmptyOwnerPoolName, fmt.Errorf("GetSpecifiedNUMABindingPoolName only for numa_binding shared_cores") + } + + numaSet, pErr := machine.Parse(am.Annotations[cpuconsts.CPUStateAnnotationKeyNUMAHint]) + if pErr != nil { + return EmptyOwnerPoolName, fmt.Errorf("parse numaHintStr: %s failed with error: %v", + am.Annotations[cpuconsts.CPUStateAnnotationKeyNUMAHint], pErr) + } else if numaSet.Size() != 1 { + return EmptyOwnerPoolName, fmt.Errorf("parse numaHintStr: %s with invalid size", numaSet.String()) + } + + specifiedPoolName := am.GetSpecifiedPoolName() + + if specifiedPoolName == EmptyOwnerPoolName { + return EmptyOwnerPoolName, fmt.Errorf("empty specifiedPoolName") + } + + return GetNUMAPoolName(specifiedPoolName, numaSet.ToSliceNoSortUInt64()[0]), nil +} + +func GetNUMAPoolName(candidateSpecifiedPoolName string, targetNUMANode uint64) string { + return fmt.Sprintf("%s%s%d", candidateSpecifiedPoolName, NUMAPoolInfix, targetNUMANode) +} + +// CheckMainContainer returns true if the AllocationInfo is for main container +func (am *AllocationMeta) CheckMainContainer() bool { + if am == nil { + return false + } + + return am.ContainerType == pluginapi.ContainerType_MAIN.String() +} + +// CheckSideCar returns true if the AllocationInfo is for side-car container +func (am *AllocationMeta) CheckSideCar() bool { + if am == nil { + return false + } + + return am.ContainerType == pluginapi.ContainerType_SIDECAR.String() +} + +func (am *AllocationMeta) GetSpecifiedSystemPoolName() (string, error) { + if !am.CheckSystem() { + return EmptyOwnerPoolName, fmt.Errorf("GetSpecifiedSystemPoolName only for system_cores") + } + + specifiedPoolName := am.GetSpecifiedPoolName() + if specifiedPoolName == EmptyOwnerPoolName { + return specifiedPoolName, nil + } + + return fmt.Sprintf("%s%s%s", PoolNamePrefixSystem, "-", specifiedPoolName), nil +} + +func (am *AllocationMeta) CheckSystem() bool { + if am == nil { + return false + } + return am.QoSLevel == consts.PodAnnotationQoSLevelSystemCores +} + +// CheckDedicated returns true if the AllocationInfo is for pod with dedicated-qos +func (am *AllocationMeta) CheckDedicated() bool { + if am == nil { + return false + } + return am.QoSLevel == consts.PodAnnotationQoSLevelDedicatedCores +} + +// CheckShared returns true if the AllocationInfo is for pod with shared-qos +func (am *AllocationMeta) CheckShared() bool { + if am == nil { + return false + } + return am.QoSLevel == consts.PodAnnotationQoSLevelSharedCores +} + +// CheckReclaimed returns true if the AllocationInfo is for pod with reclaimed-qos +func (am *AllocationMeta) CheckReclaimed() bool { + if am == nil { + return false + } + return am.QoSLevel == consts.PodAnnotationQoSLevelReclaimedCores +} + +// CheckNUMABinding returns true if the AllocationInfo is for pod with numa-binding enhancement +func (am *AllocationMeta) CheckNUMABinding() bool { + if am == nil { + return false + } + return am.Annotations[consts.PodAnnotationMemoryEnhancementNumaBinding] == + consts.PodAnnotationMemoryEnhancementNumaBindingEnable +} + +// CheckDedicatedNUMABinding returns true if the AllocationInfo is for pod with +// dedicated-qos and numa-binding enhancement +func (am *AllocationMeta) CheckDedicatedNUMABinding() bool { + return am.CheckDedicated() && am.CheckNUMABinding() +} + +// CheckSharedNUMABinding returns true if the AllocationInfo is for pod with +// shared-qos and numa-binding enhancement +func (am *AllocationMeta) CheckSharedNUMABinding() bool { + return am.CheckShared() && am.CheckNUMABinding() +} + +// CheckSharedOrDedicatedNUMABinding returns true if the AllocationInfo is for pod with +// shared-qos or dedicated-qos and numa-binding enhancement +func (am *AllocationMeta) CheckSharedOrDedicatedNUMABinding() bool { + if am == nil { + return false + } + + return am.CheckSharedNUMABinding() || am.CheckDedicatedNUMABinding() +} + +// CheckNumaExclusive returns true if the AllocationInfo is for pod with numa-exclusive enhancement +func (am *AllocationMeta) CheckNumaExclusive() bool { + if am == nil { + return false + } + + return am.Annotations[consts.PodAnnotationMemoryEnhancementNumaExclusive] == + consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable +} + +// CheckDedicatedPool returns true if the AllocationInfo is for a container in the dedicated pool +func (am *AllocationMeta) CheckDedicatedPool() bool { + if am == nil { + return false + } + return am.OwnerPoolName == PoolNameDedicated +} diff --git a/pkg/agent/qrm-plugins/commonstate/util.go b/pkg/agent/qrm-plugins/commonstate/util.go new file mode 100644 index 000000000..a253bfda5 --- /dev/null +++ b/pkg/agent/qrm-plugins/commonstate/util.go @@ -0,0 +1,109 @@ +/* +Copyright 2022 The Katalyst Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package commonstate + +import ( + "encoding/json" + "io/ioutil" + + pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" + + "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/util/general" +) + +// CheckNUMABindingSharedCoresAntiAffinity returns true +// if the AllocationMeta isn't compatible for the annotations of a numa binding shared cores candidate +func CheckNUMABindingSharedCoresAntiAffinity(meta *AllocationMeta, annotations map[string]string) bool { + if meta == nil { + return false + } else if len(annotations) == 0 { + return false + } + + if meta.CheckDedicatedNUMABinding() { + return true + } + + if meta.CheckSharedNUMABinding() { + // considering isolation, use specified pool instead of actual pool name here + candidateSpecifiedPoolName := GetSpecifiedPoolName(consts.PodAnnotationQoSLevelSharedCores, + annotations[consts.PodAnnotationCPUEnhancementCPUSet]) + aiSpecifiedPoolName := meta.GetSpecifiedPoolName() + + // shared_cores with numa binding doesn't support two share type pools with same specified name existing at same NUMA + if candidateSpecifiedPoolName != aiSpecifiedPoolName { + return true + } + } + + return false +} + +// GenerateGenericContainerAllocationMeta generates a generic container's allocation metadata. +// This function populates the AllocationMeta struct using data from the resource request and other parameters. +// Parameters: +// - req: The resource request containing information about the pod, container, and other attributes. +// - ownerPoolName: The name of the pool owning this container. +// - qosLevel: The QoS (Quality of Service) level for the container. +// Returns: +// - A pointer to an AllocationMeta struct filled with relevant data from the request and other inputs. +func GenerateGenericContainerAllocationMeta(req *pluginapi.ResourceRequest, ownerPoolName, qosLevel string) AllocationMeta { + return AllocationMeta{ + PodUid: req.PodUid, + PodNamespace: req.PodNamespace, + PodName: req.PodName, + ContainerName: req.ContainerName, + ContainerType: req.ContainerType.String(), + ContainerIndex: req.ContainerIndex, + OwnerPoolName: ownerPoolName, + PodRole: req.PodRole, + PodType: req.PodType, + Labels: general.DeepCopyMap(req.Labels), + Annotations: general.DeepCopyMap(req.Annotations), + QoSLevel: qosLevel, + } +} + +// GenerateGenericPoolAllocationMeta generates a generic allocation metadata for a pool. +// This function creates an AllocationMeta where both PodUid and OwnerPoolName are set to the given pool name. +// Parameters: +// - poolName: The name of the pool for which the metadata is generated. +// Returns: +// - A pointer to an AllocationMeta struct with the pool name set for both PodUid and OwnerPoolName. +func GenerateGenericPoolAllocationMeta(poolName string) AllocationMeta { + return AllocationMeta{ + PodUid: poolName, // The unique identifier for the pool (reusing poolName). + OwnerPoolName: poolName, // The name of the pool itself. + } +} + +func LoadExtraControlKnobConfigs(extraControlKnobConfigAbsPath string) (ExtraControlKnobConfigs, error) { + configBytes, err := ioutil.ReadFile(extraControlKnobConfigAbsPath) + if err != nil { + return nil, err + } + + extraControlKnobConfigs := make(ExtraControlKnobConfigs) + + err = json.Unmarshal(configBytes, &extraControlKnobConfigs) + if err != nil { + return nil, err + } + + return extraControlKnobConfigs, nil +} diff --git a/pkg/agent/qrm-plugins/commonstate/util_test.go b/pkg/agent/qrm-plugins/commonstate/util_test.go new file mode 100644 index 000000000..f11ab1bba --- /dev/null +++ b/pkg/agent/qrm-plugins/commonstate/util_test.go @@ -0,0 +1,195 @@ +/* +Copyright 2022 The Katalyst Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package commonstate + +import ( + "testing" + + pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" + + "github.com/kubewharf/katalyst-api/pkg/consts" +) + +func TestGetSpecifiedPoolName(t *testing.T) { + t.Parallel() + + type args struct { + qosLevel string + cpusetEnhancementValue string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "shared_cores with empty cpusetEnhancementValue", + args: args{ + qosLevel: consts.PodAnnotationQoSLevelSharedCores, + }, + want: PoolNameShare, + }, + { + name: "shared_cores with non-empty cpusetEnhancementValue", + args: args{ + qosLevel: consts.PodAnnotationQoSLevelSharedCores, + cpusetEnhancementValue: "offline", + }, + want: "offline", + }, + { + name: "dedicated_cores with empty cpusetEnhancementValue", + args: args{ + qosLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, + want: PoolNameDedicated, + }, + { + name: "reclaimed_cores with empty cpusetEnhancementValue", + args: args{ + qosLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, + want: PoolNameReclaim, + }, + { + name: "system_cores with empty cpusetEnhancementValue", + args: args{ + qosLevel: consts.PodAnnotationQoSLevelSystemCores, + cpusetEnhancementValue: "reserve", + }, + want: "reserve", + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + if got := GetSpecifiedPoolName(tt.args.qosLevel, tt.args.cpusetEnhancementValue); got != tt.want { + t.Errorf("GetSpecifiedPoolName() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestCheckNUMABindingSharedCoresAntiAffinity(t *testing.T) { + t.Parallel() + testName := "test" + type args struct { + am *AllocationMeta + annotations map[string]string + } + tests := []struct { + name string + args args + want bool + }{ + { + name: "anti affinity with dedicated numa_binding pods", + args: args{ + am: &AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, + annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + }, + want: true, + }, + { + name: "anti affinity with shared_cores numa_binding pods with same specified pool name", + args: args{ + am: &AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationCPUEnhancementCPUSet: "batch", + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, + annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationCPUEnhancementCPUSet: "bmq", + }, + }, + want: true, + }, + { + name: "not anti affinity with shared_cores numa_binding pods with same specified pool name", + args: args{ + am: &AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationCPUEnhancementCPUSet: "batch", + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, + annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationCPUEnhancementCPUSet: "batch", + }, + }, + want: false, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + if got := CheckNUMABindingSharedCoresAntiAffinity(tt.args.am, tt.args.annotations); got != tt.want { + t.Errorf("CheckNUMABindingSharedCoresAntiAffinity() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/agent/qrm-plugins/commonstate/utils.go b/pkg/agent/qrm-plugins/commonstate/utils.go deleted file mode 100644 index 38181d044..000000000 --- a/pkg/agent/qrm-plugins/commonstate/utils.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2022 The Katalyst Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package commonstate - -import ( - "encoding/json" - "io/ioutil" -) - -func LoadExtraControlKnobConfigs(extraControlKnobConfigAbsPath string) (ExtraControlKnobConfigs, error) { - configBytes, err := ioutil.ReadFile(extraControlKnobConfigAbsPath) - if err != nil { - return nil, err - } - - extraControlKnobConfigs := make(ExtraControlKnobConfigs) - - err = json.Unmarshal(configBytes, &extraControlKnobConfigs) - if err != nil { - return nil, err - } - - return extraControlKnobConfigs, nil -} diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/helper.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/helper.go index be4250f9d..80df56d09 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/helper.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/helper.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/util/general" "github.com/kubewharf/katalyst-core/pkg/util/machine" ) @@ -39,7 +39,7 @@ func (ci *CalculationInfo) IsSharedNUMABindingPool() bool { return false } - return len(ci.CalculationResultsByNumas) == 1 && ci.CalculationResultsByNumas[state.FakedNUMAID] == nil + return len(ci.CalculationResultsByNumas) == 1 && ci.CalculationResultsByNumas[commonstate.FakedNUMAID] == nil } func (ce *CalculationEntries) IsPoolEntry() bool { @@ -47,7 +47,7 @@ func (ce *CalculationEntries) IsPoolEntry() bool { return false } - return len(ce.Entries) == 1 && ce.Entries[state.FakedContainerName] != nil + return len(ce.Entries) == 1 && ce.Entries[commonstate.FakedContainerName] != nil } func (ce *CalculationEntries) IsSharedNUMABindingPoolEntry() bool { @@ -55,8 +55,8 @@ func (ce *CalculationEntries) IsSharedNUMABindingPoolEntry() bool { return false } - return len(ce.Entries[state.FakedContainerName].CalculationResultsByNumas) == 1 && - ce.Entries[state.FakedContainerName].CalculationResultsByNumas[state.FakedNUMAID] == nil + return len(ce.Entries[commonstate.FakedContainerName].CalculationResultsByNumas) == 1 && + ce.Entries[commonstate.FakedContainerName].CalculationResultsByNumas[commonstate.FakedNUMAID] == nil } func (lwr *ListAndWatchResponse) GetSharedBindingNUMAs() (sets.Int, error) { @@ -193,11 +193,11 @@ func getBlocksLessFunc(blocksEntryNames map[string][][]string, blocks []*Block) entryName, subEntryName := namesTuple[0], namesTuple[1] if isPod { - if subEntryName != state.FakedContainerName { + if subEntryName != commonstate.FakedContainerName { names = append(names, entryName) } } else { - if subEntryName == state.FakedContainerName { + if subEntryName == commonstate.FakedContainerName { names = append(names, entryName) } } @@ -217,7 +217,7 @@ func getBlocksLessFunc(blocksEntryNames map[string][][]string, blocks []*Block) return false } else { if len(podNames1) > 0 { - return strings.Join(podNames1, state.NameSeparator) < strings.Join(podNames2, state.NameSeparator) + return strings.Join(podNames1, commonstate.NameSeparator) < strings.Join(podNames2, commonstate.NameSeparator) } if len(poolNames1) > len(poolNames2) { @@ -225,7 +225,7 @@ func getBlocksLessFunc(blocksEntryNames map[string][][]string, blocks []*Block) } else if len(poolNames1) < len(poolNames2) { return false } else { - return strings.Join(poolNames1, state.NameSeparator) < strings.Join(poolNames2, state.NameSeparator) + return strings.Join(poolNames1, commonstate.NameSeparator) < strings.Join(poolNames2, commonstate.NameSeparator) } } } @@ -375,7 +375,7 @@ func IsBlockOfRelcaim(blockEntryNames [][]string) bool { for _, namesTuple := range blockEntryNames { entryName, subEntryName := namesTuple[0], namesTuple[1] - if entryName == state.PoolNameReclaim && subEntryName == state.FakedContainerName { + if entryName == commonstate.PoolNameReclaim && subEntryName == commonstate.FakedContainerName { return true } } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load.go index 1ab01e67d..738e93475 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load.go @@ -29,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" pluginapi "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" cpuutil "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/util" "github.com/kubewharf/katalyst-core/pkg/config" @@ -103,7 +104,7 @@ func NewCPUPressureLoadEviction(emitter metrics.MetricEmitter, metaServer *metas dynamicConf: conf.DynamicAgentConfiguration, skipPools: sets.NewString(conf.LoadPressureEvictionSkipPools...), syncPeriod: conf.LoadEvictionSyncPeriod, - configTranslator: general.NewCommonSuffixTranslator(state.NUMAPoolInfix), + configTranslator: general.NewCommonSuffixTranslator(commonstate.NUMAPoolInfix), } systemReservedCores, reserveErr := cpuutil.GetCoresReservedForSystem(conf, metaServer, metaServer.KatalystMachineInfo, metaServer.CPUDetails.CPUs().Clone()) @@ -152,11 +153,11 @@ func (p *CPUPressureLoadEviction) ThresholdMet(_ context.Context, var softThresholdMetPoolName string for poolName, entries := range p.metricsHistory[consts.MetricLoad1MinContainer] { - if !entries.IsPoolEntry() || p.skipPools.Has(p.configTranslator.Translate(poolName)) || state.IsIsolationPool(poolName) { + if !entries.IsPoolEntry() || p.skipPools.Has(p.configTranslator.Translate(poolName)) || commonstate.IsIsolationPool(poolName) { continue } - metricRing := entries[state.FakedContainerName] + metricRing := entries[commonstate.FakedContainerName] if metricRing == nil { general.Warningf("pool: %s hasn't metric: %s metricsRing", poolName, consts.MetricLoad1MinContainer) continue @@ -204,7 +205,7 @@ func (p *CPUPressureLoadEviction) ThresholdMet(_ context.Context, } p.clearEvictionPoolName() - if softThresholdMetPoolName != state.EmptyOwnerPoolName { + if softThresholdMetPoolName != commonstate.EmptyOwnerPoolName { _ = p.emitter.StoreFloat64(metricsNameThresholdMet, 1, metrics.MetricTypeNameCount, metrics.ConvertMapToTags(map[string]string{ metricsTagKeyPoolName: softThresholdMetPoolName, @@ -337,10 +338,10 @@ func (p *CPUPressureLoadEviction) collectMetrics(_ context.Context) { for containerName, containerEntry := range entry { if containerEntry == nil || containerEntry.IsPool { continue - } else if containerEntry.OwnerPool == state.EmptyOwnerPoolName || + } else if containerEntry.OwnerPool == commonstate.EmptyOwnerPoolName || p.skipPools.Has(p.configTranslator.Translate(containerEntry.OwnerPool)) || // skip pod with system pool - state.IsSystemPool(containerEntry.OwnerPool) { + commonstate.IsSystemPool(containerEntry.OwnerPool) { general.Infof("skip collecting metric for pod: %s, container: %s with owner pool name: %s", podUID, containerName, containerEntry.OwnerPool) continue @@ -408,7 +409,7 @@ func (p *CPUPressureLoadEviction) checkSharedPressureByPoolSize(pod2Pool PodPool } for _, containerEntry := range entry { - if !containerEntry.IsPool || p.skipPools.Has(p.configTranslator.Translate(poolName)) || entry[state.FakedContainerName] == nil { + if !containerEntry.IsPool || p.skipPools.Has(p.configTranslator.Translate(poolName)) || entry[commonstate.FakedContainerName] == nil { continue } poolSizeSum += containerEntry.PoolSize @@ -425,7 +426,8 @@ func (p *CPUPressureLoadEviction) checkSharedPressureByPoolSize(pod2Pool PodPool // accumulateSharedPoolsLimit calculates the cpu core limit used by shared core pool, // and it equals: machine-core - cores-for-dedicated-pods - reserved-cores-reclaim-pods - reserved-cores-system-pods. func (p *CPUPressureLoadEviction) accumulateSharedPoolsLimit() int { - availableCPUSet := p.state.GetMachineState().GetFilteredAvailableCPUSet(p.systemReservedCPUs, nil, state.CheckSharedOrDedicatedNUMABinding) + availableCPUSet := p.state.GetMachineState().GetFilteredAvailableCPUSet(p.systemReservedCPUs, nil, + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckSharedOrDedicatedNUMABinding)) coreNumReservedForReclaim := p.dynamicConf.GetDynamicConfiguration().MinReclaimedResourceForAllocate[v1.ResourceCPU] if coreNumReservedForReclaim.Value() > int64(p.metaServer.NumCPUs) { @@ -434,7 +436,7 @@ func (p *CPUPressureLoadEviction) accumulateSharedPoolsLimit() int { reservedForReclaim := machine.GetCoreNumReservedForReclaim(int(coreNumReservedForReclaim.Value()), p.metaServer.NumNUMANodes) reservedForReclaimInSharedNuma := 0 - sharedCoresNUMAs := p.state.GetMachineState().GetFilteredNUMASet(state.CheckSharedOrDedicatedNUMABinding) + sharedCoresNUMAs := p.state.GetMachineState().GetFilteredNUMASet(state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckSharedOrDedicatedNUMABinding)) for _, numaID := range sharedCoresNUMAs.ToSliceInt() { reservedForReclaimInSharedNuma += reservedForReclaim[numaID] } @@ -487,7 +489,7 @@ func (p *CPUPressureLoadEviction) collectPoolLoad(dynamicConfig *dynamic.Configu })...) p.logPoolSnapShot(snapshot, poolName, true) - p.pushMetric(dynamicConfig, metricName, poolName, state.FakedContainerName, snapshot) + p.pushMetric(dynamicConfig, metricName, poolName, commonstate.FakedContainerName, snapshot) } // collectPoolMetricDefault is a common collect in pool level, @@ -504,7 +506,7 @@ func (p *CPUPressureLoadEviction) collectPoolMetricDefault(dynamicConfig *dynami } p.logPoolSnapShot(snapshot, poolName, false) - p.pushMetric(dynamicConfig, metricName, poolName, state.FakedContainerName, snapshot) + p.pushMetric(dynamicConfig, metricName, poolName, commonstate.FakedContainerName, snapshot) } // pushMetric stores and push-in metric for the given pod @@ -563,10 +565,10 @@ func (p *CPUPressureLoadEviction) logPoolSnapShot(snapshot *MetricSnapshot, pool // clearEvictionPoolName resets pool in local memory func (p *CPUPressureLoadEviction) clearEvictionPoolName() { - if p.evictionPoolName != state.FakedContainerName { + if p.evictionPoolName != commonstate.FakedContainerName { general.Infof("clear eviction pool name: %s", p.evictionPoolName) } - p.evictionPoolName = state.FakedContainerName + p.evictionPoolName = commonstate.FakedContainerName } // setEvictionPoolName sets pool in local memory @@ -578,7 +580,7 @@ func (p *CPUPressureLoadEviction) setEvictionPoolName(evictionPoolName string) { // getEvictionPoolName returns the previously-set pool func (p *CPUPressureLoadEviction) getEvictionPoolName() (exists bool, evictionPoolName string) { evictionPoolName = p.evictionPoolName - if evictionPoolName == state.FakedContainerName { + if evictionPoolName == commonstate.FakedContainerName { exists = false return } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_metric.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_metric.go index ee366af64..d4e6bd78b 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_metric.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_metric.go @@ -19,7 +19,7 @@ package strategy import ( "sync" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic" ) @@ -47,7 +47,7 @@ type MetricRing struct { type SubEntries map[string]*MetricRing func (se SubEntries) IsPoolEntry() bool { - return len(se) == 1 && se[state.FakedContainerName] != nil + return len(se) == 1 && se[commonstate.FakedContainerName] != nil } // Entries are keyed by pod UID or pool name diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_test.go index 6b4650032..1d56903a6 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_load_test.go @@ -37,6 +37,7 @@ import ( apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" evictionpluginapi "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" qrmstate "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/config" "github.com/kubewharf/katalyst-core/pkg/consts" @@ -91,10 +92,10 @@ func makeConf(metricRingSize int, gracePeriod int64, loadUpperBoundRatio, loadLo } conf.ReservedCPUCores = reservedForSystem conf.LoadPressureEvictionSkipPools = []string{ - qrmstate.PoolNameReclaim, - qrmstate.PoolNameDedicated, - qrmstate.PoolNameFallback, - qrmstate.PoolNameReserve, + commonstate.PoolNameReclaim, + commonstate.PoolNameDedicated, + commonstate.PoolNameFallback, + commonstate.PoolNameReserve, } return conf } @@ -166,14 +167,23 @@ func TestThresholdMet(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -188,20 +198,12 @@ func TestThresholdMet(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -238,14 +240,23 @@ func TestThresholdMet(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -260,20 +271,12 @@ func TestThresholdMet(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -310,14 +313,23 @@ func TestThresholdMet(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -332,20 +344,12 @@ func TestThresholdMet(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -452,14 +456,23 @@ func TestGetTopEvictionPods(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -474,20 +487,12 @@ func TestGetTopEvictionPods(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -517,14 +522,23 @@ func TestGetTopEvictionPods(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -539,20 +553,12 @@ func TestGetTopEvictionPods(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -585,14 +591,23 @@ func TestGetTopEvictionPods(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -607,26 +622,28 @@ func TestGetTopEvictionPods(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -641,26 +658,28 @@ func TestGetTopEvictionPods(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameReclaim, AllocationResult: machine.NewCPUSet(7, 8, 10, 15), OriginalAllocationResult: machine.NewCPUSet(7, 8, 10, 15), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -673,20 +692,12 @@ func TestGetTopEvictionPods(t *testing.T) { 1: machine.NewCPUSet(10), 3: machine.NewCPUSet(7, 15), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -703,10 +714,9 @@ func TestGetTopEvictionPods(t *testing.T) { }, }, }, - qrmstate.PoolNameReclaim: qrmstate.ContainerEntries{ + commonstate.PoolNameReclaim: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameReclaim, - OwnerPoolName: qrmstate.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("7-8,10,15"), OriginalAllocationResult: machine.MustParse("7-8,10,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -804,12 +814,12 @@ func TestGetTopEvictionPods(t *testing.T) { assert.NotNil(t, resp) if metResp.MetType == evictionpluginapi.ThresholdMetType_HARD_MET { - as.Equal(candidatePods, resp.TargetPods) + as.Equalf(candidatePods, resp.TargetPods, tt.name) tt.wantResp = &evictionpluginapi.GetTopEvictionPodsResponse{ TargetPods: candidatePods, } } - as.Equal(tt.wantResp, resp) + as.Equalf(tt.wantResp, resp, tt.name) } } @@ -840,14 +850,23 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -862,26 +881,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -896,26 +917,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameReclaim, AllocationResult: machine.NewCPUSet(7, 8, 10, 15), OriginalAllocationResult: machine.NewCPUSet(7, 8, 10, 15), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -928,20 +951,12 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 1: machine.NewCPUSet(10), 3: machine.NewCPUSet(7, 15), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -958,10 +973,9 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { }, }, }, - qrmstate.PoolNameReclaim: qrmstate.ContainerEntries{ + commonstate.PoolNameReclaim: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameReclaim, - OwnerPoolName: qrmstate.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("7-8,10,15"), OriginalAllocationResult: machine.MustParse("7-8,10,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1006,14 +1020,23 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("3-6,11-14"), OriginalAllocationResult: machine.MustParse("3-6,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1028,26 +1051,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("3-6,11-14"), OriginalAllocationResult: machine.MustParse("3-6,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1062,26 +1087,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameReclaim, AllocationResult: machine.NewCPUSet(7, 10, 15), OriginalAllocationResult: machine.NewCPUSet(7, 10, 15), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1092,26 +1119,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 1: machine.NewCPUSet(10), 3: machine.NewCPUSet(7, 15), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, pod4UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod4UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod4UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameDedicated, AllocationResult: machine.NewCPUSet(0-1, 8-9), OriginalAllocationResult: machine.NewCPUSet(0-1, 8-9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1120,21 +1149,13 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(0, 1, 8, 9), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("3-6,11-14"), OriginalAllocationResult: machine.MustParse("3-6,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1151,10 +1172,9 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { }, }, }, - qrmstate.PoolNameReclaim: qrmstate.ContainerEntries{ + commonstate.PoolNameReclaim: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameReclaim, - OwnerPoolName: qrmstate.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("7,10,15"), OriginalAllocationResult: machine.MustParse("7,10,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1198,14 +1218,23 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("3-6,11-14"), OriginalAllocationResult: machine.MustParse("3-6,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1220,26 +1249,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("3-6,11-14"), OriginalAllocationResult: machine.MustParse("3-6,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1254,26 +1285,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameReclaim, AllocationResult: machine.NewCPUSet(7, 10, 15), OriginalAllocationResult: machine.NewCPUSet(7, 10, 15), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1284,26 +1317,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 1: machine.NewCPUSet(10), 3: machine.NewCPUSet(7, 15), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, pod4UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod4UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod4UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameDedicated, AllocationResult: machine.NewCPUSet(0-1, 8-9), OriginalAllocationResult: machine.NewCPUSet(0-1, 8-9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1312,21 +1347,13 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(0, 1, 8, 9), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("3-6,11-14"), OriginalAllocationResult: machine.MustParse("3-6,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1343,10 +1370,9 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { }, }, }, - qrmstate.PoolNameReclaim: qrmstate.ContainerEntries{ + commonstate.PoolNameReclaim: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameReclaim, - OwnerPoolName: qrmstate.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("7,10,15"), OriginalAllocationResult: machine.MustParse("7,10,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1390,14 +1416,23 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("3-6,11-14"), OriginalAllocationResult: machine.MustParse("3-6,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1412,26 +1447,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameShare, AllocationResult: machine.MustParse("3-6,11-14"), OriginalAllocationResult: machine.MustParse("3-6,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1446,26 +1483,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameReclaim, AllocationResult: machine.NewCPUSet(7, 10, 15), OriginalAllocationResult: machine.NewCPUSet(7, 10, 15), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1476,26 +1515,28 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { 1: machine.NewCPUSet(10), 3: machine.NewCPUSet(7, 15), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, pod4UID: qrmstate.ContainerEntries{ testName: &qrmstate.AllocationInfo{ - PodUid: pod4UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod4UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameDedicated, AllocationResult: machine.NewCPUSet(0-1, 8-9), OriginalAllocationResult: machine.NewCPUSet(0-1, 8-9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1504,21 +1545,13 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(0, 1, 8, 9), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelDedicatedCores, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameShare: qrmstate.ContainerEntries{ + commonstate.PoolNameShare: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameShare, - OwnerPoolName: qrmstate.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("3-6,11-14"), OriginalAllocationResult: machine.MustParse("3-6,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1535,10 +1568,9 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { }, }, }, - qrmstate.PoolNameReclaim: qrmstate.ContainerEntries{ + commonstate.PoolNameReclaim: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameReclaim, - OwnerPoolName: qrmstate.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("7,10,15"), OriginalAllocationResult: machine.MustParse("7,10,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1616,7 +1648,7 @@ func TestCPUPressureLoadEviction_collectMetrics(t *testing.T) { as.NotNil(plugin) p := plugin.(*CPUPressureLoadEviction) p.collectMetrics(context.TODO()) - metricRing := p.metricsHistory[consts.MetricLoad1MinContainer][qrmstate.PoolNameShare][""] + metricRing := p.metricsHistory[consts.MetricLoad1MinContainer][commonstate.PoolNameShare][""] snapshot := metricRing.Queue[metricRing.CurrentIndex] as.True(math.Abs(tt.wantSharedPoolSnapshots.Value-snapshot.Info.Value) < 0.01) diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression.go index 49add6a6f..caa52cef1 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression.go @@ -28,6 +28,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1" pluginapi "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/config" "github.com/kubewharf/katalyst-core/pkg/metaserver" @@ -81,7 +82,7 @@ func (p *CPUPressureSuppression) GetEvictPods(_ context.Context, request *plugin // only reclaim pool support suppression tolerance eviction entries := p.state.GetPodEntries() - poolCPUSet, err := entries.GetCPUSetForPool(state.PoolNameReclaim) + poolCPUSet, err := entries.GetCPUSetForPool(commonstate.PoolNameReclaim) if err != nil { return nil, fmt.Errorf("get reclaim pool failed: %s", err) } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression_test.go index 20c62a21b..216ecc0a3 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpueviction/strategy/pressure_suppression_test.go @@ -34,6 +34,7 @@ import ( apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" evictionpluginapi "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" qrmstate "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/config" pkgconsts "github.com/kubewharf/katalyst-core/pkg/consts" @@ -98,14 +99,24 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ pod1Name: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: pod1Name, - PodName: pod1Name, - ContainerName: pod1Name, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: pod1Name, + PodName: pod1Name, + ContainerName: pod1Name, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + apiconsts.PodAnnotationCPUEnhancementKey: `{"suppression_tolerance_rate": "1.2"}`, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameReclaim, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -120,21 +131,12 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - apiconsts.PodAnnotationCPUEnhancementKey: `{"suppression_tolerance_rate": "1.2"}`, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - qrmstate.PoolNameReclaim: qrmstate.ContainerEntries{ + commonstate.PoolNameReclaim: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameReclaim, - OwnerPoolName: qrmstate.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -173,14 +175,24 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) { podEntries: qrmstate.PodEntries{ pod1UID: qrmstate.ContainerEntries{ pod1Name: &qrmstate.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: pod1Name, - PodName: pod1Name, - ContainerName: pod1Name, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: pod1Name, + PodName: pod1Name, + ContainerName: pod1Name, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + apiconsts.PodAnnotationCPUEnhancementKey: `{"suppression_tolerance_rate": "1.2"}`, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameReclaim, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -195,27 +207,29 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - apiconsts.PodAnnotationCPUEnhancementKey: `{"suppression_tolerance_rate": "1.2"}`, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 15, }, }, pod2UID: qrmstate.ContainerEntries{ pod1Name: &qrmstate.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: pod2Name, - PodName: pod2Name, - ContainerName: pod2Name, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: pod2Name, + PodName: pod2Name, + ContainerName: pod2Name, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, + apiconsts.PodAnnotationCPUEnhancementKey: `{"suppression_tolerance_rate": "1.2"}`, + }, + QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: qrmstate.PoolNameReclaim, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -230,21 +244,12 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelReclaimedCores, - apiconsts.PodAnnotationCPUEnhancementKey: `{"suppression_tolerance_rate": "1.2"}`, - }, - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 4, }, }, - qrmstate.PoolNameReclaim: qrmstate.ContainerEntries{ + commonstate.PoolNameReclaim: qrmstate.ContainerEntries{ "": &qrmstate.AllocationInfo{ - PodUid: qrmstate.PoolNameReclaim, - OwnerPoolName: qrmstate.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go index cd810ee66..2e9f2b2b5 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy.go @@ -35,6 +35,7 @@ import ( "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/agent" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/agent/qrm" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/calculator" advisorapi "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor" @@ -428,9 +429,9 @@ func (p *DynamicPolicy) GetResourcesAllocation(_ context.Context, // pooledCPUs is the total available cpu cores minus those that are reserved pooledCPUs := machineState.GetFilteredAvailableCPUSet(p.reservedCPUs, func(ai *state.AllocationInfo) bool { - return state.CheckDedicated(ai) || state.CheckSharedNUMABinding(ai) + return ai.CheckDedicated() || ai.CheckSharedNUMABinding() }, - state.CheckDedicatedNUMABinding) + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckDedicatedNUMABinding)) pooledCPUsTopologyAwareAssignments, err := machine.GetNumaAwareAssignments(p.machineInfo.CPUTopology, pooledCPUs) if err != nil { return nil, fmt.Errorf("GetNumaAwareAssignments err: %v", err) @@ -463,7 +464,7 @@ func (p *DynamicPolicy) GetResourcesAllocation(_ context.Context, initTs, tsErr := time.Parse(util.QRMTimeFormat, allocationInfo.InitTimestamp) if tsErr != nil { - if state.CheckShared(allocationInfo) && !state.CheckNUMABinding(allocationInfo) { + if allocationInfo.CheckShared() && !allocationInfo.CheckNUMABinding() { general.Errorf("pod: %s/%s, container: %s init timestamp parsed failed with error: %v, re-ramp-up it", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName, tsErr) @@ -475,7 +476,7 @@ func (p *DynamicPolicy) GetResourcesAllocation(_ context.Context, allocationInfo.TopologyAwareAssignments = clonedPooledCPUsTopologyAwareAssignments allocationInfo.OriginalTopologyAwareAssignments = clonedPooledCPUsTopologyAwareAssignments // fill OwnerPoolName with empty string when ramping up - allocationInfo.OwnerPoolName = state.EmptyOwnerPoolName + allocationInfo.OwnerPoolName = commonstate.EmptyOwnerPoolName allocationInfo.RampUp = true } @@ -486,7 +487,7 @@ func (p *DynamicPolicy) GetResourcesAllocation(_ context.Context, allocationInfo.RampUp = false p.state.SetAllocationInfo(podUID, containerName, allocationInfo) - if state.CheckShared(allocationInfo) { + if allocationInfo.CheckShared() { allocationInfosJustFinishRampUp = append(allocationInfosJustFinishRampUp, allocationInfo) } } @@ -994,7 +995,7 @@ func (p *DynamicPolicy) cleanPools() error { for _, allocationInfo := range entries { ownerPool := allocationInfo.GetOwnerPoolName() - if ownerPool != state.EmptyOwnerPoolName { + if ownerPool != commonstate.EmptyOwnerPoolName { remainPools[ownerPool] = true } } @@ -1032,28 +1033,27 @@ func (p *DynamicPolicy) cleanPools() error { // initReservePool initializes reserve pool for system cores workload func (p *DynamicPolicy) initReservePool() error { - reserveAllocationInfo := p.state.GetAllocationInfo(state.PoolNameReserve, state.FakedContainerName) + reserveAllocationInfo := p.state.GetAllocationInfo(commonstate.PoolNameReserve, commonstate.FakedContainerName) if reserveAllocationInfo != nil && !reserveAllocationInfo.AllocationResult.IsEmpty() { general.Infof("pool: %s allocation result transform from %s to %s", - state.PoolNameReserve, reserveAllocationInfo.AllocationResult.String(), p.reservedCPUs) + commonstate.PoolNameReserve, reserveAllocationInfo.AllocationResult.String(), p.reservedCPUs) } - general.Infof("initReservePool %s: %s", state.PoolNameReserve, p.reservedCPUs) + general.Infof("initReservePool %s: %s", commonstate.PoolNameReserve, p.reservedCPUs) topologyAwareAssignments, err := machine.GetNumaAwareAssignments(p.machineInfo.CPUTopology, p.reservedCPUs) if err != nil { return fmt.Errorf("unable to calculate topologyAwareAssignments for pool: %s, result cpuset: %s, error: %v", - state.PoolNameReserve, p.reservedCPUs.String(), err) + commonstate.PoolNameReserve, p.reservedCPUs.String(), err) } curReserveAllocationInfo := &state.AllocationInfo{ - PodUid: state.PoolNameReserve, - OwnerPoolName: state.PoolNameReserve, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReserve), AllocationResult: p.reservedCPUs.Clone(), OriginalAllocationResult: p.reservedCPUs.Clone(), TopologyAwareAssignments: topologyAwareAssignments, OriginalTopologyAwareAssignments: machine.DeepcopyCPUAssignment(topologyAwareAssignments), } - p.state.SetAllocationInfo(state.PoolNameReserve, state.FakedContainerName, curReserveAllocationInfo) + p.state.SetAllocationInfo(commonstate.PoolNameReserve, commonstate.FakedContainerName, curReserveAllocationInfo) return nil } @@ -1061,7 +1061,7 @@ func (p *DynamicPolicy) initReservePool() error { // initReclaimPool initializes pools for reclaimed-cores. // if this info already exists in state-file, just use it, otherwise calculate right away func (p *DynamicPolicy) initReclaimPool() error { - reclaimedAllocationInfo := p.state.GetAllocationInfo(state.PoolNameReclaim, state.FakedContainerName) + reclaimedAllocationInfo := p.state.GetAllocationInfo(commonstate.PoolNameReclaim, commonstate.FakedContainerName) if reclaimedAllocationInfo == nil { podEntries := p.state.GetPodEntries() noneResidentCPUs := podEntries.GetFilteredPoolsCPUSet(state.ResidentPools) @@ -1069,9 +1069,9 @@ func (p *DynamicPolicy) initReclaimPool() error { machineState := p.state.GetMachineState() availableCPUs := machineState.GetFilteredAvailableCPUSet(p.reservedCPUs, func(ai *state.AllocationInfo) bool { - return state.CheckDedicated(ai) || state.CheckSharedNUMABinding(ai) + return ai.CheckDedicated() || ai.CheckSharedNUMABinding() }, - state.CheckDedicatedNUMABinding).Difference(noneResidentCPUs) + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckDedicatedNUMABinding)).Difference(noneResidentCPUs) var initReclaimedCPUSetSize int if availableCPUs.Size() >= reservedReclaimedCPUsSize { @@ -1083,7 +1083,7 @@ func (p *DynamicPolicy) initReclaimPool() error { reclaimedCPUSet, _, err := calculator.TakeByNUMABalance(p.machineInfo, availableCPUs, initReclaimedCPUSetSize) if err != nil { return fmt.Errorf("takeByNUMABalance faild in initReclaimPool for %s and %s with error: %v", - state.PoolNameShare, state.PoolNameReclaim, err) + commonstate.PoolNameShare, commonstate.PoolNameReclaim, err) } // for residual pools, we must make them exist even if cause overlap @@ -1093,11 +1093,11 @@ func (p *DynamicPolicy) initReclaimPool() error { reclaimedCPUSet, _, err = calculator.TakeByNUMABalance(p.machineInfo, allAvailableCPUs, reservedReclaimedCPUsSize) if err != nil { return fmt.Errorf("fallback takeByNUMABalance faild in initReclaimPool for %s with error: %v", - state.PoolNameReclaim, err) + commonstate.PoolNameReclaim, err) } } - for poolName, cset := range map[string]machine.CPUSet{state.PoolNameReclaim: reclaimedCPUSet} { + for poolName, cset := range map[string]machine.CPUSet{commonstate.PoolNameReclaim: reclaimedCPUSet} { general.Infof("initReclaimPool %s: %s", poolName, cset.String()) topologyAwareAssignments, err := machine.GetNumaAwareAssignments(p.machineInfo.CPUTopology, cset) if err != nil { @@ -1106,17 +1106,16 @@ func (p *DynamicPolicy) initReclaimPool() error { } curPoolAllocationInfo := &state.AllocationInfo{ - PodUid: poolName, - OwnerPoolName: poolName, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(poolName), AllocationResult: cset.Clone(), OriginalAllocationResult: cset.Clone(), TopologyAwareAssignments: topologyAwareAssignments, OriginalTopologyAwareAssignments: machine.DeepcopyCPUAssignment(topologyAwareAssignments), } - p.state.SetAllocationInfo(poolName, state.FakedContainerName, curPoolAllocationInfo) + p.state.SetAllocationInfo(poolName, commonstate.FakedContainerName, curPoolAllocationInfo) } } else { - general.Infof("exist initial %s: %s", state.PoolNameReclaim, reclaimedAllocationInfo.AllocationResult.String()) + general.Infof("exist initial %s: %s", commonstate.PoolNameReclaim, reclaimedAllocationInfo.AllocationResult.String()) } return nil @@ -1145,14 +1144,14 @@ func (p *DynamicPolicy) getContainerRequestedCores(allocationInfo *state.Allocat // optimize this logic someday: // only for refresh cpu request for old pod with cpu ceil and old inplace update resized pods. - if state.CheckShared(allocationInfo) { + if allocationInfo.CheckShared() { // if there is these two annotations in memory state, it is a new pod, // we don't need to check the pod request from podWatcher if allocationInfo.Annotations[consts.PodAnnotationAggregatedRequestsKey] != "" || allocationInfo.Annotations[consts.PodAnnotationInplaceUpdateResizingKey] != "" { return allocationInfo.RequestQuantity } - if state.CheckNUMABinding(allocationInfo) { + if allocationInfo.CheckNUMABinding() { if metaValue < allocationInfo.RequestQuantity { general.Infof("[snb] get cpu request quantity: (%.3f->%.3f) for pod: %s/%s container: %s from podWatcher", allocationInfo.RequestQuantity, metaValue, allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName) @@ -1184,7 +1183,8 @@ func (p *DynamicPolicy) checkNormalShareCoresCpuResource(req *pluginapi.Resource machineState := p.state.GetMachineState() pooledCPUs := machineState.GetFilteredAvailableCPUSet(p.reservedCPUs, - state.CheckDedicated, state.CheckSharedOrDedicatedNUMABinding) + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckDedicated), + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckSharedOrDedicatedNUMABinding)) general.Infof("[checkNormalShareCoresCpuResource] node cpu allocated: %d, allocatable: %d", shareCoresAllocatedInt, pooledCPUs.Size()) if shareCoresAllocatedInt > pooledCPUs.Size() { diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_advisor_handler.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_advisor_handler.go index 328065bce..05b5c45af 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_advisor_handler.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_advisor_handler.go @@ -32,6 +32,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/calculator" advisorapi "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor" @@ -141,7 +142,7 @@ func (p *DynamicPolicy) GetCheckpoint(_ context.Context, } ownerPoolName := allocationInfo.GetOwnerPoolName() - if ownerPoolName == state.EmptyOwnerPoolName { + if ownerPoolName == commonstate.EmptyOwnerPoolName { general.Warningf("pod: %s/%s container: %s get empty owner pool name", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName) if allocationInfo.CheckSideCar() { @@ -157,7 +158,7 @@ func (p *DynamicPolicy) GetCheckpoint(_ context.Context, // not set topology-aware assignments for shared_cores and reclaimed_cores, // since their topology-aware assignments are same to the pools they are in. - if (!state.CheckShared(allocationInfo) && !state.CheckReclaimed(allocationInfo)) || containerEntries.IsPoolEntry() { + if (!allocationInfo.CheckShared() && !allocationInfo.CheckReclaimed()) || containerEntries.IsPoolEntry() { chkEntries[uid].Entries[entryName].TopologyAwareAssignments = machine.ParseCPUAssignmentFormat(allocationInfo.TopologyAwareAssignments) chkEntries[uid].Entries[entryName].OriginalTopologyAwareAssignments = machine.ParseCPUAssignmentFormat(allocationInfo.OriginalTopologyAwareAssignments) } @@ -318,12 +319,12 @@ func (p *DynamicPolicy) generateBlockCPUSet(resp *advisorapi.ListAndWatchRespons // and calculate availableCPUs after deducting static pools blockCPUSet := advisorapi.NewBlockCPUSet() for _, poolName := range state.StaticPools.List() { - allocationInfo := p.state.GetAllocationInfo(poolName, state.FakedContainerName) + allocationInfo := p.state.GetAllocationInfo(poolName, commonstate.FakedContainerName) if allocationInfo == nil { continue } - blocks, ok := resp.GeEntryNUMABlocks(poolName, state.FakedContainerName, state.FakedNUMAID) + blocks, ok := resp.GeEntryNUMABlocks(poolName, commonstate.FakedContainerName, commonstate.FakedNUMAID) if !ok || len(blocks) != 1 { return nil, fmt.Errorf("blocks of pool: %s is invalid", poolName) } @@ -336,7 +337,7 @@ func (p *DynamicPolicy) generateBlockCPUSet(resp *advisorapi.ListAndWatchRespons // walk through all blocks with specified NUMA ids // for each block, add them into blockCPUSet (if not exist) and renew availableCPUs for numaID, blocks := range numaToBlocks { - if numaID == state.FakedNUMAID { + if numaID == commonstate.FakedNUMAID { continue } @@ -374,7 +375,7 @@ func (p *DynamicPolicy) generateBlockCPUSet(resp *advisorapi.ListAndWatchRespons // walk through all blocks without specified NUMA id // for each block, add them into blockCPUSet (if not exist) and renew availableCPUs - for _, block := range numaToBlocks[state.FakedNUMAID] { + for _, block := range numaToBlocks[commonstate.FakedNUMAID] { if block == nil { general.Warningf("got nil block") continue @@ -430,7 +431,7 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad if calculationInfo == nil { general.Warningf("got nil calculationInfo entry: %s, subEntry: %s", entryName, subEntryName) continue - } else if !(subEntryName == state.FakedContainerName || calculationInfo.OwnerPoolName == state.PoolNameDedicated) { + } else if !(subEntryName == commonstate.FakedContainerName || calculationInfo.OwnerPoolName == commonstate.PoolNameDedicated) { continue } @@ -452,7 +453,7 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad if allocationInfo == nil { // currently, cpu advisor can only create new pools, // all container entries or entries with owner pool name dedicated can't be created by cpu advisor - if calculationInfo.OwnerPoolName == state.PoolNameDedicated || subEntryName != state.FakedContainerName { + if calculationInfo.OwnerPoolName == commonstate.PoolNameDedicated || subEntryName != commonstate.FakedContainerName { return fmt.Errorf("no-pool entry isn't found in plugin cache, entry: %s, subEntry: %s", entryName, subEntryName) } else if entryName != calculationInfo.OwnerPoolName { return fmt.Errorf("pool entryName: %s and OwnerPoolName: %s mismatch", entryName, calculationInfo.OwnerPoolName) @@ -460,8 +461,10 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad general.Infof("create new pool: %s cpuset result %s", entryName, entryCPUSet.String()) allocationInfo = &state.AllocationInfo{ - PodUid: entryName, - OwnerPoolName: entryName, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: entryName, + OwnerPoolName: entryName, + }, AllocationResult: entryCPUSet.Clone(), OriginalAllocationResult: entryCPUSet.Clone(), TopologyAwareAssignments: topologyAwareAssignments, @@ -487,7 +490,7 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad pooledUnionDedicatedCPUSet = pooledUnionDedicatedCPUSet.Union(allocationInfo.AllocationResult) // ramp-up finishes immediately for dedicated - if allocationInfo.OwnerPoolName == state.PoolNameDedicated { + if allocationInfo.OwnerPoolName == commonstate.PoolNameDedicated { dedicatedCPUSet = dedicatedCPUSet.Union(allocationInfo.AllocationResult) general.Infof("try to apply dedicated_cores: %s/%s %s: %s", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName, allocationInfo.AllocationResult.String()) @@ -499,7 +502,7 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad } else { _ = p.emitter.StoreInt64(util.MetricNamePoolSize, int64(allocationInfo.AllocationResult.Size()), metrics.MetricTypeNameRaw, metrics.MetricTag{Key: "poolName", Val: allocationInfo.OwnerPoolName}, - metrics.MetricTag{Key: "pool_type", Val: state.GetPoolType(allocationInfo.OwnerPoolName)}) + metrics.MetricTag{Key: "pool_type", Val: commonstate.GetPoolType(allocationInfo.OwnerPoolName)}) general.Infof("try to apply pool %s: %s", allocationInfo.OwnerPoolName, allocationInfo.AllocationResult.String()) } } @@ -507,7 +510,7 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad // if there is no block for state.PoolNameReclaim pool, // we must make it existing here even if cause overlap - if newEntries.CheckPoolEmpty(state.PoolNameReclaim) { + if newEntries.CheckPoolEmpty(commonstate.PoolNameReclaim) { reclaimPoolCPUSet := p.machineInfo.CPUDetails.CPUs().Difference(p.reservedCPUs).Difference(pooledUnionDedicatedCPUSet) if reclaimPoolCPUSet.IsEmpty() { allAvailableCPUs := p.machineInfo.CPUDetails.CPUs().Difference(p.reservedCPUs) @@ -524,22 +527,24 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad topologyAwareAssignments, err := machine.GetNumaAwareAssignments(p.machineInfo.CPUTopology, reclaimPoolCPUSet) if err != nil { return fmt.Errorf("unable to calculate topologyAwareAssignments for pool: %s, "+ - "result cpuset: %s, error: %v", state.PoolNameReclaim, reclaimPoolCPUSet.String(), err) + "result cpuset: %s, error: %v", commonstate.PoolNameReclaim, reclaimPoolCPUSet.String(), err) } - if newEntries[state.PoolNameReclaim] == nil { - newEntries[state.PoolNameReclaim] = make(state.ContainerEntries) + if newEntries[commonstate.PoolNameReclaim] == nil { + newEntries[commonstate.PoolNameReclaim] = make(state.ContainerEntries) } - newEntries[state.PoolNameReclaim][state.FakedContainerName] = &state.AllocationInfo{ - PodUid: state.PoolNameReclaim, - OwnerPoolName: state.PoolNameReclaim, + newEntries[commonstate.PoolNameReclaim][commonstate.FakedContainerName] = &state.AllocationInfo{ + AllocationMeta: commonstate.AllocationMeta{ + PodUid: commonstate.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, + }, AllocationResult: reclaimPoolCPUSet.Clone(), OriginalAllocationResult: reclaimPoolCPUSet.Clone(), TopologyAwareAssignments: topologyAwareAssignments, OriginalTopologyAwareAssignments: machine.DeepcopyCPUAssignment(topologyAwareAssignments), } } else { - general.Infof("detected reclaimPoolCPUSet: %s", newEntries[state.PoolNameReclaim][state.FakedContainerName].AllocationResult.String()) + general.Infof("detected reclaimPoolCPUSet: %s", newEntries[commonstate.PoolNameReclaim][commonstate.FakedContainerName].AllocationResult.String()) } // calculate rampUpCPUs @@ -625,12 +630,12 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad continue containerLoop } - newEntries[podUID][containerName].OwnerPoolName = state.EmptyOwnerPoolName + newEntries[podUID][containerName].OwnerPoolName = commonstate.EmptyOwnerPoolName newEntries[podUID][containerName].AllocationResult = rampUpCPUs.Clone() newEntries[podUID][containerName].OriginalAllocationResult = rampUpCPUs.Clone() newEntries[podUID][containerName].TopologyAwareAssignments = machine.DeepcopyCPUAssignment(rampUpCPUsTopologyAwareAssignments) newEntries[podUID][containerName].OriginalTopologyAwareAssignments = machine.DeepcopyCPUAssignment(rampUpCPUsTopologyAwareAssignments) - } else if newEntries[ownerPoolName][state.FakedContainerName] == nil { + } else if newEntries[ownerPoolName][commonstate.FakedContainerName] == nil { errMsg := fmt.Sprintf("cpu advisor doesn't return entry for pool: %s and it's referred by pod: %s/%s, container: %s, qosLevel: %s", ownerPoolName, allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName, allocationInfo.QoSLevel) @@ -643,12 +648,12 @@ func (p *DynamicPolicy) applyBlocks(blockCPUSet advisorapi.BlockCPUSet, resp *ad metrics.MetricTag{Key: "poolName", Val: ownerPoolName}) return fmt.Errorf(errMsg) } else { - poolEntry := newEntries[ownerPoolName][state.FakedContainerName] + poolEntry := newEntries[ownerPoolName][commonstate.FakedContainerName] general.Infof("put pod: %s/%s container: %s to pool: %s, set its allocation result from %s to %s", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName, ownerPoolName, allocationInfo.AllocationResult.String(), poolEntry.AllocationResult.String()) - if state.CheckSharedNUMABinding(allocationInfo) { + if allocationInfo.CheckSharedNUMABinding() { poolEntry.QoSLevel = apiconsts.PodAnnotationQoSLevelSharedCores // set SharedNUMABinding declarations to pool entry containing SharedNUMABinding containers, // in order to differentiate them from normal share pools during GetFilteredPoolsCPUSetMap. diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_allocation_handlers.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_allocation_handlers.go index fc9a968e6..cc69516de 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_allocation_handlers.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_allocation_handlers.go @@ -29,6 +29,7 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/calculator" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" @@ -70,7 +71,8 @@ func (p *DynamicPolicy) sharedCoresWithoutNUMABindingAllocationHandler(_ context machineState := p.state.GetMachineState() pooledCPUs := machineState.GetFilteredAvailableCPUSet(p.reservedCPUs, - state.CheckDedicated, state.CheckSharedOrDedicatedNUMABinding) + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckDedicated), + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckSharedOrDedicatedNUMABinding)) if pooledCPUs.IsEmpty() { general.Errorf("pod: %s/%s, container: %s get empty pooledCPUs", req.PodNamespace, req.PodName, req.ContainerName) @@ -101,30 +103,20 @@ func (p *DynamicPolicy) sharedCoresWithoutNUMABindingAllocationHandler(_ context shouldRampUp := p.shouldSharedCoresRampUp(req.PodUid) allocationInfo = &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, + AllocationMeta: commonstate.GenerateGenericContainerAllocationMeta(req, + commonstate.EmptyOwnerPoolName, apiconsts.PodAnnotationQoSLevelSharedCores), RampUp: shouldRampUp, - OwnerPoolName: state.EmptyOwnerPoolName, - PodRole: req.PodRole, - PodType: req.PodType, AllocationResult: pooledCPUs, OriginalAllocationResult: pooledCPUs.Clone(), TopologyAwareAssignments: pooledCPUsTopologyAwareAssignments, OriginalTopologyAwareAssignments: machine.DeepcopyCPUAssignment(pooledCPUsTopologyAwareAssignments), InitTimestamp: time.Now().Format(util.QRMTimeFormat), - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, RequestQuantity: reqFloat64, } if !shouldRampUp { targetPoolName := allocationInfo.GetSpecifiedPoolName() - poolAllocationInfo := p.state.GetAllocationInfo(targetPoolName, state.FakedContainerName) + poolAllocationInfo := p.state.GetAllocationInfo(targetPoolName, commonstate.FakedContainerName) if poolAllocationInfo == nil { general.Infof("pod: %s/%s, container: %s is active, but its specified pool entry doesn't exist, try to ramp up it", @@ -228,17 +220,17 @@ func (p *DynamicPolicy) reclaimedCoresAllocationHandler(_ context.Context, return nil, fmt.Errorf("updateAllocationInfoByReq failed with error: %v", err) } - reclaimedAllocationInfo := p.state.GetAllocationInfo(state.PoolNameReclaim, state.FakedContainerName) + reclaimedAllocationInfo := p.state.GetAllocationInfo(commonstate.PoolNameReclaim, commonstate.FakedContainerName) if reclaimedAllocationInfo == nil { general.Errorf("allocation for pod: %s/%s, container: %s is failed, because pool: %s is not ready", - req.PodNamespace, req.PodName, req.ContainerName, state.PoolNameReclaim) + req.PodNamespace, req.PodName, req.ContainerName, commonstate.PoolNameReclaim) - return nil, fmt.Errorf("pool: %s is not ready", state.PoolNameReclaim) + return nil, fmt.Errorf("pool: %s is not ready", commonstate.PoolNameReclaim) } else if reclaimedAllocationInfo.AllocationResult.Size() == 0 { general.Errorf("allocation for pod: %s/%s, container: %s is failed, because pool: %s is empty", - req.PodNamespace, req.PodName, req.ContainerName, state.PoolNameReclaim) + req.PodNamespace, req.PodName, req.ContainerName, commonstate.PoolNameReclaim) - return nil, fmt.Errorf("pool: %s is not empty", state.PoolNameReclaim) + return nil, fmt.Errorf("pool: %s is not empty", commonstate.PoolNameReclaim) } if allocationInfo != nil { @@ -249,24 +241,13 @@ func (p *DynamicPolicy) reclaimedCoresAllocationHandler(_ context.Context, req.PodNamespace, req.PodName, req.ContainerName, reclaimedAllocationInfo.AllocationResult.String()) allocationInfo = &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - OwnerPoolName: state.PoolNameReclaim, - PodRole: req.PodRole, - PodType: req.PodType, + AllocationMeta: commonstate.GenerateGenericContainerAllocationMeta(req, + commonstate.PoolNameReclaim, apiconsts.PodAnnotationQoSLevelReclaimedCores), InitTimestamp: time.Now().Format(util.QRMTimeFormat), - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: reqFloat64, } } - allocationInfo.OwnerPoolName = state.PoolNameReclaim allocationInfo.AllocationResult = reclaimedAllocationInfo.AllocationResult.Clone() allocationInfo.OriginalAllocationResult = reclaimedAllocationInfo.OriginalAllocationResult.Clone() allocationInfo.TopologyAwareAssignments = machine.DeepcopyCPUAssignment(reclaimedAllocationInfo.TopologyAwareAssignments) @@ -382,24 +363,14 @@ func (p *DynamicPolicy) dedicatedCoresWithNUMABindingAllocationHandler(ctx conte } allocationInfo := &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, + AllocationMeta: commonstate.GenerateGenericContainerAllocationMeta(req, + commonstate.PoolNameDedicated, apiconsts.PodAnnotationQoSLevelDedicatedCores), RampUp: true, - PodRole: req.PodRole, - PodType: req.PodType, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: result.Clone(), OriginalAllocationResult: result.Clone(), TopologyAwareAssignments: topologyAwareAssignments, OriginalTopologyAwareAssignments: machine.DeepcopyCPUAssignment(topologyAwareAssignments), InitTimestamp: time.Now().Format(util.QRMTimeFormat), - QoSLevel: apiconsts.PodAnnotationQoSLevelDedicatedCores, - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), RequestQuantity: reqFloat64, } @@ -459,18 +430,9 @@ func (p *DynamicPolicy) allocationSidecarHandler(_ context.Context, // the sidecar container also support inplace update resize, update the allocation and machine state here allocationInfo := &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodRole: req.PodRole, - PodType: req.PodType, + AllocationMeta: commonstate.GenerateGenericContainerAllocationMeta(req, + commonstate.EmptyOwnerPoolName, qosLevel), InitTimestamp: time.Now().Format(util.QRMTimeFormat), - QoSLevel: qosLevel, - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), RequestQuantity: reqFloat64, } p.applySidecarAllocationInfoFromMainContainer(allocationInfo, mainContainerAllocationInfo) @@ -615,23 +577,15 @@ func (p *DynamicPolicy) allocateSharedNumaBindingCPUs(req *pluginapi.ResourceReq targetNUMANode := hint.Nodes[0] allocationInfo := &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodRole: req.PodRole, - PodType: req.PodType, - OwnerPoolName: state.EmptyOwnerPoolName, // it will be put to correct pool in doAndCheckPutAllocationInfo - InitTimestamp: time.Now().Format(util.QRMTimeFormat), - QoSLevel: apiconsts.PodAnnotationQoSLevelSharedCores, - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.MergeMap(req.Annotations, map[string]string{ - cpuconsts.CPUStateAnnotationKeyNUMAHint: fmt.Sprintf("%d", targetNUMANode), - }), + AllocationMeta: commonstate.GenerateGenericContainerAllocationMeta(req, + // it will be put to correct pool in doAndCheckPutAllocationInfo + commonstate.EmptyOwnerPoolName, apiconsts.PodAnnotationQoSLevelSharedCores), + InitTimestamp: time.Now().Format(util.QRMTimeFormat), RequestQuantity: reqFloat64, } + allocationInfo.Annotations = general.MergeMap(allocationInfo.Annotations, map[string]string{ + cpuconsts.CPUStateAnnotationKeyNUMAHint: fmt.Sprintf("%d", targetNUMANode), + }) if util.PodInplaceUpdateResizing(req) { originAllocationInfo := p.state.GetAllocationInfo(allocationInfo.PodUid, allocationInfo.ContainerName) @@ -684,7 +638,7 @@ func (p *DynamicPolicy) putAllocationsAndAdjustAllocationEntriesResizeAware(orig for _, allocationInfo := range allocationInfos { if allocationInfo == nil { return fmt.Errorf("found nil allocationInfo in input parameter") - } else if !state.CheckShared(allocationInfo) { + } else if !allocationInfo.CheckShared() { return fmt.Errorf("put container with invalid qos level: %s into pool", allocationInfo.QoSLevel) } else if entries[allocationInfo.PodUid][allocationInfo.ContainerName] == nil { return fmt.Errorf("entry %s/%s, %s isn't found in state", @@ -692,7 +646,7 @@ func (p *DynamicPolicy) putAllocationsAndAdjustAllocationEntriesResizeAware(orig } poolName := allocationInfo.GetSpecifiedPoolName() - if poolName == state.EmptyOwnerPoolName { + if poolName == commonstate.EmptyOwnerPoolName { return fmt.Errorf("allocationInfo points to empty poolName") } } @@ -765,7 +719,7 @@ func (p *DynamicPolicy) putAllocationsAndAdjustAllocationEntriesResizeAware(orig func (p *DynamicPolicy) calcPoolResizeRequest(originAllocation, allocation *state.AllocationInfo, podEntries state.PodEntries) (string, int, float64, error) { poolName := allocation.GetPoolName() - targetNumaID := state.FakedNUMAID + targetNumaID := commonstate.FakedNUMAID originPodAggregatedRequest, ok := originAllocation.GetPodAggregatedRequest() if !ok { @@ -814,7 +768,7 @@ func (p *DynamicPolicy) calcPoolResizeRequest(originAllocation, allocation *stat } // only support normal share and snb inplace update resize now - if state.CheckSharedNUMABinding(allocation) { + if allocation.CheckSharedNUMABinding() { // check snb numa migrate for inplace update resize originTargetNumaID, err := state.GetSharedNUMABindingTargetNuma(originAllocation) if err != nil { @@ -842,7 +796,7 @@ func (p *DynamicPolicy) calcPoolResizeRequest(originAllocation, allocation *stat } } - if poolName == state.EmptyOwnerPoolName { + if poolName == commonstate.EmptyOwnerPoolName { return "", 0, 0, fmt.Errorf("get poolName failed for %s/%s/%s", allocation.PodNamespace, allocation.PodName, allocation.ContainerName) } @@ -891,7 +845,8 @@ func (p *DynamicPolicy) adjustAllocationEntries() error { func (p *DynamicPolicy) adjustPoolsAndIsolatedEntries(poolsQuantityMap map[string]map[int]int, isolatedQuantityMap map[string]map[string]int, entries state.PodEntries, machineState state.NUMANodeMap, ) error { - availableCPUs := machineState.GetFilteredAvailableCPUSet(p.reservedCPUs, nil, state.CheckDedicatedNUMABinding) + availableCPUs := machineState.GetFilteredAvailableCPUSet(p.reservedCPUs, nil, + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckDedicatedNUMABinding)) reclaimOverlapShareRatio, err := p.getReclaimOverlapShareRatio(entries) if err != nil { @@ -930,12 +885,12 @@ func (p *DynamicPolicy) reclaimOverlapNUMABinding(poolsCPUSet map[string]machine return nil } - if entries.CheckPoolEmpty(state.PoolNameReclaim) { + if entries.CheckPoolEmpty(commonstate.PoolNameReclaim) { return fmt.Errorf("reclaim pool misses in current entries") } - curReclaimCPUSet := entries[state.PoolNameReclaim][state.FakedContainerName].AllocationResult.Clone() - nonOverlapReclaimCPUSet := poolsCPUSet[state.PoolNameReclaim].Clone() + curReclaimCPUSet := entries[commonstate.PoolNameReclaim][commonstate.FakedContainerName].AllocationResult.Clone() + nonOverlapReclaimCPUSet := poolsCPUSet[commonstate.PoolNameReclaim].Clone() general.Infof("curReclaimCPUSet: %s", curReclaimCPUSet.String()) for _, containerEntries := range entries { @@ -944,7 +899,7 @@ func (p *DynamicPolicy) reclaimOverlapNUMABinding(poolsCPUSet map[string]machine } for _, allocationInfo := range containerEntries { - if !(allocationInfo != nil && state.CheckDedicatedNUMABinding(allocationInfo) && allocationInfo.CheckMainContainer()) { + if !(allocationInfo != nil && allocationInfo.CheckDedicatedNUMABinding() && allocationInfo.CheckMainContainer()) { continue } else if allocationInfo.RampUp { general.Infof("dedicated numa_binding pod: %s/%s container: %s is in ramp up, not to overlap reclaim pool with it", @@ -952,15 +907,15 @@ func (p *DynamicPolicy) reclaimOverlapNUMABinding(poolsCPUSet map[string]machine continue } - poolsCPUSet[state.PoolNameReclaim] = poolsCPUSet[state.PoolNameReclaim].Union(curReclaimCPUSet.Intersection(allocationInfo.AllocationResult)) + poolsCPUSet[commonstate.PoolNameReclaim] = poolsCPUSet[commonstate.PoolNameReclaim].Union(curReclaimCPUSet.Intersection(allocationInfo.AllocationResult)) } } - if poolsCPUSet[state.PoolNameReclaim].IsEmpty() { + if poolsCPUSet[commonstate.PoolNameReclaim].IsEmpty() { return fmt.Errorf("reclaim pool is empty after overlapping with dedicated_cores numa_binding containers") } - general.Infof("nonOverlapReclaimCPUSet: %s, finalReclaimCPUSet: %s", nonOverlapReclaimCPUSet.String(), poolsCPUSet[state.PoolNameReclaim].String()) + general.Infof("nonOverlapReclaimCPUSet: %s, finalReclaimCPUSet: %s", nonOverlapReclaimCPUSet.String(), poolsCPUSet[commonstate.PoolNameReclaim].String()) return nil } @@ -982,7 +937,7 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine if allocationInfo == nil { general.Errorf("isolated pod: %s, container: %s without entry in current checkpoint", podUID, containerName) continue - } else if !state.CheckDedicated(allocationInfo) || state.CheckNUMABinding(allocationInfo) { + } else if !allocationInfo.CheckDedicated() || allocationInfo.CheckNUMABinding() { general.Errorf("isolated pod: %s, container: %s isn't dedicated_cores without NUMA binding", podUID, containerName) continue } @@ -1010,7 +965,7 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine } newPodEntries[podUID][containerName] = allocationInfo.Clone() - newPodEntries[podUID][containerName].OwnerPoolName = state.PoolNameDedicated + newPodEntries[podUID][containerName].OwnerPoolName = commonstate.PoolNameDedicated newPodEntries[podUID][containerName].AllocationResult = isolatedCPUs.Clone() newPodEntries[podUID][containerName].OriginalAllocationResult = isolatedCPUs.Clone() newPodEntries[podUID][containerName].TopologyAwareAssignments = topologyAwareAssignments @@ -1021,8 +976,8 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine } // 2. construct entries for all pools - if poolsCPUSet[state.PoolNameReclaim].IsEmpty() { - return fmt.Errorf("entry: %s is empty", state.PoolNameReclaim) + if poolsCPUSet[commonstate.PoolNameReclaim].IsEmpty() { + return fmt.Errorf("entry: %s is empty", commonstate.PoolNameReclaim) } for poolName, cset := range poolsCPUSet { @@ -1034,7 +989,7 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine poolName, cset.String(), err) } - allocationInfo := curEntries[poolName][state.FakedContainerName] + allocationInfo := curEntries[poolName][commonstate.FakedContainerName] if allocationInfo != nil { general.Infof("pool: %s allocation result transform from %s(size: %d) to %s(size: %d)", poolName, allocationInfo.AllocationResult.String(), allocationInfo.AllocationResult.Size(), @@ -1044,9 +999,8 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine if newPodEntries[poolName] == nil { newPodEntries[poolName] = make(state.ContainerEntries) } - newPodEntries[poolName][state.FakedContainerName] = &state.AllocationInfo{ - PodUid: poolName, - OwnerPoolName: poolName, + newPodEntries[poolName][commonstate.FakedContainerName] = &state.AllocationInfo{ + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(poolName), AllocationResult: cset.Clone(), OriginalAllocationResult: cset.Clone(), TopologyAwareAssignments: topologyAwareAssignments, @@ -1055,13 +1009,14 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine _ = p.emitter.StoreInt64(util.MetricNamePoolSize, int64(cset.Size()), metrics.MetricTypeNameRaw, metrics.MetricTag{Key: "poolName", Val: poolName}, - metrics.MetricTag{Key: "pool_type", Val: state.GetPoolType(poolName)}) + metrics.MetricTag{Key: "pool_type", Val: commonstate.GetPoolType(poolName)}) } sharedBindingNUMACPUs := p.machineInfo.CPUDetails.CPUsInNUMANodes(sharedBindingNUMAs.UnsortedList()...) // rampUpCPUs include reclaim pool in NUMAs without NUMA_binding cpus rampUpCPUs := machineState.GetFilteredAvailableCPUSet(p.reservedCPUs, - nil, state.CheckDedicatedNUMABinding). + nil, + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckDedicatedNUMABinding)). Difference(unionDedicatedIsolatedCPUSet). Difference(sharedBindingNUMACPUs) @@ -1102,7 +1057,7 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine newPodEntries[podUID][containerName].OwnerPoolName = allocationInfo.GetPoolName() // for numa_binding containers, we just clone checkpoint already exist - if state.CheckDedicatedNUMABinding(allocationInfo) { + if allocationInfo.CheckDedicatedNUMABinding() { continue containerLoop } @@ -1111,7 +1066,7 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine "we put it into fallback pool: %s temporary", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName, rampUpCPUs.String()) - newPodEntries[podUID][containerName].OwnerPoolName = state.PoolNameFallback + newPodEntries[podUID][containerName].OwnerPoolName = commonstate.PoolNameFallback newPodEntries[podUID][containerName].AllocationResult = rampUpCPUs.Clone() newPodEntries[podUID][containerName].OriginalAllocationResult = rampUpCPUs.Clone() newPodEntries[podUID][containerName].TopologyAwareAssignments = machine.DeepcopyCPUAssignment(rampUpCPUsTopologyAwareAssignments) @@ -1133,10 +1088,10 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine case apiconsts.PodAnnotationQoSLevelSharedCores, apiconsts.PodAnnotationQoSLevelReclaimedCores: var ownerPoolName string - if state.CheckSharedNUMABinding(allocationInfo) { + if allocationInfo.CheckSharedNUMABinding() { ownerPoolName = allocationInfo.GetOwnerPoolName() - if ownerPoolName == state.EmptyOwnerPoolName { + if ownerPoolName == commonstate.EmptyOwnerPoolName { var err error // why do we integrate GetOwnerPoolName + GetSpecifiedNUMABindingPoolName into GetPoolName for SharedNUMABinding containers? // it's because we reply on GetSpecifiedPoolName (in GetPoolName) when calling CheckNUMABindingSharedCoresAntiAffinity, @@ -1158,12 +1113,12 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName, allocationInfo.AllocationResult.String(), rampUpCPUs.String()) - newPodEntries[podUID][containerName].OwnerPoolName = state.EmptyOwnerPoolName + newPodEntries[podUID][containerName].OwnerPoolName = commonstate.EmptyOwnerPoolName newPodEntries[podUID][containerName].AllocationResult = rampUpCPUs.Clone() newPodEntries[podUID][containerName].OriginalAllocationResult = rampUpCPUs.Clone() newPodEntries[podUID][containerName].TopologyAwareAssignments = machine.DeepcopyCPUAssignment(rampUpCPUsTopologyAwareAssignments) newPodEntries[podUID][containerName].OriginalTopologyAwareAssignments = machine.DeepcopyCPUAssignment(rampUpCPUsTopologyAwareAssignments) - } else if newPodEntries[ownerPoolName][state.FakedContainerName] == nil { + } else if newPodEntries[ownerPoolName][commonstate.FakedContainerName] == nil { general.Warningf("pod: %s/%s container: %s get owner pool: %s allocationInfo failed. reuse its allocation result: %s", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName, ownerPoolName, allocationInfo.AllocationResult.String()) @@ -1173,12 +1128,12 @@ func (p *DynamicPolicy) applyPoolsAndIsolatedInfo(poolsCPUSet map[string]machine metrics.MetricTag{Key: "containerName", Val: allocationInfo.ContainerName}, metrics.MetricTag{Key: "poolName", Val: ownerPoolName}) } else { - poolEntry := newPodEntries[ownerPoolName][state.FakedContainerName] + poolEntry := newPodEntries[ownerPoolName][commonstate.FakedContainerName] general.Infof("put pod: %s/%s container: %s to pool: %s, set its allocation result from %s to %s", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName, ownerPoolName, allocationInfo.AllocationResult.String(), poolEntry.AllocationResult.String()) - if state.CheckSharedNUMABinding(allocationInfo) { + if allocationInfo.CheckSharedNUMABinding() { poolEntry.QoSLevel = apiconsts.PodAnnotationQoSLevelSharedCores // set SharedNUMABinding declarations to pool entry containing SharedNUMABinding containers, // in order to differentiate them from normal share pools during GetFilteredPoolsCPUSetMap. @@ -1221,7 +1176,7 @@ func (p *DynamicPolicy) generateNUMABindingPoolsCPUSetInPlace(poolsCPUSet map[st for poolName, numaToQuantity := range poolsQuantityMap { for numaID, quantity := range numaToQuantity { - if numaID == state.FakedNUMAID { + if numaID == commonstate.FakedNUMAID { // only deal with numa_binding pools continue } @@ -1289,7 +1244,7 @@ func (p *DynamicPolicy) generatePoolsAndIsolation(poolsQuantityMap map[string]ma if quantity == 0 { poolsToSkip = append(poolsToSkip, poolName) } else { - if numaID != state.FakedNUMAID { + if numaID != commonstate.FakedNUMAID { poolsBindingNUMAs.Insert(numaID) } else { nonBindingPoolsQuantityMap[poolName] = quantity @@ -1404,24 +1359,24 @@ func (p *DynamicPolicy) generatePoolsAndIsolation(poolsQuantityMap map[string]ma availableCPUs = availableCPUs.Union(nonBindingAvailableCPUs) // deal with reserve pool - if poolsCPUSet[state.PoolNameReserve].IsEmpty() { - poolsCPUSet[state.PoolNameReserve] = p.reservedCPUs.Clone() - general.Infof("set pool %s:%s", state.PoolNameReserve, poolsCPUSet[state.PoolNameReserve].String()) + if poolsCPUSet[commonstate.PoolNameReserve].IsEmpty() { + poolsCPUSet[commonstate.PoolNameReserve] = p.reservedCPUs.Clone() + general.Infof("set pool %s:%s", commonstate.PoolNameReserve, poolsCPUSet[commonstate.PoolNameReserve].String()) } else { - err = fmt.Errorf("static pool %s result: %s is generated dynamically", state.PoolNameReserve, poolsCPUSet[state.PoolNameReserve].String()) + err = fmt.Errorf("static pool %s result: %s is generated dynamically", commonstate.PoolNameReserve, poolsCPUSet[commonstate.PoolNameReserve].String()) return } // deal with reclaim pool - poolsCPUSet[state.PoolNameReclaim] = poolsCPUSet[state.PoolNameReclaim].Union(availableCPUs) + poolsCPUSet[commonstate.PoolNameReclaim] = poolsCPUSet[commonstate.PoolNameReclaim].Union(availableCPUs) if !p.state.GetAllowSharedCoresOverlapReclaimedCores() { enableReclaim := p.dynamicConfig.GetDynamicConfiguration().EnableReclaim - if !enableReclaim && poolsCPUSet[state.PoolNameReclaim].Size() > reservedReclaimedCPUsSize { - poolsCPUSet[state.PoolNameReclaim] = p.apportionReclaimedPool( - poolsCPUSet, poolsCPUSet[state.PoolNameReclaim].Clone(), nonBindingPoolsQuantityMap) + if !enableReclaim && poolsCPUSet[commonstate.PoolNameReclaim].Size() > reservedReclaimedCPUsSize { + poolsCPUSet[commonstate.PoolNameReclaim] = p.apportionReclaimedPool( + poolsCPUSet, poolsCPUSet[commonstate.PoolNameReclaim].Clone(), nonBindingPoolsQuantityMap) general.Infof("apportionReclaimedPool finished, current %s pool: %s", - state.PoolNameReclaim, poolsCPUSet[state.PoolNameReclaim].String()) + commonstate.PoolNameReclaim, poolsCPUSet[commonstate.PoolNameReclaim].String()) } } else { // p.state.GetAllowSharedCoresOverlapReclaimedCores() == true @@ -1436,18 +1391,18 @@ func (p *DynamicPolicy) generatePoolsAndIsolation(poolsQuantityMap map[string]ma overlapCPUs, _, tErr := calculator.TakeByNUMABalanceReversely(p.machineInfo, cset, req) if tErr != nil { err = fmt.Errorf("take overlapCPUs from: %s to %s by ratio: %.4f failed with err: %v", - poolName, state.PoolNameReclaim, ratio, tErr) + poolName, commonstate.PoolNameReclaim, ratio, tErr) return } general.Infof("merge overlapCPUs: %s from pool: %s to %s by ratio: %.4f", - overlapCPUs.String(), poolName, state.PoolNameReclaim, ratio) - poolsCPUSet[state.PoolNameReclaim] = poolsCPUSet[state.PoolNameReclaim].Union(overlapCPUs) + overlapCPUs.String(), poolName, commonstate.PoolNameReclaim, ratio) + poolsCPUSet[commonstate.PoolNameReclaim] = poolsCPUSet[commonstate.PoolNameReclaim].Union(overlapCPUs) } } } - if poolsCPUSet[state.PoolNameReclaim].IsEmpty() { + if poolsCPUSet[commonstate.PoolNameReclaim].IsEmpty() { // for reclaimed pool, we must make them exist when the node isn't in hybrid mode even if cause overlap allAvailableCPUs := p.machineInfo.CPUDetails.CPUs().Difference(p.reservedCPUs) reclaimedCPUSet, _, tErr := calculator.TakeByNUMABalance(p.machineInfo, allAvailableCPUs, reservedReclaimedCPUsSize) @@ -1457,7 +1412,7 @@ func (p *DynamicPolicy) generatePoolsAndIsolation(poolsQuantityMap map[string]ma } general.Infof("fallback takeByNUMABalance in generatePoolsAndIsolation for reclaimedCPUSet: %s", reclaimedCPUSet.String()) - poolsCPUSet[state.PoolNameReclaim] = reclaimedCPUSet + poolsCPUSet[commonstate.PoolNameReclaim] = reclaimedCPUSet } return @@ -1726,13 +1681,13 @@ func (p *DynamicPolicy) getReclaimOverlapShareRatio(entries state.PodEntries) (m return nil, nil } - if entries.CheckPoolEmpty(state.PoolNameReclaim) { + if entries.CheckPoolEmpty(commonstate.PoolNameReclaim) { return nil, fmt.Errorf("reclaim pool misses in current entries") } reclaimOverlapShareRatio := make(map[string]float64) - curReclaimCPUSet := entries[state.PoolNameReclaim][state.FakedContainerName].AllocationResult + curReclaimCPUSet := entries[commonstate.PoolNameReclaim][commonstate.FakedContainerName].AllocationResult for poolName, subEntries := range entries { if !subEntries.IsPoolEntry() { @@ -1741,7 +1696,7 @@ func (p *DynamicPolicy) getReclaimOverlapShareRatio(entries state.PodEntries) (m allocationInfo := subEntries.GetPoolEntry() - if allocationInfo != nil && state.GetPoolType(poolName) == state.PoolNameShare { + if allocationInfo != nil && commonstate.GetPoolType(poolName) == commonstate.PoolNameShare { if allocationInfo.AllocationResult.IsEmpty() { continue } @@ -1773,19 +1728,9 @@ func (p *DynamicPolicy) systemCoresAllocationHandler(ctx context.Context, req *p } allocationInfo := &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - OwnerPoolName: state.EmptyOwnerPoolName, - PodRole: req.PodRole, - PodType: req.PodType, - InitTimestamp: time.Now().Format(util.QRMTimeFormat), - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), - QoSLevel: apiconsts.PodAnnotationQoSLevelSystemCores, + AllocationMeta: commonstate.GenerateGenericContainerAllocationMeta(req, + commonstate.EmptyOwnerPoolName, apiconsts.PodAnnotationQoSLevelSystemCores), + InitTimestamp: time.Now().Format(util.QRMTimeFormat), } poolCPUSet, topologyAwareAssignments, err := p.getSystemPoolCPUSetAndNumaAwareAssignments(p.state.GetPodEntries(), allocationInfo) @@ -1845,7 +1790,7 @@ func (p *DynamicPolicy) getSystemPoolCPUSetAndNumaAwareAssignments(podEntries st poolCPUSet := machine.NewCPUSet() specifiedPoolName := allocationInfo.GetSpecifiedPoolName() - if specifiedPoolName != state.EmptyOwnerPoolName { + if specifiedPoolName != commonstate.EmptyOwnerPoolName { for pool, entries := range podEntries { if !entries.IsPoolEntry() { continue @@ -1862,7 +1807,7 @@ func (p *DynamicPolicy) getSystemPoolCPUSetAndNumaAwareAssignments(podEntries st // if pool set is empty, try to get default cpuset if poolCPUSet.IsEmpty() { // if the pod is numa binding, get the default cpuset from machine state - if state.CheckNUMABinding(allocationInfo) { + if allocationInfo.CheckNUMABinding() { poolCPUSet = p.state.GetMachineState().GetAvailableCPUSet(p.reservedCPUs) } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_async_handler.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_async_handler.go index 491140006..3080d9093 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_async_handler.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_async_handler.go @@ -75,7 +75,7 @@ func (p *DynamicPolicy) checkCPUSet(_ *coreconfig.Configuration, for containerName, allocationInfo := range containerEntries { if allocationInfo == nil || !allocationInfo.CheckMainContainer() { continue - } else if state.CheckShared(allocationInfo) && p.getContainerRequestedCores(allocationInfo) == 0 { + } else if allocationInfo.CheckShared() && p.getContainerRequestedCores(allocationInfo) == 0 { general.Warningf("skip cpuset checking for pod: %s/%s container: %s with zero cpu request", allocationInfo.PodNamespace, allocationInfo.PodName, containerName) continue @@ -115,7 +115,7 @@ func (p *DynamicPolicy) checkCPUSet(_ *coreconfig.Configuration, allocationInfo.AllocationResult.String(), actualCPUSets[podUID][containerName].String()) // only do comparison for dedicated_cores with numa_biding to avoid effect of adjustment for shared_cores - if !state.CheckDedicated(allocationInfo) { + if !allocationInfo.CheckDedicated() { continue } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_hint_handlers.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_hint_handlers.go index cebdff5c1..bfe5f780c 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_hint_handlers.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_hint_handlers.go @@ -29,6 +29,7 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" cpuutil "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/util" @@ -165,7 +166,8 @@ func (p *DynamicPolicy) dedicatedCoresWithNUMABindingHintHandler(_ context.Conte // if hints exists in extra state-file, prefer to use them if hints == nil { - availableNUMAs := machineState.GetFilteredNUMASet(state.CheckSharedOrDedicatedNUMABinding) + availableNUMAs := machineState.GetFilteredNUMASet(state.WrapAllocationMetaFilter( + (*commonstate.AllocationMeta).CheckSharedOrDedicatedNUMABinding)) var extraErr error hints, extraErr = util.GetHintsFromExtraStateFile(req.PodName, string(v1.ResourceCPU), p.extraStateFileAbsPath, availableNUMAs) @@ -351,7 +353,7 @@ func getNUMAAllocatedMemBW(machineState state.NUMANodeMap, metaServer *metaserve for _, entries := range numaState.PodEntries { for _, allocationInfo := range entries { - if !(state.CheckDedicatedNUMABinding(allocationInfo) && allocationInfo.CheckMainContainer()) { + if !(allocationInfo.CheckDedicatedNUMABinding() && allocationInfo.CheckMainContainer()) { continue } @@ -794,14 +796,15 @@ func (p *DynamicPolicy) calculateHintsForNUMABindingSharedCores(reqInt int, podE machineState state.NUMANodeMap, req *pluginapi.ResourceRequest, ) (map[string]*pluginapi.ListOfTopologyHints, error) { - nonBindingNUMAsCPUQuantity := machineState.GetFilteredAvailableCPUSet(p.reservedCPUs, nil, state.CheckSharedOrDedicatedNUMABinding).Size() - nonBindingNUMAs := machineState.GetFilteredNUMASet(state.CheckSharedOrDedicatedNUMABinding) + nonBindingNUMAsCPUQuantity := machineState.GetFilteredAvailableCPUSet(p.reservedCPUs, nil, + state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckSharedOrDedicatedNUMABinding)).Size() + nonBindingNUMAs := machineState.GetFilteredNUMASet(state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckSharedOrDedicatedNUMABinding)) nonBindingSharedRequestedQuantity := state.GetNonBindingSharedRequestedQuantityFromPodEntries(podEntries, nil, p.getContainerRequestedCores) reqAnnotations := req.Annotations numaNodes := p.filterNUMANodesByNonBindingSharedRequestedQuantity(nonBindingSharedRequestedQuantity, nonBindingNUMAsCPUQuantity, nonBindingNUMAs, machineState, - machineState.GetFilteredNUMASetWithAnnotations(state.CheckNUMABindingSharedCoresAntiAffinity, reqAnnotations).ToSliceInt()) + machineState.GetFilteredNUMASetWithAnnotations(state.WrapAllocationMetaFilterWithAnnotations(commonstate.CheckNUMABindingSharedCoresAntiAffinity), reqAnnotations).ToSliceInt()) hints := map[string]*pluginapi.ListOfTopologyHints{ string(v1.ResourceCPU): { diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go index 8d255e2f4..28a260c52 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/policy_test.go @@ -36,6 +36,7 @@ import ( utilfs "k8s.io/kubernetes/pkg/util/filesystem" "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/calculator" advisorapi "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor" @@ -66,6 +67,16 @@ type cpuTestCase struct { fakeNUMANum int } +func generateSharedNumaBindingPoolAllocationMeta(poolName string) commonstate.AllocationMeta { + meta := commonstate.GenerateGenericPoolAllocationMeta(poolName) + if meta.Annotations == nil { + meta.Annotations = make(map[string]string) + } + meta.Annotations[consts.PodAnnotationMemoryEnhancementNumaBinding] = consts.PodAnnotationMemoryEnhancementNumaBindingEnable + meta.QoSLevel = consts.PodAnnotationQoSLevelSharedCores + return meta +} + func getTestDynamicPolicyWithInitialization(topology *machine.CPUTopology, stateFileDirectory string) (*DynamicPolicy, error) { dynamicPolicy, err := getTestDynamicPolicyWithoutInitialization(topology, stateFileDirectory) if err != nil { @@ -161,7 +172,7 @@ func TestInitPoolAndCalculator(t *testing.T) { err = policyImpl.initReclaimPool() as.Nil(err) - reclaimPoolAllocationInfo := policyImpl.state.GetAllocationInfo(state.PoolNameReclaim, "") + reclaimPoolAllocationInfo := policyImpl.state.GetAllocationInfo(commonstate.PoolNameReclaim, "") as.NotNil(reclaimPoolAllocationInfo) @@ -1490,14 +1501,24 @@ func TestGetTopologyHints(t *testing.T) { podEntries: state.PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff812kkk": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.MustParse("1,8,9"), OriginalAllocationResult: machine.MustParse("1,8,9"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1506,27 +1527,30 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 8, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + RequestQuantity: 2, }, }, "373d08e4-7a6b-4293-aaaf-b135ff8123bf": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, + RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1537,26 +1561,28 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12), 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1567,26 +1593,28 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12), 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1601,20 +1629,12 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(13), 3: machine.NewCPUSet(15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - state.PoolNameReclaim: state.ContainerEntries{ + commonstate.PoolNameReclaim: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameReclaim, - OwnerPoolName: state.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1631,10 +1651,9 @@ func TestGetTopologyHints(t *testing.T) { }, }, }, - state.PoolNameShare: state.ContainerEntries{ + commonstate.PoolNameShare: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1649,8 +1668,7 @@ func TestGetTopologyHints(t *testing.T) { }, "share-NUMA1": state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: generateSharedNumaBindingPoolAllocationMeta("share-NUMA1"), AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1659,22 +1677,28 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, }, }, "373d08e4-7a6b-4293-aaaf-b135ff812aaa": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA1", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA1", AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1683,14 +1707,6 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 1, }, }, @@ -1755,14 +1771,24 @@ func TestGetTopologyHints(t *testing.T) { podEntries: state.PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff812kkk": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.MustParse("1,8,9"), OriginalAllocationResult: machine.MustParse("1,8,9"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1771,27 +1797,28 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 8, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, "373d08e4-7a6b-4293-aaaf-b135ff8123bf": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1802,26 +1829,28 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12), 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1832,26 +1861,28 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12), 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1866,20 +1897,12 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(13), 3: machine.NewCPUSet(15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - state.PoolNameReclaim: state.ContainerEntries{ + commonstate.PoolNameReclaim: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameReclaim, - OwnerPoolName: state.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1896,10 +1919,9 @@ func TestGetTopologyHints(t *testing.T) { }, }, }, - state.PoolNameShare: state.ContainerEntries{ + commonstate.PoolNameShare: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1914,8 +1936,7 @@ func TestGetTopologyHints(t *testing.T) { }, "share-NUMA1": state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: generateSharedNumaBindingPoolAllocationMeta("share-NUMA1"), AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1924,22 +1945,28 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, }, }, "373d08e4-7a6b-4293-aaaf-b135ff812aaa": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA1", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA1", AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1948,14 +1975,6 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 1, }, }, @@ -2020,14 +2039,24 @@ func TestGetTopologyHints(t *testing.T) { podEntries: state.PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff812kkk": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + OwnerPoolName: commonstate.PoolNameDedicated, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.MustParse("1,8,9"), OriginalAllocationResult: machine.MustParse("1,8,9"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2036,27 +2065,29 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 8, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, "373d08e4-7a6b-4293-aaaf-b135ff8123bf": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, + RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2067,26 +2098,28 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12), 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2097,26 +2130,28 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12), 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2131,20 +2166,12 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(13), 3: machine.NewCPUSet(15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - state.PoolNameReclaim: state.ContainerEntries{ + commonstate.PoolNameReclaim: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameReclaim, - OwnerPoolName: state.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2161,10 +2188,9 @@ func TestGetTopologyHints(t *testing.T) { }, }, }, - state.PoolNameShare: state.ContainerEntries{ + commonstate.PoolNameShare: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2179,8 +2205,7 @@ func TestGetTopologyHints(t *testing.T) { }, "share-NUMA1": state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: generateSharedNumaBindingPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2189,22 +2214,28 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, }, }, "373d08e4-7a6b-4293-aaaf-b135ff812aaa": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA1", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA1", AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2213,14 +2244,6 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, @@ -2285,14 +2308,24 @@ func TestGetTopologyHints(t *testing.T) { podEntries: state.PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff812kkk": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.MustParse("1,8,9"), OriginalAllocationResult: machine.MustParse("1,8,9"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2301,27 +2334,28 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 8, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2336,20 +2370,12 @@ func TestGetTopologyHints(t *testing.T) { 2: machine.NewCPUSet(13), 3: machine.NewCPUSet(15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - state.PoolNameReclaim: state.ContainerEntries{ + commonstate.PoolNameReclaim: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameReclaim, - OwnerPoolName: state.PoolNameReclaim, + AllocationMeta: generateSharedNumaBindingPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2368,8 +2394,7 @@ func TestGetTopologyHints(t *testing.T) { }, "share-NUMA2": state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: generateSharedNumaBindingPoolAllocationMeta("share-NUMA2"), AllocationResult: machine.MustParse("4,5,12"), OriginalAllocationResult: machine.MustParse("4,5,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2378,16 +2403,11 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 5, 12), }, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, }, }, "share-NUMA1": state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: generateSharedNumaBindingPoolAllocationMeta("share-NUMA1"), AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2396,16 +2416,11 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, }, }, "share-NUMA3": state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: generateSharedNumaBindingPoolAllocationMeta("share-NUMA3"), AllocationResult: machine.MustParse("6,7,14"), OriginalAllocationResult: machine.MustParse("6,7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2414,22 +2429,28 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14), }, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, }, }, "373d08e4-7a6b-4293-aaaf-b135ff812aaa": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA1", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA1", AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2438,27 +2459,29 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "373d08e4-7a6b-4293-aaaf-b135ff812iii": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812iii", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812iii", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA2", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA2", AllocationResult: machine.MustParse("4,5,12"), OriginalAllocationResult: machine.MustParse("4,5,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2467,27 +2490,29 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 5, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 3, }, }, "373d08e4-7a6b-4293-aaaf-b135ff812ooo": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812ooo", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812ooo", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA3", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA3", AllocationResult: machine.MustParse("6,7,14"), OriginalAllocationResult: machine.MustParse("6,7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2496,14 +2521,6 @@ func TestGetTopologyHints(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 3, }, }, @@ -2946,7 +2963,7 @@ func TestGetResourcesAllocation(t *testing.T) { resp1, err := dynamicPolicy.GetResourcesAllocation(context.Background(), &pluginapi.GetResourcesAllocationRequest{}) as.Nil(err) - reclaim := dynamicPolicy.state.GetAllocationInfo(state.PoolNameReclaim, state.FakedContainerName) + reclaim := dynamicPolicy.state.GetAllocationInfo(commonstate.PoolNameReclaim, commonstate.FakedContainerName) as.NotNil(reclaim) as.NotNil(resp1.PodResources[req.PodUid]) @@ -3042,9 +3059,8 @@ func TestGetResourcesAllocation(t *testing.T) { dynamicPolicy.state.SetAllowSharedCoresOverlapReclaimedCores(true) dynamicPolicy.dynamicConfig.GetDynamicConfiguration().EnableReclaim = true - dynamicPolicy.state.SetAllocationInfo(state.PoolNameReclaim, "", &state.AllocationInfo{ - PodUid: state.PoolNameReclaim, - OwnerPoolName: state.PoolNameReclaim, + dynamicPolicy.state.SetAllocationInfo(commonstate.PoolNameReclaim, "", &state.AllocationInfo{ + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("1,3,4-5"), OriginalAllocationResult: machine.MustParse("1,3,4-5"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3085,7 +3101,7 @@ func TestGetResourcesAllocation(t *testing.T) { AllocationResult: machine.NewCPUSet(1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).String(), }, resp3.PodResources[req.PodUid].ContainerResources[testName].ResourceAllocation[string(v1.ResourceCPU)]) - reclaimEntry := dynamicPolicy.state.GetAllocationInfo(state.PoolNameReclaim, "") + reclaimEntry := dynamicPolicy.state.GetAllocationInfo(commonstate.PoolNameReclaim, "") as.NotNil(reclaimEntry) as.Equal(6, reclaimEntry.AllocationResult.Size()) // ceil("14 * (4 / 10)") == 6 } @@ -3121,14 +3137,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { podEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3143,26 +3168,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3177,26 +3204,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.NewCPUSet(7, 8, 10, 15), OriginalAllocationResult: machine.NewCPUSet(7, 8, 10, 15), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3209,23 +3238,16 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 1: machine.NewCPUSet(10), 3: machine.NewCPUSet(7, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, }, lwResp: &advisorapi.ListAndWatchResponse{ Entries: map[string]*advisorapi.CalculationEntries{ - state.PoolNameShare: { + commonstate.PoolNameShare: { Entries: map[string]*advisorapi.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameShare, + OwnerPoolName: commonstate.PoolNameShare, CalculationResultsByNumas: map[int64]*advisorapi.NumaCalculationResult{ -1: { Blocks: []*advisorapi.Block{ @@ -3239,10 +3261,10 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { }, }, }, - state.PoolNameReserve: { + commonstate.PoolNameReserve: { Entries: map[string]*advisorapi.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReserve, + OwnerPoolName: commonstate.PoolNameReserve, CalculationResultsByNumas: map[int64]*advisorapi.NumaCalculationResult{ -1: { Blocks: []*advisorapi.Block{ @@ -3261,14 +3283,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { expectedPodEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3281,26 +3312,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3313,26 +3346,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3347,20 +3382,12 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 2: machine.NewCPUSet(5, 13), 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - state.PoolNameReclaim: state.ContainerEntries{ + commonstate.PoolNameReclaim: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameReclaim, - OwnerPoolName: state.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3377,10 +3404,9 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { }, }, }, - state.PoolNameShare: state.ContainerEntries{ + commonstate.PoolNameShare: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3395,10 +3421,9 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { }, }, }, - state.PoolNameReserve: state.ContainerEntries{ + commonstate.PoolNameReserve: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameReserve, - OwnerPoolName: state.PoolNameReserve, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReserve), AllocationResult: machine.MustParse("0,2"), OriginalAllocationResult: machine.MustParse("0,2"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3419,14 +3444,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { PodEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3435,26 +3469,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3463,26 +3499,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("8"), OriginalAllocationResult: machine.MustParse("8"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3491,13 +3529,6 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(8), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -3509,14 +3540,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { PodEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3525,26 +3565,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3553,26 +3595,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("10"), OriginalAllocationResult: machine.MustParse("10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3581,13 +3625,6 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -3599,14 +3636,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { PodEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3615,26 +3661,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3643,26 +3691,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("5,13"), OriginalAllocationResult: machine.MustParse("5,13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3671,13 +3721,6 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(5, 13), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -3689,14 +3732,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { PodEntries: state.PodEntries{ pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("6,7,14,15"), OriginalAllocationResult: machine.MustParse("6,7,14,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3705,13 +3757,6 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -3725,14 +3770,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { podEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,6-7"), OriginalAllocationResult: machine.MustParse("4-5,6-7"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3743,26 +3797,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 2: machine.NewCPUSet(4, 5), 3: machine.NewCPUSet(6, 7), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,6-7"), OriginalAllocationResult: machine.MustParse("4-5,6-7"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3773,26 +3829,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 2: machine.NewCPUSet(4, 5), 3: machine.NewCPUSet(6, 7), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.NewCPUSet(12, 13, 14, 15), OriginalAllocationResult: machine.NewCPUSet(12, 13, 14, 15), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3803,26 +3861,29 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 2: machine.NewCPUSet(12, 13), 3: machine.NewCPUSet(14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, pod4UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod4UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod4UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.NewCPUSet(1, 3, 8, 9, 10, 11), OriginalAllocationResult: machine.NewCPUSet(1, 3, 8, 9, 10, 11), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3833,24 +3894,16 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 0: machine.NewCPUSet(1, 8, 9), 1: machine.NewCPUSet(3, 10, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, }, lwResp: &advisorapi.ListAndWatchResponse{ Entries: map[string]*advisorapi.CalculationEntries{ - state.PoolNameShare: { + commonstate.PoolNameShare: { Entries: map[string]*advisorapi.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameShare, + OwnerPoolName: commonstate.PoolNameShare, CalculationResultsByNumas: map[int64]*advisorapi.NumaCalculationResult{ -1: { Blocks: []*advisorapi.Block{ @@ -3864,10 +3917,10 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { }, }, }, - state.PoolNameReserve: { + commonstate.PoolNameReserve: { Entries: map[string]*advisorapi.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReserve, + OwnerPoolName: commonstate.PoolNameReserve, CalculationResultsByNumas: map[int64]*advisorapi.NumaCalculationResult{ -1: { Blocks: []*advisorapi.Block{ @@ -3881,10 +3934,10 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { }, }, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { Entries: map[string]*advisorapi.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, CalculationResultsByNumas: map[int64]*advisorapi.NumaCalculationResult{ 0: { Blocks: []*advisorapi.Block{ @@ -3917,7 +3970,7 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { pod4UID: { Entries: map[string]*advisorapi.CalculationInfo{ testName: { - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, CalculationResultsByNumas: map[int64]*advisorapi.NumaCalculationResult{ 0: { Blocks: []*advisorapi.Block{ @@ -3952,14 +4005,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { expectedPodEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4,5,6,7,12,13"), OriginalAllocationResult: machine.MustParse("4,5,6,7,12,13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3970,26 +4032,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12, 13), 3: machine.NewCPUSet(6, 7), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4,5,6,7,12,13"), OriginalAllocationResult: machine.MustParse("4,5,6,7,12,13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4000,26 +4064,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12, 13), 3: machine.NewCPUSet(6, 7), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("1,3,14-15"), OriginalAllocationResult: machine.MustParse("1,3,14-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4032,26 +4098,29 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 1: machine.NewCPUSet(3), 3: machine.NewCPUSet(14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, pod4UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod4UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod4UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementKey: `{"numa_binding": "true"}`, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.NewCPUSet(1, 3, 8, 9, 10, 11), OriginalAllocationResult: machine.NewCPUSet(1, 3, 8, 9, 10, 11), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4062,21 +4131,12 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { 0: machine.NewCPUSet(1, 8, 9), 1: machine.NewCPUSet(3, 10, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementKey: `{"numa_binding": "true"}`, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, - state.PoolNameReclaim: state.ContainerEntries{ + commonstate.PoolNameReclaim: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameReclaim, - OwnerPoolName: state.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("1,3,14-15"), OriginalAllocationResult: machine.MustParse("1,3,14-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4091,10 +4151,9 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { }, }, }, - state.PoolNameShare: state.ContainerEntries{ + commonstate.PoolNameShare: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("4,5,6,7,12,13"), OriginalAllocationResult: machine.MustParse("4,5,6,7,12,13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4107,10 +4166,9 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { }, }, }, - state.PoolNameReserve: state.ContainerEntries{ + commonstate.PoolNameReserve: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameReserve, - OwnerPoolName: state.PoolNameReserve, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReserve), AllocationResult: machine.MustParse("0,2"), OriginalAllocationResult: machine.MustParse("0,2"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4131,14 +4189,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { PodEntries: state.PodEntries{ pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("1"), OriginalAllocationResult: machine.MustParse("1"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4147,26 +4214,29 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, pod4UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod4UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod4UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.NewCPUSet(1, 8, 9), OriginalAllocationResult: machine.NewCPUSet(1, 8, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4175,14 +4245,6 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 8, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, @@ -4194,14 +4256,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { PodEntries: state.PodEntries{ pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("3"), OriginalAllocationResult: machine.MustParse("3"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4210,26 +4281,29 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(3), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, pod4UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod4UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod4UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.NewCPUSet(3, 10, 11), OriginalAllocationResult: machine.NewCPUSet(3, 10, 11), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4238,14 +4312,6 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, @@ -4257,14 +4323,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { PodEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12-13"), OriginalAllocationResult: machine.MustParse("4-5,12-13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4273,26 +4348,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 5, 12, 13), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12-13"), OriginalAllocationResult: machine.MustParse("4-5,12-13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4301,26 +4378,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 5, 12, 13), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, //pod3UID: state.ContainerEntries{ // testName: &state.AllocationInfo{ - // PodUid: pod3UID, - // PodNamespace: testName, - // PodName: testName, - // ContainerName: testName, - // ContainerType: pluginapi.ContainerType_MAIN.String(), - // ContainerIndex: 0, + // AllocationMeta: commonstate.AllocationMeta{ + // PodUid: pod3UID, + // PodNamespace: testName, + // PodName: testName, + // ContainerName: testName, + // ContainerType: pluginapi.ContainerType_MAIN.String(), + // ContainerIndex: 0, + // OwnerPoolName: commonstate.PoolNameReclaim, + // Labels: map[string]string{ + // consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + // }, + // Annotations: map[string]string{ + // consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + // }, + // QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + // }, // RampUp: false, - // OwnerPoolName: state.PoolNameReclaim, // AllocationResult: machine.MustParse("5,13"), // OriginalAllocationResult: machine.MustParse("5,13"), // TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4329,13 +4408,6 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { // OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ // 2: machine.NewCPUSet(5, 13), // }, - // Labels: map[string]string{ - // consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - // }, - // Annotations: map[string]string{ - // consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - // }, - // QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, // RequestQuantity: 2, // }, //}, @@ -4347,14 +4419,23 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { PodEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("6,7"), OriginalAllocationResult: machine.MustParse("6,7"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4363,26 +4444,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("6,7"), OriginalAllocationResult: machine.MustParse("6,7"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4391,26 +4474,28 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("14,15"), OriginalAllocationResult: machine.MustParse("14,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4419,13 +4504,6 @@ func TestAllocateByQoSAwareServerListAndWatchResp(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -4671,14 +4749,23 @@ func TestRemoveContainer(t *testing.T) { podEntries := state.PodEntries{ podUID: state.ContainerEntries{ containerName: &state.AllocationInfo{ - PodUid: podUID, - PodNamespace: testName, - PodName: testName, - ContainerName: containerName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: podUID, + PodNamespace: testName, + PodName: testName, + ContainerName: containerName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4693,13 +4780,6 @@ func TestRemoveContainer(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, @@ -4736,9 +4816,8 @@ func TestShoudSharedCoresRampUp(t *testing.T) { dynamicPolicy, err := getTestDynamicPolicyWithInitialization(cpuTopology, tmpDir) as.Nil(err) - dynamicPolicy.state.SetAllocationInfo(state.PoolNameShare, "", &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + dynamicPolicy.state.SetAllocationInfo(commonstate.PoolNameShare, "", &state.AllocationInfo{ + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4758,14 +4837,23 @@ func TestShoudSharedCoresRampUp(t *testing.T) { existPodUID := uuid.NewUUID() existName := "exist" dynamicPolicy.state.SetAllocationInfo(string(existPodUID), existName, &state.AllocationInfo{ - PodUid: string(existPodUID), - PodNamespace: existName, - PodName: existName, - ContainerName: existName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: string(existPodUID), + PodNamespace: existName, + PodName: existName, + ContainerName: existName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("1,3-6,9,11-14"), OriginalAllocationResult: machine.MustParse("1,3-6,9,11-14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -4780,13 +4868,6 @@ func TestShoudSharedCoresRampUp(t *testing.T) { 2: machine.NewCPUSet(4, 5, 11, 12), 3: machine.NewCPUSet(6, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }) @@ -4832,7 +4913,7 @@ func TestShoudSharedCoresRampUp(t *testing.T) { allocationInfo := dynamicPolicy.state.GetAllocationInfo(req.PodUid, testName) as.NotNil(allocationInfo) as.Equal(false, allocationInfo.RampUp) - as.Equal(allocationInfo.OwnerPoolName, state.PoolNameShare) + as.Equal(allocationInfo.OwnerPoolName, commonstate.PoolNameShare) } func BenchmarkGetTopologyHints(b *testing.B) { @@ -5037,14 +5118,24 @@ func Test_getNUMAAllocatedMemBW(t *testing.T) { podEntries := state.PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff812kkk": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812kkk", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.MustParse("1,8,9"), OriginalAllocationResult: machine.MustParse("1,8,9"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -5053,27 +5144,28 @@ func Test_getNUMAAllocatedMemBW(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 8, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, }, "373d08e4-7a6b-4293-aaaf-b135ff8123bf": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -5084,26 +5176,28 @@ func Test_getNUMAAllocatedMemBW(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12), 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameShare, AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -5114,26 +5208,28 @@ func Test_getNUMAAllocatedMemBW(t *testing.T) { 2: machine.NewCPUSet(4, 5, 12), 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameReclaim, AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -5148,20 +5244,12 @@ func Test_getNUMAAllocatedMemBW(t *testing.T) { 2: machine.NewCPUSet(13), 3: machine.NewCPUSet(15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - state.PoolNameReclaim: state.ContainerEntries{ + commonstate.PoolNameReclaim: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameReclaim, - OwnerPoolName: state.PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("9,11,13,15"), OriginalAllocationResult: machine.MustParse("9,11,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -5178,10 +5266,9 @@ func Test_getNUMAAllocatedMemBW(t *testing.T) { }, }, }, - state.PoolNameShare: state.ContainerEntries{ + commonstate.PoolNameShare: state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("4-5,12,6-7,14"), OriginalAllocationResult: machine.MustParse("4-5,12,6-7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -5196,8 +5283,7 @@ func Test_getNUMAAllocatedMemBW(t *testing.T) { }, "share-NUMA1": state.ContainerEntries{ "": &state.AllocationInfo{ - PodUid: state.PoolNameShare, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: generateSharedNumaBindingPoolAllocationMeta("share-NUMA1"), AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -5206,22 +5292,28 @@ func Test_getNUMAAllocatedMemBW(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, }, }, "373d08e4-7a6b-4293-aaaf-b135ff812aaa": state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA1", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA1", AllocationResult: machine.MustParse("3,10"), OriginalAllocationResult: machine.MustParse("3,10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -5230,14 +5322,6 @@ func Test_getNUMAAllocatedMemBW(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 1, }, }, diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state.go index 28ee7e5fa..2ae01ae58 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state.go @@ -24,11 +24,9 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" - pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" - "github.com/kubewharf/katalyst-api/pkg/consts" apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" - cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/util/general" "github.com/kubewharf/katalyst-core/pkg/util/machine" ) @@ -40,16 +38,10 @@ import ( // 3. not use omitempty in map property and must make new map to do initialization type AllocationInfo struct { - PodUid string `json:"pod_uid,omitempty"` - PodNamespace string `json:"pod_namespace,omitempty"` - PodName string `json:"pod_name,omitempty"` - ContainerName string `json:"container_name,omitempty"` - ContainerType string `json:"container_type,omitempty"` - ContainerIndex uint64 `json:"container_index,omitempty"` - RampUp bool `json:"ramp_up,omitempty"` - OwnerPoolName string `json:"owner_pool_name,omitempty"` - PodRole string `json:"pod_role,omitempty"` - PodType string `json:"pod_type,omitempty"` + commonstate.AllocationMeta `json:",inline"` + + RampUp bool `json:"ramp_up,omitempty"` + AllocationResult machine.CPUSet `json:"allocation_result,omitempty"` OriginalAllocationResult machine.CPUSet `json:"original_allocation_result,omitempty"` @@ -60,10 +52,7 @@ type AllocationInfo struct { // for ramp up calculation. notice we don't use time.Time type here to avid checksum corruption. InitTimestamp string `json:"init_timestamp"` - Labels map[string]string `json:"labels"` - Annotations map[string]string `json:"annotations"` - QoSLevel string `json:"qosLevel"` - RequestQuantity float64 `json:"request_quantity,omitempty"` + RequestQuantity float64 `json:"request_quantity,omitempty"` } type ( @@ -88,22 +77,11 @@ func (ai *AllocationInfo) Clone() *AllocationInfo { } clone := &AllocationInfo{ - PodUid: ai.PodUid, - PodNamespace: ai.PodNamespace, - PodName: ai.PodName, - ContainerName: ai.ContainerName, - ContainerType: ai.ContainerType, - ContainerIndex: ai.ContainerIndex, + AllocationMeta: *ai.AllocationMeta.Clone(), RampUp: ai.RampUp, - OwnerPoolName: ai.OwnerPoolName, - PodRole: ai.PodRole, - PodType: ai.PodType, AllocationResult: ai.AllocationResult.Clone(), OriginalAllocationResult: ai.OriginalAllocationResult.Clone(), InitTimestamp: ai.InitTimestamp, - QoSLevel: ai.QoSLevel, - Labels: general.DeepCopyMap(ai.Labels), - Annotations: general.DeepCopyMap(ai.Annotations), RequestQuantity: ai.RequestQuantity, } @@ -139,90 +117,6 @@ func (ai *AllocationInfo) String() string { return string(contentBytes) } -// GetPoolName parses the owner pool name for AllocationInfo -// if owner exists, just return; otherwise, parse from qos-level -func (ai *AllocationInfo) GetPoolName() string { - if ai == nil { - return EmptyOwnerPoolName - } - - if ownerPoolName := ai.GetOwnerPoolName(); ownerPoolName != EmptyOwnerPoolName { - return ownerPoolName - } - return ai.GetSpecifiedPoolName() -} - -// GetOwnerPoolName parses the owner pool name for AllocationInfo -func (ai *AllocationInfo) GetOwnerPoolName() string { - if ai == nil { - return EmptyOwnerPoolName - } - return ai.OwnerPoolName -} - -// GetSpecifiedPoolName parses the owner pool name for AllocationInfo from qos-level -func (ai *AllocationInfo) GetSpecifiedPoolName() string { - if ai == nil { - return EmptyOwnerPoolName - } - - return GetSpecifiedPoolName(ai.QoSLevel, ai.Annotations[consts.PodAnnotationCPUEnhancementCPUSet]) -} - -// GetSpecifiedNUMABindingPoolName get numa_binding pool name -// for numa_binding shared_cores according to enhancements and NUMA hint -func (ai *AllocationInfo) GetSpecifiedNUMABindingPoolName() (string, error) { - if !CheckSharedNUMABinding(ai) { - return EmptyOwnerPoolName, fmt.Errorf("GetSpecifiedNUMABindingPoolName only for numa_binding shared_cores") - } - - numaSet, pErr := machine.Parse(ai.Annotations[cpuconsts.CPUStateAnnotationKeyNUMAHint]) - if pErr != nil { - return EmptyOwnerPoolName, fmt.Errorf("parse numaHintStr: %s failed with error: %v", - ai.Annotations[cpuconsts.CPUStateAnnotationKeyNUMAHint], pErr) - } else if numaSet.Size() != 1 { - return EmptyOwnerPoolName, fmt.Errorf("parse numaHintStr: %s with invalid size", numaSet.String()) - } - - specifiedPoolName := ai.GetSpecifiedPoolName() - - if specifiedPoolName == EmptyOwnerPoolName { - return EmptyOwnerPoolName, fmt.Errorf("empty specifiedPoolName") - } - - return GetNUMAPoolName(specifiedPoolName, numaSet.ToSliceNoSortUInt64()[0]), nil -} - -func (ai *AllocationInfo) GetSpecifiedSystemPoolName() (string, error) { - if !CheckSystem(ai) { - return EmptyOwnerPoolName, fmt.Errorf("GetSpecifiedSystemPoolName only for system_cores") - } - - specifiedPoolName := ai.GetSpecifiedPoolName() - if specifiedPoolName == EmptyOwnerPoolName { - return PoolNamePrefixSystem, nil - } - - return fmt.Sprintf("%s%s%s", PoolNamePrefixSystem, "-", specifiedPoolName), nil -} - -func CheckSystem(ai *AllocationInfo) bool { - if ai == nil { - return false - } - - return ai.QoSLevel == consts.PodAnnotationQoSLevelSystemCores -} - -// CheckMainContainer returns true if the AllocationInfo is for main container -func (ai *AllocationInfo) CheckMainContainer() bool { - if ai == nil { - return false - } - - return ai.ContainerType == pluginapi.ContainerType_MAIN.String() -} - // GetAllocationResultNUMASet returns numaSet parsed from TopologyAwareAssignments func (ai *AllocationInfo) GetAllocationResultNUMASet() machine.CPUSet { if ai == nil { @@ -244,17 +138,9 @@ func (ai *AllocationInfo) GetAllocationResultNUMASet() machine.CPUSet { return numaSet } -// CheckSideCar returns true if the AllocationInfo is for side-car container -func (ai *AllocationInfo) CheckSideCar() bool { - if ai == nil { - return false - } - - return ai.ContainerType == pluginapi.ContainerType_SIDECAR.String() -} - func (ai *AllocationInfo) GetPodAggregatedRequest() (float64, bool) { - if ai.Annotations == nil { + if ai == nil || + ai.Annotations == nil { return 0, false } value, ok := ai.Annotations[apiconsts.PodAnnotationAggregatedRequestsKey] @@ -270,120 +156,17 @@ func (ai *AllocationInfo) GetPodAggregatedRequest() (float64, bool) { return float64(resourceList.Cpu().MilliValue()) / 1000, true } -// CheckDedicated returns true if the AllocationInfo is for pod with dedicated-qos -func CheckDedicated(ai *AllocationInfo) bool { - if ai == nil { - return false - } - - return ai.QoSLevel == consts.PodAnnotationQoSLevelDedicatedCores -} - -// CheckShared returns true if the AllocationInfo is for pod with shared-qos -func CheckShared(ai *AllocationInfo) bool { - if ai == nil { - return false - } - - return ai.QoSLevel == consts.PodAnnotationQoSLevelSharedCores -} - -// CheckReclaimed returns true if the AllocationInfo is for pod with reclaimed-qos -func CheckReclaimed(ai *AllocationInfo) bool { - if ai == nil { - return false - } - - return ai.QoSLevel == consts.PodAnnotationQoSLevelReclaimedCores -} - -// CheckNUMABinding returns true if the AllocationInfo is for pod with numa-binding enhancement -func CheckNUMABinding(ai *AllocationInfo) bool { - if ai == nil { - return false - } - - return ai.Annotations[consts.PodAnnotationMemoryEnhancementNumaBinding] == consts.PodAnnotationMemoryEnhancementNumaBindingEnable -} - -// CheckDedicatedNUMABinding returns true if the AllocationInfo is for pod with -// dedicated-qos and numa-binding enhancement -func CheckDedicatedNUMABinding(ai *AllocationInfo) bool { - if ai == nil { - return false - } - - return CheckDedicated(ai) && CheckNUMABinding(ai) -} - -// CheckSharedNUMABinding returns true if the AllocationInfo is for pod with -// shared-qos and numa-binding enhancement -func CheckSharedNUMABinding(ai *AllocationInfo) bool { - if ai == nil { - return false - } - - return CheckShared(ai) && CheckNUMABinding(ai) -} - -// CheckSharedOrDedicatedNUMABinding returns true if the AllocationInfo is for pod with -// shared-qos or dedicated-qos and numa-binding enhancement -func CheckSharedOrDedicatedNUMABinding(ai *AllocationInfo) bool { - if ai == nil { - return false - } - - return CheckSharedNUMABinding(ai) || CheckDedicatedNUMABinding(ai) -} - -// CheckDedicatedPool returns true if the AllocationInfo is for a container in the dedicated pool -func CheckDedicatedPool(ai *AllocationInfo) bool { - if ai == nil { - return false - } - - return ai.OwnerPoolName == PoolNameDedicated -} - -// CheckNUMABindingSharedCoresAntiAffinity returns true -// if the AllocationInfo isn't compatible for the annotations of a numa binding shared cores candidate -func CheckNUMABindingSharedCoresAntiAffinity(ai *AllocationInfo, annotations map[string]string) bool { - if ai == nil { - return false - } else if len(annotations) == 0 { - return false - } - - if CheckDedicatedNUMABinding(ai) { - return true - } - - if CheckSharedNUMABinding(ai) { - // considering isolation, use specified pool instead of actual pool name here - candidateSpecifiedPoolName := GetSpecifiedPoolName(apiconsts.PodAnnotationQoSLevelSharedCores, - annotations[apiconsts.PodAnnotationCPUEnhancementCPUSet]) - aiSpecifiedPoolName := ai.GetSpecifiedPoolName() - - // shared_cores with numa binding doesn't support two share type pools with same specified name existing at same NUMA - if candidateSpecifiedPoolName != aiSpecifiedPoolName { - return true - } - } - - return false -} - // IsPoolEntry returns true if this entry is for a pool; // otherwise, this entry is for a container entity. func (ce ContainerEntries) IsPoolEntry() bool { - return len(ce) == 1 && ce[FakedContainerName] != nil + return len(ce) == 1 && ce[commonstate.FakedContainerName] != nil } func (ce ContainerEntries) GetPoolEntry() *AllocationInfo { if !ce.IsPoolEntry() { return nil } - return ce[FakedContainerName] + return ce[commonstate.FakedContainerName] } // GetMainContainerEntry returns the main container entry in pod container entries @@ -439,8 +222,8 @@ func (pe PodEntries) String() string { // CheckPoolEmpty returns true if the given pool doesn't exist func (pe PodEntries) CheckPoolEmpty(poolName string) bool { - return pe[poolName][FakedContainerName] == nil || - pe[poolName][FakedContainerName].AllocationResult.IsEmpty() + return pe[poolName][commonstate.FakedContainerName] == nil || + pe[poolName][commonstate.FakedContainerName].AllocationResult.IsEmpty() } // GetCPUSetForPool returns cpuset that belongs to the given pool @@ -452,7 +235,7 @@ func (pe PodEntries) GetCPUSetForPool(poolName string) (machine.CPUSet, error) { if !pe[poolName].IsPoolEntry() { return machine.NewCPUSet(), fmt.Errorf("pool not found") } - return pe[poolName][FakedContainerName].AllocationResult.Clone(), nil + return pe[poolName][commonstate.FakedContainerName].AllocationResult.Clone(), nil } // GetFilteredPoolsCPUSet returns a mapping of pools for all of them (except for those skipped ones) @@ -486,7 +269,7 @@ func (pe PodEntries) GetFilteredPoolsCPUSetMap(ignorePools sets.String) (map[str // pool entry containing SharedNUMABinding containers also has SharedNUMABinding declarations, // it's also applicable to isolation pools for SharedNUMABinding containers. // it helps us to differentiate them from normal share pools when getting targetNUMAID for the pool. - if CheckSharedNUMABinding(allocationInfo) { + if allocationInfo.CheckSharedNUMABinding() { // pool for numa_binding shared_cores containers numaSet := allocationInfo.GetAllocationResultNUMASet() @@ -511,7 +294,7 @@ func (pe PodEntries) GetFilteredPoolsCPUSetMap(ignorePools sets.String) (map[str } else { // pool for shared_cores without numa_binding containers ret[poolName] = make(map[int]machine.CPUSet) - ret[poolName][FakedNUMAID] = cset + ret[poolName][commonstate.FakedNUMAID] = cset } } } @@ -577,7 +360,7 @@ func (ns *NUMANodeState) GetAvailableCPUQuantity(reservedCPUs machine.CPUSet) in // if there is pod aggregated resource key in main container annotations, use pod aggregated resource instead. mainContainerEntry := containerEntries.GetMainContainerEntry() - if mainContainerEntry == nil || !CheckSharedNUMABinding(mainContainerEntry) { + if mainContainerEntry == nil || !mainContainerEntry.CheckSharedNUMABinding() { continue } @@ -589,8 +372,7 @@ func (ns *NUMANodeState) GetAvailableCPUQuantity(reservedCPUs machine.CPUSet) in // calc pod aggregated resource request by container entries. for _, allocationInfo := range containerEntries { - if allocationInfo == nil || - !CheckSharedNUMABinding(allocationInfo) { + if allocationInfo == nil || !allocationInfo.CheckSharedNUMABinding() { continue } @@ -635,7 +417,7 @@ func (ns *NUMANodeState) ExistMatchedAllocationInfo(f func(ai *AllocationInfo) b return false } -// ExistMatchedAllocationInfo returns true if the stated predicate (with annotations of candidate) +// ExistMatchedAllocationInfoWithAnnotations returns true if the stated predicate (with annotations of candidate) // holds true for some pods of this numa else it returns false. func (ns *NUMANodeState) ExistMatchedAllocationInfoWithAnnotations( f func(ai *AllocationInfo, annotations map[string]string) bool, diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go index 95acb90ce..949409b11 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go @@ -24,16 +24,16 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/util/sets" pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" "k8s.io/kubernetes/pkg/kubelet/checkpointmanager" testutil "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state/testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/kubewharf/katalyst-api/pkg/consts" apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" "github.com/kubewharf/katalyst-core/pkg/util/machine" ) @@ -56,6 +56,17 @@ func assertStateEqual(t *testing.T, restoredState, expectedState State) { as.Equalf(expectedPodEntries, restoredPodEntries, "podEntries mismatch") } +// generateSharedNumaBindingPoolAllocationMeta generates a generic allocation metadata for a pool. +func generateSharedNumaBindingPoolAllocationMeta(poolName string) commonstate.AllocationMeta { + meta := commonstate.GenerateGenericPoolAllocationMeta(poolName) + if meta.Annotations == nil { + meta.Annotations = make(map[string]string) + } + meta.Annotations[consts.PodAnnotationMemoryEnhancementNumaBinding] = consts.PodAnnotationMemoryEnhancementNumaBindingEnable + meta.QoSLevel = consts.PodAnnotationQoSLevelSharedCores + return meta +} + func TestNewCheckpointState(t *testing.T) { t.Parallel() @@ -522,21 +533,30 @@ func TestNewCheckpointState(t *testing.T) { } } }, - "checksum": 1563971849 + "checksum": 4030123680 }`, "", &cpuPluginState{ podEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -549,26 +569,28 @@ func TestNewCheckpointState(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -581,26 +603,28 @@ func TestNewCheckpointState(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -615,20 +639,12 @@ func TestNewCheckpointState(t *testing.T) { 2: machine.NewCPUSet(5, 13), 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - PoolNameReclaim: ContainerEntries{ + commonstate.PoolNameReclaim: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameReclaim, - OwnerPoolName: PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -645,10 +661,9 @@ func TestNewCheckpointState(t *testing.T) { }, }, }, - PoolNameShare: ContainerEntries{ + commonstate.PoolNameShare: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameShare, - OwnerPoolName: PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -671,14 +686,23 @@ func TestNewCheckpointState(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -687,26 +711,28 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -715,26 +741,28 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("8"), OriginalAllocationResult: machine.MustParse("8"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -743,13 +771,6 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(8), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -761,14 +782,23 @@ func TestNewCheckpointState(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -777,26 +807,28 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -805,26 +837,28 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("10"), OriginalAllocationResult: machine.MustParse("10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -833,13 +867,6 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -851,14 +878,23 @@ func TestNewCheckpointState(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -867,26 +903,28 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -895,26 +933,28 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("5,13"), OriginalAllocationResult: machine.MustParse("5,13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -923,13 +963,6 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(5, 13), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -941,14 +974,23 @@ func TestNewCheckpointState(t *testing.T) { PodEntries: PodEntries{ "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("6,7,14,15"), OriginalAllocationResult: machine.MustParse("6,7,14,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -957,13 +999,6 @@ func TestNewCheckpointState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -1489,14 +1524,23 @@ func TestClearState(t *testing.T) { podEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1509,26 +1553,28 @@ func TestClearState(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1541,26 +1587,28 @@ func TestClearState(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1575,20 +1623,12 @@ func TestClearState(t *testing.T) { 2: machine.NewCPUSet(5, 13), 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - PoolNameReclaim: ContainerEntries{ + commonstate.PoolNameReclaim: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameReclaim, - OwnerPoolName: PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1605,10 +1645,9 @@ func TestClearState(t *testing.T) { }, }, }, - PoolNameShare: ContainerEntries{ + commonstate.PoolNameShare: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameShare, - OwnerPoolName: PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1631,14 +1670,23 @@ func TestClearState(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1647,26 +1695,28 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1675,26 +1725,28 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("8"), OriginalAllocationResult: machine.MustParse("8"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1703,13 +1755,6 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(8), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -1721,14 +1766,23 @@ func TestClearState(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1737,26 +1791,29 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, + RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1765,26 +1822,28 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("10"), OriginalAllocationResult: machine.MustParse("10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1793,13 +1852,6 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -1811,14 +1863,23 @@ func TestClearState(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1827,26 +1888,28 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1855,26 +1918,28 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("5,13"), OriginalAllocationResult: machine.MustParse("5,13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1883,13 +1948,6 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(5, 13), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -1901,14 +1959,23 @@ func TestClearState(t *testing.T) { PodEntries: PodEntries{ "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("6,7,14,15"), OriginalAllocationResult: machine.MustParse("6,7,14,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -1917,13 +1984,6 @@ func TestClearState(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -1982,14 +2042,23 @@ func TestCheckpointStateHelpers(t *testing.T) { podEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2002,26 +2071,28 @@ func TestCheckpointStateHelpers(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2034,26 +2105,28 @@ func TestCheckpointStateHelpers(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2068,20 +2141,12 @@ func TestCheckpointStateHelpers(t *testing.T) { 2: machine.NewCPUSet(5, 13), 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - PoolNameReclaim: ContainerEntries{ + commonstate.PoolNameReclaim: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameReclaim, - OwnerPoolName: PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2098,10 +2163,9 @@ func TestCheckpointStateHelpers(t *testing.T) { }, }, }, - PoolNameShare: ContainerEntries{ + commonstate.PoolNameShare: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameShare, - OwnerPoolName: PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2124,14 +2188,23 @@ func TestCheckpointStateHelpers(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2140,26 +2213,28 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2168,26 +2243,28 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("8"), OriginalAllocationResult: machine.MustParse("8"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2196,13 +2273,6 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(8), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -2214,14 +2284,23 @@ func TestCheckpointStateHelpers(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2230,26 +2309,28 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2258,26 +2339,28 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("10"), OriginalAllocationResult: machine.MustParse("10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2286,13 +2369,6 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -2304,14 +2380,23 @@ func TestCheckpointStateHelpers(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2320,26 +2405,28 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2348,26 +2435,28 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("5,13"), OriginalAllocationResult: machine.MustParse("5,13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2376,13 +2465,6 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(5, 13), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -2394,14 +2476,23 @@ func TestCheckpointStateHelpers(t *testing.T) { PodEntries: PodEntries{ "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("6,7,14,15"), OriginalAllocationResult: machine.MustParse("6,7,14,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2410,13 +2501,6 @@ func TestCheckpointStateHelpers(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -2585,7 +2669,7 @@ func TestAllocationInfo_GetSpecifiedNUMABindingPoolName(t *testing.T) { ContainerType: pluginapi.ContainerType_MAIN.String(), ContainerIndex: 0, RampUp: false, - OwnerPoolName: PoolNameShare, + OwnerPoolName: commonstate.PoolNameShare, AllocationResult: machine.MustParse("1"), OriginalAllocationResult: machine.MustParse("1"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2618,7 +2702,7 @@ func TestAllocationInfo_GetSpecifiedNUMABindingPoolName(t *testing.T) { ContainerType: pluginapi.ContainerType_MAIN.String(), ContainerIndex: 0, RampUp: false, - OwnerPoolName: PoolNameShare, + OwnerPoolName: commonstate.PoolNameShare, AllocationResult: machine.MustParse("1"), OriginalAllocationResult: machine.MustParse("1"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2650,7 +2734,7 @@ func TestAllocationInfo_GetSpecifiedNUMABindingPoolName(t *testing.T) { ContainerType: pluginapi.ContainerType_MAIN.String(), ContainerIndex: 0, RampUp: false, - OwnerPoolName: PoolNameShare, + OwnerPoolName: commonstate.PoolNameShare, AllocationResult: machine.MustParse("1"), OriginalAllocationResult: machine.MustParse("1"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2682,7 +2766,7 @@ func TestAllocationInfo_GetSpecifiedNUMABindingPoolName(t *testing.T) { ContainerType: pluginapi.ContainerType_MAIN.String(), ContainerIndex: 0, RampUp: false, - OwnerPoolName: PoolNameShare, + OwnerPoolName: commonstate.PoolNameShare, AllocationResult: machine.MustParse("1"), OriginalAllocationResult: machine.MustParse("1"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2711,24 +2795,26 @@ func TestAllocationInfo_GetSpecifiedNUMABindingPoolName(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() ai := &AllocationInfo{ - PodUid: tt.fields.PodUid, - PodNamespace: tt.fields.PodNamespace, - PodName: tt.fields.PodName, - ContainerName: tt.fields.ContainerName, - ContainerType: tt.fields.ContainerType, - ContainerIndex: tt.fields.ContainerIndex, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: tt.fields.PodUid, + PodNamespace: tt.fields.PodNamespace, + PodName: tt.fields.PodName, + ContainerName: tt.fields.ContainerName, + ContainerType: tt.fields.ContainerType, + ContainerIndex: tt.fields.ContainerIndex, + OwnerPoolName: tt.fields.OwnerPoolName, + PodRole: tt.fields.PodRole, + PodType: tt.fields.PodType, + Labels: tt.fields.Labels, + Annotations: tt.fields.Annotations, + QoSLevel: tt.fields.QoSLevel, + }, RampUp: tt.fields.RampUp, - OwnerPoolName: tt.fields.OwnerPoolName, - PodRole: tt.fields.PodRole, - PodType: tt.fields.PodType, AllocationResult: tt.fields.AllocationResult, OriginalAllocationResult: tt.fields.OriginalAllocationResult, TopologyAwareAssignments: tt.fields.TopologyAwareAssignments, OriginalTopologyAwareAssignments: tt.fields.OriginalTopologyAwareAssignments, InitTimestamp: tt.fields.InitTimestamp, - Labels: tt.fields.Labels, - Annotations: tt.fields.Annotations, - QoSLevel: tt.fields.QoSLevel, RequestQuantity: tt.fields.RequestQuantity, } got, err := ai.GetSpecifiedNUMABindingPoolName() @@ -2743,145 +2829,6 @@ func TestAllocationInfo_GetSpecifiedNUMABindingPoolName(t *testing.T) { } } -func TestCheckNUMABindingSharedCoresAntiAffinity(t *testing.T) { - t.Parallel() - testName := "test" - type args struct { - ai *AllocationInfo - annotations map[string]string - } - tests := []struct { - name string - args args - want bool - }{ - { - name: "anti affinity with dedicated numa_binding pods", - args: args{ - ai: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - RampUp: false, - OwnerPoolName: PoolNameShare, - AllocationResult: machine.MustParse("1"), - OriginalAllocationResult: machine.MustParse("1"), - TopologyAwareAssignments: map[int]machine.CPUSet{ - 0: machine.NewCPUSet(1), - }, - OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ - 0: machine.NewCPUSet(1), - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RequestQuantity: 2, - }, - annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - }, - want: true, - }, - { - name: "anti affinity with shared_cores numa_binding pods with same specified pool name", - args: args{ - ai: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - RampUp: false, - OwnerPoolName: PoolNameShare, - AllocationResult: machine.MustParse("1"), - OriginalAllocationResult: machine.MustParse("1"), - TopologyAwareAssignments: map[int]machine.CPUSet{ - 0: machine.NewCPUSet(1), - }, - OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ - 0: machine.NewCPUSet(1), - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationCPUEnhancementCPUSet: "batch", - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - RequestQuantity: 2, - }, - annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationCPUEnhancementCPUSet: "bmq", - }, - }, - want: true, - }, - { - name: "not anti affinity with shared_cores numa_binding pods with same specified pool name", - args: args{ - ai: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - RampUp: false, - OwnerPoolName: PoolNameShare, - AllocationResult: machine.MustParse("1"), - OriginalAllocationResult: machine.MustParse("1"), - TopologyAwareAssignments: map[int]machine.CPUSet{ - 0: machine.NewCPUSet(1), - }, - OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ - 0: machine.NewCPUSet(1), - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationCPUEnhancementCPUSet: "batch", - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - RequestQuantity: 2, - }, - annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationCPUEnhancementCPUSet: "batch", - }, - }, - want: false, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - if got := CheckNUMABindingSharedCoresAntiAffinity(tt.args.ai, tt.args.annotations); got != tt.want { - t.Errorf("CheckNUMABindingSharedCoresAntiAffinity() = %v, want %v", got, tt.want) - } - }) - } -} - func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { t.Parallel() testName := "test" @@ -2900,14 +2847,23 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { pe: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2920,26 +2876,28 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2952,26 +2910,28 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("5,8,10,13,15"), OriginalAllocationResult: machine.MustParse("5,8,10,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -2986,20 +2946,12 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { 2: machine.NewCPUSet(5, 13), 3: machine.NewCPUSet(15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - PoolNameReclaim: ContainerEntries{ + commonstate.PoolNameReclaim: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameReclaim, - OwnerPoolName: PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("5,8,10,13,15"), OriginalAllocationResult: machine.MustParse("5,8,10,13,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3016,10 +2968,9 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { }, }, }, - PoolNameShare: ContainerEntries{ + commonstate.PoolNameShare: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameShare, - OwnerPoolName: PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3036,8 +2987,7 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { }, "share-NUMA3": ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameShare, - OwnerPoolName: PoolNameShare, + AllocationMeta: generateSharedNumaBindingPoolAllocationMeta("share-NUMA3"), AllocationResult: machine.MustParse("6,7,14"), OriginalAllocationResult: machine.MustParse("6,7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3046,22 +2996,28 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14), }, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, }, }, "373d08e4-7a6b-4293-aaaf-b135ff812aaa": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA3", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA3", AllocationResult: machine.MustParse("6,7,14"), OriginalAllocationResult: machine.MustParse("6,7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3070,14 +3026,6 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, @@ -3087,7 +3035,7 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { }, want: map[string]map[int]machine.CPUSet{ "share": { - FakedNUMAID: machine.MustParse("1,3-4,9,11-12"), + commonstate.FakedNUMAID: machine.MustParse("1,3-4,9,11-12"), }, "share-NUMA3": { 3: machine.MustParse("6,7,14"), @@ -3115,7 +3063,9 @@ func TestPodEntries_GetFilteredPoolsCPUSetMap(t *testing.T) { func TestGetAggregatedRequest(t *testing.T) { t.Parallel() - allocation := &AllocationInfo{} + allocation := &AllocationInfo{ + AllocationMeta: commonstate.AllocationMeta{}, + } _, ok := allocation.GetPodAggregatedRequest() require.Equal(t, false, ok) @@ -3158,14 +3108,25 @@ func TestGetAvailableCPUQuantity(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationAggregatedRequestsKey: "{\"cpu\":\"5\"}", + consts.PodAnnotationMemoryEnhancementNumaBinding: "true", + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3174,26 +3135,27 @@ func TestGetAvailableCPUQuantity(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationAggregatedRequestsKey: "{\"cpu\":\"5\"}", - consts.PodAnnotationMemoryEnhancementNumaBinding: "true", - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, sidecarName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: sidecarName, - ContainerType: pluginapi.ContainerType_SIDECAR.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: sidecarName, + ContainerType: pluginapi.ContainerType_SIDECAR.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: "true", + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3202,27 +3164,29 @@ func TestGetAvailableCPUQuantity(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: "true", - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: "true", + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3231,25 +3195,27 @@ func TestGetAvailableCPUQuantity(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: "true", - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, sidecarName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: sidecarName, - ContainerType: pluginapi.ContainerType_SIDECAR.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: sidecarName, + ContainerType: pluginapi.ContainerType_SIDECAR.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: "true", + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -3258,14 +3224,6 @@ func TestGetAvailableCPUQuantity(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: "true", - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util.go index 77fe9a3e5..fd71809dc 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util.go @@ -19,58 +19,58 @@ package state import ( "fmt" "math" - "strings" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" - apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" "github.com/kubewharf/katalyst-core/pkg/util/general" "github.com/kubewharf/katalyst-core/pkg/util/machine" ) -// notice that pool-name may not have direct mapping relations with qos-level, for instance -// - both isolated_shared_cores and dedicated_cores fall into PoolNameDedicated -const ( - PoolNameShare = "share" - PoolNameReclaim = "reclaim" - PoolNameDedicated = "dedicated" - PoolNameReserve = "reserve" - PoolNamePrefixIsolation = "isolation" - PoolNamePrefixSystem = "system" - - // PoolNameFallback is not a real pool, and is a union of - // all none-reclaimed pools to put pod should have been isolated - PoolNameFallback = "fallback" -) - -// FakedContainerName represents a placeholder since pool entry has no container-level -// FakedNUMAID represents a placeholder since pools like shared/reclaimed will not contain a specific numa -const ( - EmptyOwnerPoolName = "" - FakedContainerName = "" - FakedNUMAID = -1 - NameSeparator = "#" - NUMAPoolInfix = "-NUMA" -) - type GetContainerRequestedCoresFunc func(allocationInfo *AllocationInfo) float64 var ( // StaticPools are generated by cpu plugin statically, // and they will be ignored when reading cpu advisor list and watch response. StaticPools = sets.NewString( - PoolNameReserve, + commonstate.PoolNameReserve, ) // ResidentPools are guaranteed existing in state, // and they are usually used to ensure stability. ResidentPools = sets.NewString( - PoolNameReclaim, + commonstate.PoolNameReclaim, ).Union(StaticPools) ) +// WrapAllocationMetaFilter takes a filter function that operates on +// AllocationMeta and returns a wrapper function that applies the same filter +// to an AllocationInfo by extracting its AllocationMeta. +func WrapAllocationMetaFilter(metaFilter func(meta *commonstate.AllocationMeta) bool) func(info *AllocationInfo) bool { + return func(info *AllocationInfo) bool { + if info == nil { + return false // Handle nil cases safely. + } + return metaFilter(&info.AllocationMeta) + } +} + +// WrapAllocationMetaFilterWithAnnotations takes a filter function that operates on +// AllocationMeta and returns a wrapper function that applies the same filter +// to an AllocationInfo by extracting its AllocationMeta and input annotations of candidate. +func WrapAllocationMetaFilterWithAnnotations( + metaFilter func(meta *commonstate.AllocationMeta, annotations map[string]string) bool, +) func(info *AllocationInfo, annotations map[string]string) bool { + return func(info *AllocationInfo, annotations map[string]string) bool { + if info == nil { + return false // Handle nil cases safely. + } + return metaFilter(&info.AllocationMeta, annotations) + } +} + // GetIsolatedQuantityMapFromPodEntries returns a map to indicates isolation info, // and the map is formatted as pod -> container -> isolated-quantity func GetIsolatedQuantityMapFromPodEntries(podEntries PodEntries, ignoreAllocationInfos []*AllocationInfo, getContainerRequestedCores GetContainerRequestedCoresFunc) map[string]map[string]int { @@ -83,7 +83,7 @@ func GetIsolatedQuantityMapFromPodEntries(podEntries PodEntries, ignoreAllocatio containerLoop: for containerName, allocationInfo := range entries { // only filter dedicated_cores without numa_binding - if allocationInfo == nil || CheckDedicatedNUMABinding(allocationInfo) || !CheckDedicated(allocationInfo) { + if allocationInfo == nil || allocationInfo.CheckDedicatedNUMABinding() || !allocationInfo.CheckDedicated() { continue } @@ -97,7 +97,7 @@ func GetIsolatedQuantityMapFromPodEntries(podEntries PodEntries, ignoreAllocatio // to pool rather than isolation. calling this function means we will start to adjust allocation, // and we will try to isolate those containers, so we will treat them as containers to be isolated. var quantity int - if allocationInfo.OwnerPoolName != PoolNameDedicated { + if allocationInfo.OwnerPoolName != commonstate.PoolNameDedicated { quantity = int(math.Ceil(getContainerRequestedCores(allocationInfo))) } else { quantity = allocationInfo.AllocationResult.Size() @@ -133,7 +133,7 @@ func GetSharedQuantityMapFromPodEntries(podEntries PodEntries, ignoreAllocationI // if there is no more cores to allocate, we will put dedicated_cores without numa_binding to pool rather than isolation. // calling this function means we will start to adjust allocation, and we will try to isolate those containers, // so we will treat them as containers to be isolated. - if allocationInfo == nil || !CheckShared(allocationInfo) || !allocationInfo.CheckMainContainer() { + if allocationInfo == nil || !allocationInfo.CheckShared() || !allocationInfo.CheckMainContainer() { continue } @@ -172,7 +172,7 @@ func GetNonBindingSharedRequestedQuantityFromPodEntries(podEntries PodEntries, n } for _, allocationInfo := range entries { - if allocationInfo == nil || !CheckShared(allocationInfo) || CheckNUMABinding(allocationInfo) { + if allocationInfo == nil || !allocationInfo.CheckShared() || allocationInfo.CheckNUMABinding() { continue } @@ -192,53 +192,8 @@ func GenerateMachineStateFromPodEntries(topology *machine.CPUTopology, podEntrie return GenerateMachineStateFromPodEntriesByPolicy(topology, podEntries, cpuconsts.CPUResourcePluginPolicyNameDynamic) } -func IsIsolationPool(poolName string) bool { - return strings.HasPrefix(poolName, PoolNamePrefixIsolation) -} - -func IsSystemPool(poolName string) bool { - return strings.HasPrefix(poolName, PoolNamePrefixSystem) -} - -func GetPoolType(poolName string) string { - if IsIsolationPool(poolName) { - return PoolNamePrefixIsolation - } else if IsSystemPool(poolName) { - return PoolNamePrefixSystem - } - switch poolName { - case PoolNameReclaim, PoolNameDedicated, PoolNameReserve, PoolNameFallback: - return poolName - default: - return PoolNameShare - } -} - -// GetSpecifiedPoolName todo: this function (along with pool-name consts) should be moved to generic qos conf -func GetSpecifiedPoolName(qosLevel, cpusetEnhancementValue string) string { - switch qosLevel { - case apiconsts.PodAnnotationQoSLevelSharedCores: - if cpusetEnhancementValue != EmptyOwnerPoolName { - return cpusetEnhancementValue - } - return PoolNameShare - case apiconsts.PodAnnotationQoSLevelSystemCores: - return cpusetEnhancementValue - case apiconsts.PodAnnotationQoSLevelReclaimedCores: - return PoolNameReclaim - case apiconsts.PodAnnotationQoSLevelDedicatedCores: - return PoolNameDedicated - default: - return EmptyOwnerPoolName - } -} - -func GetNUMAPoolName(candidateSpecifiedPoolName string, targetNUMANode uint64) string { - return fmt.Sprintf("%s%s%d", candidateSpecifiedPoolName, NUMAPoolInfix, targetNUMANode) -} - func GetCPUIncrRatio(allocationInfo *AllocationInfo) float64 { - if CheckSharedNUMABinding(allocationInfo) { + if allocationInfo.CheckSharedNUMABinding() { // multiply incrRatio for numa_binding shared_cores to allow it burst return cpuconsts.CPUIncrRatioSharedCoresNUMABinding } @@ -251,7 +206,7 @@ func GetSharedBindingNUMAsFromQuantityMap(poolsQuantityMap map[string]map[int]in for _, quantityMap := range poolsQuantityMap { for numaID, quantity := range quantityMap { - if numaID != FakedNUMAID && quantity > 0 { + if numaID != commonstate.FakedNUMAID && quantity > 0 { res.Insert(numaID) } } @@ -280,11 +235,11 @@ func CountAllocationInfosToPoolsQuantityMap(allocationInfos []*AllocationInfo, var targetNUMAID int var poolName string - if CheckSharedNUMABinding(allocationInfo) { + if allocationInfo.CheckSharedNUMABinding() { var numaSet machine.CPUSet poolName = allocationInfo.GetOwnerPoolName() - if poolName == EmptyOwnerPoolName { + if poolName == commonstate.EmptyOwnerPoolName { var pErr error poolName, pErr = allocationInfo.GetSpecifiedNUMABindingPoolName() if pErr != nil { @@ -320,11 +275,11 @@ func CountAllocationInfosToPoolsQuantityMap(allocationInfos []*AllocationInfo, allocationInfo.Annotations[cpuconsts.CPUStateAnnotationKeyNUMAHint]) } } else { - targetNUMAID = FakedNUMAID + targetNUMAID = commonstate.FakedNUMAID poolName = allocationInfo.GetPoolName() } - if poolName == EmptyOwnerPoolName { + if poolName == commonstate.EmptyOwnerPoolName { return fmt.Errorf("get poolName failed for %s/%s/%s", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName) } @@ -370,17 +325,17 @@ func GetSharedNUMABindingTargetNuma(allocationInfo *AllocationInfo) (int, error) var numaSet machine.CPUSet poolName := allocationInfo.GetOwnerPoolName() - if poolName == EmptyOwnerPoolName { + if poolName == commonstate.EmptyOwnerPoolName { var pErr error poolName, pErr = allocationInfo.GetSpecifiedNUMABindingPoolName() if pErr != nil { - return FakedNUMAID, fmt.Errorf("GetSpecifiedNUMABindingPoolName for %s/%s/%s failed with error: %v", + return commonstate.FakedNUMAID, fmt.Errorf("GetSpecifiedNUMABindingPoolName for %s/%s/%s failed with error: %v", allocationInfo.PodNamespace, allocationInfo.PodName, allocationInfo.ContainerName, pErr) } numaSet, pErr = machine.Parse(allocationInfo.Annotations[cpuconsts.CPUStateAnnotationKeyNUMAHint]) if pErr != nil { - return FakedNUMAID, fmt.Errorf("parse numaHintStr: %s failed with error: %v", + return commonstate.FakedNUMAID, fmt.Errorf("parse numaHintStr: %s failed with error: %v", allocationInfo.Annotations[cpuconsts.CPUStateAnnotationKeyNUMAHint], pErr) } @@ -395,14 +350,14 @@ func GetSharedNUMABindingTargetNuma(allocationInfo *AllocationInfo) (int, error) } if numaSet.Size() != 1 { - return FakedNUMAID, fmt.Errorf("numaHintStr: %s indicates invalid numaSet size for numa_binding shared_cores", + return commonstate.FakedNUMAID, fmt.Errorf("numaHintStr: %s indicates invalid numaSet size for numa_binding shared_cores", allocationInfo.Annotations[cpuconsts.CPUStateAnnotationKeyNUMAHint]) } targetNUMAID := numaSet.ToSliceNoSortInt()[0] if targetNUMAID < 0 { - return FakedNUMAID, fmt.Errorf("numaHintStr: %s indicates invalid numaSet numa_binding shared_cores", + return commonstate.FakedNUMAID, fmt.Errorf("numaHintStr: %s indicates invalid numaSet numa_binding shared_cores", allocationInfo.Annotations[cpuconsts.CPUStateAnnotationKeyNUMAHint]) } @@ -475,12 +430,12 @@ func GenerateMachineStateFromPodEntriesByPolicy(topology *machine.CPUTopology, p // only modify allocated and default properties in NUMA node state if the policy is dynamic and the entry indicates numa_binding. // shared_cores with numa_binding also contributes to numaNodeState.AllocatedCPUSet, // it's convenient that we can skip NUMA with AllocatedCPUSet > 0 when allocating CPUs for dedicated_cores with numa_binding. - if CheckSharedOrDedicatedNUMABinding(allocationInfo) { + if allocationInfo.CheckSharedOrDedicatedNUMABinding() { allocatedCPUsInNumaNode = allocatedCPUsInNumaNode.Union(allocationInfo.OriginalTopologyAwareAssignments[int(numaNode)]) } case cpuconsts.CPUResourcePluginPolicyNameNative: // only modify allocated and default properties in NUMA node state if the policy is native and the QoS class is Guaranteed - if CheckDedicatedPool(allocationInfo) { + if allocationInfo.CheckDedicatedPool() { allocatedCPUsInNumaNode = allocatedCPUsInNumaNode.Union(allocationInfo.OriginalTopologyAwareAssignments[int(numaNode)]) } } diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go index b0b0c90ed..f541adc69 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/util_test.go @@ -29,6 +29,7 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" "github.com/kubewharf/katalyst-core/pkg/util/machine" ) @@ -53,14 +54,23 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { podEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -73,26 +83,28 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -105,26 +117,28 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -139,20 +153,12 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { 2: machine.NewCPUSet(5, 13), 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, - PoolNameReclaim: ContainerEntries{ + commonstate.PoolNameReclaim: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameReclaim, - OwnerPoolName: PoolNameReclaim, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameReclaim), AllocationResult: machine.MustParse("5-8,10,13-15"), OriginalAllocationResult: machine.MustParse("5-8,10,13-15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -169,10 +175,9 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { }, }, }, - PoolNameShare: ContainerEntries{ + commonstate.PoolNameShare: ContainerEntries{ "": &AllocationInfo{ - PodUid: PoolNameShare, - OwnerPoolName: PoolNameShare, + AllocationMeta: commonstate.GenerateGenericPoolAllocationMeta(commonstate.PoolNameShare), AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -195,14 +200,23 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -211,26 +225,28 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.NewCPUSet(1, 9), OriginalAllocationResult: machine.NewCPUSet(1, 9), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -239,26 +255,29 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(1, 9), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("8"), OriginalAllocationResult: machine.MustParse("8"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -267,13 +286,6 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.NewCPUSet(8), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -285,14 +297,23 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -301,26 +322,28 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("3,11"), OriginalAllocationResult: machine.MustParse("3,11"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -329,26 +352,28 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(3, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("10"), OriginalAllocationResult: machine.MustParse("10"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -357,13 +382,6 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.NewCPUSet(10), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -375,14 +393,23 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { PodEntries: PodEntries{ "373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff8123bf", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -391,26 +418,28 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("4,12"), OriginalAllocationResult: machine.MustParse("4,12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -419,26 +448,28 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 2, }, }, "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("5,13"), OriginalAllocationResult: machine.MustParse("5,13"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -447,13 +478,6 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 2: machine.NewCPUSet(5, 13), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -465,14 +489,23 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { PodEntries: PodEntries{ "2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{ testName: &AllocationInfo{ - PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "2432d068-c5a0-46ba-a7bd-b69d9bd16961", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameReclaim, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + }, RampUp: false, - OwnerPoolName: PoolNameReclaim, AllocationResult: machine.MustParse("6,7,14,15"), OriginalAllocationResult: machine.MustParse("6,7,14,15"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -481,13 +514,6 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14, 15), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, RequestQuantity: 2, }, }, @@ -511,67 +537,6 @@ func TestGenerateCPUMachineStateByPodEntries(t *testing.T) { } } -func TestGetSpecifiedPoolName(t *testing.T) { - t.Parallel() - - type args struct { - qosLevel string - cpusetEnhancementValue string - } - tests := []struct { - name string - args args - want string - }{ - { - name: "shared_cores with empty cpusetEnhancementValue", - args: args{ - qosLevel: consts.PodAnnotationQoSLevelSharedCores, - }, - want: PoolNameShare, - }, - { - name: "shared_cores with non-empty cpusetEnhancementValue", - args: args{ - qosLevel: consts.PodAnnotationQoSLevelSharedCores, - cpusetEnhancementValue: "offline", - }, - want: "offline", - }, - { - name: "dedicated_cores with empty cpusetEnhancementValue", - args: args{ - qosLevel: consts.PodAnnotationQoSLevelDedicatedCores, - }, - want: PoolNameDedicated, - }, - { - name: "reclaimed_cores with empty cpusetEnhancementValue", - args: args{ - qosLevel: consts.PodAnnotationQoSLevelReclaimedCores, - }, - want: PoolNameReclaim, - }, - { - name: "system_cores with empty cpusetEnhancementValue", - args: args{ - qosLevel: consts.PodAnnotationQoSLevelSystemCores, - cpusetEnhancementValue: "reserve", - }, - want: "reserve", - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - if got := GetSpecifiedPoolName(tt.args.qosLevel, tt.args.cpusetEnhancementValue); got != tt.want { - t.Errorf("GetSpecifiedPoolName() = %v, want %v", got, tt.want) - } - }) - } -} - func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { t.Parallel() testName := "test" @@ -592,14 +557,24 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { args: args{ allocationInfos: []*AllocationInfo{ { - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA3", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA3", AllocationResult: machine.MustParse("6,7,14"), OriginalAllocationResult: machine.MustParse("6,7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -608,44 +583,47 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 1.1, }, { - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812bbb", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - RampUp: false, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - cpuconsts.CPUStateAnnotationKeyNUMAHint: "3", - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812bbb", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + cpuconsts.CPUStateAnnotationKeyNUMAHint: "3", + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, + RampUp: false, RequestQuantity: 1.1, }, { - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -658,13 +636,6 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 3.1, }, }, @@ -675,7 +646,7 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { 3: 5, }, "share": { - FakedNUMAID: 4, + commonstate.FakedNUMAID: 4, }, }, @@ -686,14 +657,24 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { args: args{ allocationInfos: []*AllocationInfo{ { - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA3", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA3", AllocationResult: machine.MustParse("6,7,14"), OriginalAllocationResult: machine.MustParse("6,7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -702,44 +683,47 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 1.1, }, { - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812bbb", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - RampUp: false, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - cpuconsts.CPUStateAnnotationKeyNUMAHint: "2-3", - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812bbb", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + cpuconsts.CPUStateAnnotationKeyNUMAHint: "2-3", + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, + RampUp: false, RequestQuantity: 1.1, }, { - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -752,13 +736,6 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 3.1, }, }, @@ -771,14 +748,24 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { args: args{ allocationInfos: []*AllocationInfo{ { - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812aaa", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: "share-NUMA3", + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: "share-NUMA3", AllocationResult: machine.MustParse("6,7,14"), OriginalAllocationResult: machine.MustParse("6,7,14"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -787,44 +774,47 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { OriginalTopologyAwareAssignments: map[int]machine.CPUSet{ 3: machine.NewCPUSet(6, 7, 14), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 1.1, }, { - PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812bbb", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - RampUp: false, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - cpuconsts.CPUStateAnnotationKeyNUMAHint: "2-3", - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "373d08e4-7a6b-4293-aaaf-b135ff812bbb", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + cpuconsts.CPUStateAnnotationKeyNUMAHint: "2-3", + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, + RampUp: false, RequestQuantity: 1.1, }, { - PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "ec6e2f30-c78a-4bc4-9576-c916db5281a3", + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameShare, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, RampUp: false, - OwnerPoolName: PoolNameShare, AllocationResult: machine.MustParse("1,3-4,9,11-12"), OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -837,13 +827,6 @@ func TestCountAllocationInfosToPoolsQuantityMap(t *testing.T) { 1: machine.NewCPUSet(3, 11), 2: machine.NewCPUSet(4, 12), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RequestQuantity: 3.1, }, }, diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/util_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/util_test.go index 974b280dd..ab0debd12 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/util_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/util_test.go @@ -22,6 +22,7 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" ) @@ -51,7 +52,9 @@ func Test_updateAllocationInfoByReq(t *testing.T) { Annotations: map[string]string{apiconsts.PodAnnotationQoSLevelKey: apiconsts.PodAnnotationQoSLevelSharedCores}, }, allocationInfo: &state.AllocationInfo{ - QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + AllocationMeta: commonstate.AllocationMeta{ + QoSLevel: apiconsts.PodAnnotationQoSLevelReclaimedCores, + }, }, }, wantErr: false, diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/validator/validator_cpu_advisor.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/validator/validator_cpu_advisor.go index 1aa5a6489..37dba6ebe 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/validator/validator_cpu_advisor.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/validator/validator_cpu_advisor.go @@ -21,6 +21,7 @@ import ( "k8s.io/apimachinery/pkg/util/errors" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" advisorapi "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/util/general" @@ -61,8 +62,8 @@ func (c *CPUAdvisorValidator) validateEntries(resp *advisorapi.ListAndWatchRespo entries := c.state.GetPodEntries() // validate dedicated_cores entries - dedicatedAllocationInfos := entries.GetFilteredPodEntries(state.CheckDedicated) - dedicatedCalculationInfos := resp.FilterCalculationInfo(state.PoolNameDedicated) + dedicatedAllocationInfos := entries.GetFilteredPodEntries(state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckDedicated)) + dedicatedCalculationInfos := resp.FilterCalculationInfo(commonstate.PoolNameDedicated) if len(dedicatedAllocationInfos) != len(dedicatedCalculationInfos) { return fmt.Errorf("dedicatedAllocationInfos length: %d and dedicatedCalculationInfos length: %d mismatch", len(dedicatedAllocationInfos), len(dedicatedCalculationInfos)) @@ -75,7 +76,7 @@ func (c *CPUAdvisorValidator) validateEntries(resp *advisorapi.ListAndWatchRespo return fmt.Errorf("missing CalculationInfo for pod: %s container: %s", podUID, containerName) } - if !state.CheckDedicatedNUMABinding(allocationInfo) { + if !allocationInfo.CheckDedicatedNUMABinding() { numaCalculationQuantities, err := calculationInfo.GetNUMAQuantities() if err != nil { return fmt.Errorf("GetNUMAQuantities failed with error: %v, pod: %s container: %s", @@ -115,7 +116,7 @@ func (c *CPUAdvisorValidator) validateEntries(resp *advisorapi.ListAndWatchRespo } // validate shared_cores with numa_binding entries - sharedNUMABindingAllocationInfos := entries.GetFilteredPodEntries(state.CheckSharedNUMABinding) + sharedNUMABindingAllocationInfos := entries.GetFilteredPodEntries(state.WrapAllocationMetaFilter((*commonstate.AllocationMeta).CheckSharedNUMABinding)) for podUID, containerEntries := range sharedNUMABindingAllocationInfos { for containerName := range containerEntries { @@ -125,7 +126,7 @@ func (c *CPUAdvisorValidator) validateEntries(resp *advisorapi.ListAndWatchRespo return fmt.Errorf("missing CalculationInfo for pod: %s container: %s", podUID, containerName) } - if calculationInfo.OwnerPoolName == state.EmptyOwnerPoolName { + if calculationInfo.OwnerPoolName == commonstate.EmptyOwnerPoolName { return fmt.Errorf("shared_cores with numa_biding pod: %s container: %s has empty pool name", podUID, containerName) } } @@ -138,10 +139,10 @@ func (c *CPUAdvisorValidator) validateStaticPools(resp *advisorapi.ListAndWatchR for _, poolName := range state.StaticPools.List() { var nilStateEntry, nilRespEntry bool - if entries[poolName] == nil || entries[poolName][state.FakedContainerName] == nil { + if entries[poolName] == nil || entries[poolName][commonstate.FakedContainerName] == nil { nilStateEntry = true } - if resp.Entries[poolName] == nil || resp.Entries[poolName].Entries[state.FakedContainerName] == nil { + if resp.Entries[poolName] == nil || resp.Entries[poolName].Entries[commonstate.FakedContainerName] == nil { nilRespEntry = true } @@ -154,16 +155,16 @@ func (c *CPUAdvisorValidator) validateStaticPools(resp *advisorapi.ListAndWatchR continue } - allocationInfo := entries[poolName][state.FakedContainerName] - calculationInfo := resp.Entries[poolName].Entries[state.FakedContainerName] + allocationInfo := entries[poolName][commonstate.FakedContainerName] + calculationInfo := resp.Entries[poolName].Entries[commonstate.FakedContainerName] if calculationInfo.OwnerPoolName != poolName { return fmt.Errorf("pool: %s has invalid owner pool name: %s in cpu advisor resp", poolName, calculationInfo.OwnerPoolName) } if len(calculationInfo.CalculationResultsByNumas) != 1 || - calculationInfo.CalculationResultsByNumas[state.FakedNUMAID] == nil || - len(calculationInfo.CalculationResultsByNumas[state.FakedNUMAID].Blocks) != 1 { + calculationInfo.CalculationResultsByNumas[commonstate.FakedNUMAID] == nil || + len(calculationInfo.CalculationResultsByNumas[commonstate.FakedNUMAID].Blocks) != 1 { return fmt.Errorf("static pool: %s has invalid calculationInfo", poolName) } @@ -196,7 +197,7 @@ func (c *CPUAdvisorValidator) validateBlocks(resp *advisorapi.ListAndWatchRespon totalQuantity := 0 numas := c.machineInfo.CPUTopology.CPUDetails.NUMANodes() for numaId, blocks := range numaToBlocks { - if numaId != state.FakedNUMAID && !numas.Contains(numaId) { + if numaId != commonstate.FakedNUMAID && !numas.Contains(numaId) { return fmt.Errorf("NUMA: %d referred by blocks isn't in topology", numaId) } @@ -214,7 +215,7 @@ func (c *CPUAdvisorValidator) validateBlocks(resp *advisorapi.ListAndWatchRespon numaQuantity += quantityInt } - if numaId != state.FakedNUMAID { + if numaId != commonstate.FakedNUMAID { numaCapacity := c.machineInfo.CPUTopology.CPUDetails.CPUsInNUMANodes(numaId).Size() if numaQuantity > numaCapacity { return fmt.Errorf("numaQuantity: %d exceeds NUMA capacity: %d in NUMA: %d", numaQuantity, numaCapacity, numaId) diff --git a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/vpa_test.go b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/vpa_test.go index d901e3e7b..aa9fc7957 100644 --- a/pkg/agent/qrm-plugins/cpu/dynamicpolicy/vpa_test.go +++ b/pkg/agent/qrm-plugins/cpu/dynamicpolicy/vpa_test.go @@ -29,7 +29,7 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" "github.com/kubewharf/katalyst-api/pkg/consts" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/util" "github.com/kubewharf/katalyst-core/pkg/util/machine" ) @@ -672,7 +672,7 @@ func TestNormalShareVPA(t *testing.T) { resp1, err := dynamicPolicy.GetResourcesAllocation(context.Background(), &pluginapi.GetResourcesAllocationRequest{}) as.Nil(err) - reclaim := dynamicPolicy.state.GetAllocationInfo(state.PoolNameReclaim, state.FakedContainerName) + reclaim := dynamicPolicy.state.GetAllocationInfo(commonstate.PoolNameReclaim, commonstate.FakedContainerName) as.NotNil(reclaim) as.NotNil(resp1.PodResources[req.PodUid]) @@ -741,7 +741,7 @@ func TestNormalShareVPA(t *testing.T) { resp1, err = dynamicPolicy.GetResourcesAllocation(context.Background(), &pluginapi.GetResourcesAllocationRequest{}) as.Nil(err) - reclaim = dynamicPolicy.state.GetAllocationInfo(state.PoolNameReclaim, state.FakedContainerName) + reclaim = dynamicPolicy.state.GetAllocationInfo(commonstate.PoolNameReclaim, commonstate.FakedContainerName) as.NotNil(reclaim) as.NotNil(resp1.PodResources[req.PodUid]) @@ -828,7 +828,7 @@ func TestNormalShareVPAWithSidecar(t *testing.T) { as.NotNil(allocationRes.PodResources[podUID].ContainerResources[sidecarContainerName]) as.NotNil(allocationRes.PodResources[podUID].ContainerResources[sidecarContainerName].ResourceAllocation[string(v1.ResourceCPU)]) // reserve pool size: 2, reclaimed pool size: 4, share pool size: 42 - reclaim := dynamicPolicy.state.GetAllocationInfo(state.PoolNameReclaim, state.FakedContainerName) + reclaim := dynamicPolicy.state.GetAllocationInfo(commonstate.PoolNameReclaim, commonstate.FakedContainerName) as.NotNil(reclaim) as.Equal(&pluginapi.ResourceAllocationInfo{ OciPropertyName: util.OCIPropertyNameCPUSetCPUs, @@ -877,7 +877,7 @@ func TestNormalShareVPAWithSidecar(t *testing.T) { as.NotNil(allocationRes.PodResources[mainReq.PodUid].ContainerResources[mainContainerName]) as.NotNil(allocationRes.PodResources[mainReq.PodUid].ContainerResources[mainContainerName].ResourceAllocation[string(v1.ResourceCPU)]) // reserve pool size: 2, reclaimed pool size: 4, share pool size: 42 - reclaim = dynamicPolicy.state.GetAllocationInfo(state.PoolNameReclaim, state.FakedContainerName) + reclaim = dynamicPolicy.state.GetAllocationInfo(commonstate.PoolNameReclaim, commonstate.FakedContainerName) as.NotNil(reclaim) as.Equal(&pluginapi.ResourceAllocationInfo{ OciPropertyName: util.OCIPropertyNameCPUSetCPUs, @@ -935,7 +935,7 @@ func TestNormalShareVPAWithSidecar(t *testing.T) { as.NotNil(resizeMainContainerAllocations.PodResources[podUID].ContainerResources[mainContainerName]) as.NotNil(resizeMainContainerAllocations.PodResources[podUID].ContainerResources[mainContainerName].ResourceAllocation[string(v1.ResourceCPU)]) // reserve pool size: 2, reclaimed pool size: 4, share pool size: 42 - reclaim = dynamicPolicy.state.GetAllocationInfo(state.PoolNameReclaim, state.FakedContainerName) + reclaim = dynamicPolicy.state.GetAllocationInfo(commonstate.PoolNameReclaim, commonstate.FakedContainerName) as.NotNil(reclaim) as.Equal(&pluginapi.ResourceAllocationInfo{ OciPropertyName: util.OCIPropertyNameCPUSetCPUs, @@ -1012,7 +1012,7 @@ func TestNormalShareVPAWithSidecar(t *testing.T) { as.NotNil(resizeSidecarContainerAllocations.PodResources[podUID].ContainerResources[mainContainerName]) as.NotNil(resizeSidecarContainerAllocations.PodResources[podUID].ContainerResources[mainContainerName].ResourceAllocation[string(v1.ResourceCPU)]) // reserve pool size: 2, reclaimed pool size: 4, share pool size: 42 - reclaim = dynamicPolicy.state.GetAllocationInfo(state.PoolNameReclaim, state.FakedContainerName) + reclaim = dynamicPolicy.state.GetAllocationInfo(commonstate.PoolNameReclaim, commonstate.FakedContainerName) as.NotNil(reclaim) as.Equal(&pluginapi.ResourceAllocationInfo{ OciPropertyName: util.OCIPropertyNameCPUSetCPUs, diff --git a/pkg/agent/qrm-plugins/cpu/nativepolicy/policy.go b/pkg/agent/qrm-plugins/cpu/nativepolicy/policy.go index 31b0fa80a..823d28af5 100644 --- a/pkg/agent/qrm-plugins/cpu/nativepolicy/policy.go +++ b/pkg/agent/qrm-plugins/cpu/nativepolicy/policy.go @@ -29,6 +29,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/plugins/skeleton" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/agent" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" cpuconsts "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" nativepolicyutil "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/nativepolicy/util" @@ -458,9 +459,9 @@ func (p *NativePolicy) GetResourcesAllocation(_ context.Context, resultCPUSet := machine.NewCPUSet() switch allocationInfo.OwnerPoolName { - case state.PoolNameDedicated: + case commonstate.PoolNameDedicated: resultCPUSet = allocationInfo.AllocationResult - case state.PoolNameShare: + case commonstate.PoolNameShare: resultCPUSet = defaultCPUSet if !allocationInfo.AllocationResult.Equals(defaultCPUSet) { @@ -530,7 +531,7 @@ func (p *NativePolicy) GetTopologyAwareResources(_ context.Context, }, } - if allocationInfo.OwnerPoolName == state.PoolNameDedicated { + if allocationInfo.OwnerPoolName == commonstate.PoolNameDedicated { resp.ContainerTopologyAwareResources.AllocatedResources[string(v1.ResourceCPU)] = &pluginapi.TopologyAwareResource{ IsNodeResource: false, IsScalarResource: true, diff --git a/pkg/agent/qrm-plugins/cpu/nativepolicy/policy_allocation_handlers.go b/pkg/agent/qrm-plugins/cpu/nativepolicy/policy_allocation_handlers.go index ddd374ecb..26916bcff 100644 --- a/pkg/agent/qrm-plugins/cpu/nativepolicy/policy_allocation_handlers.go +++ b/pkg/agent/qrm-plugins/cpu/nativepolicy/policy_allocation_handlers.go @@ -27,6 +27,7 @@ import ( "k8s.io/klog/v2" pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/nativepolicy/calculator" nativepolicyutil "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/nativepolicy/util" @@ -115,21 +116,13 @@ func (p *NativePolicy) dedicatedCoresAllocationHandler(_ context.Context, } allocationInfo := &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodType: req.PodType, - OwnerPoolName: state.PoolNameDedicated, + // native policy not support qos level now + AllocationMeta: commonstate.GenerateGenericContainerAllocationMeta(req, commonstate.PoolNameDedicated, ""), AllocationResult: result.Clone(), OriginalAllocationResult: result.Clone(), TopologyAwareAssignments: topologyAwareAssignments, OriginalTopologyAwareAssignments: machine.DeepcopyCPUAssignment(topologyAwareAssignments), InitTimestamp: time.Now().Format(util.QRMTimeFormat), - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), RequestQuantity: reqFloat64, } @@ -191,21 +184,12 @@ func (p *NativePolicy) sharedPoolAllocationHandler(ctx context.Context, } allocationInfo := &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodType: req.PodType, - OwnerPoolName: state.PoolNameShare, + AllocationMeta: commonstate.GenerateGenericContainerAllocationMeta(req, commonstate.PoolNameShare, ""), AllocationResult: defaultCPUSet.Clone(), OriginalAllocationResult: defaultCPUSet.Clone(), TopologyAwareAssignments: topologyAwareAssignments, OriginalTopologyAwareAssignments: machine.DeepcopyCPUAssignment(topologyAwareAssignments), InitTimestamp: time.Now().Format(util.QRMTimeFormat), - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), RequestQuantity: reqFloat64, } diff --git a/pkg/agent/qrm-plugins/cpu/util/util_test.go b/pkg/agent/qrm-plugins/cpu/util/util_test.go index 44a905de7..ea2e3bf7e 100644 --- a/pkg/agent/qrm-plugins/cpu/util/util_test.go +++ b/pkg/agent/qrm-plugins/cpu/util/util_test.go @@ -25,6 +25,7 @@ import ( pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/util" "github.com/kubewharf/katalyst-core/pkg/config" @@ -148,14 +149,24 @@ func TestRegenerateHints(t *testing.T) { name: "test RegenerateHints", args: args{ allocationInfo: &state.AllocationInfo{ - PodUid: "test", - PodNamespace: "test", - PodName: "test", - ContainerName: "test", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test", + PodNamespace: "test", + PodName: "test", + ContainerName: "test", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.NewCPUSet(1, 3, 8, 9, 10, 11), OriginalAllocationResult: machine.NewCPUSet(1, 3, 8, 9, 10, 11), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -166,14 +177,6 @@ func TestRegenerateHints(t *testing.T) { 0: machine.NewCPUSet(1, 8, 9), 1: machine.NewCPUSet(3, 10, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, reqInt: 2, @@ -236,14 +239,24 @@ func TestPackAllocationResponse(t *testing.T) { name: "test PackAllocationResponse", args: args{ allocationInfo: &state.AllocationInfo{ - PodUid: "test", - PodNamespace: "test", - PodName: "test", - ContainerName: "test", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test", + PodNamespace: "test", + PodName: "test", + ContainerName: "test", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + OwnerPoolName: commonstate.PoolNameDedicated, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, RampUp: false, - OwnerPoolName: state.PoolNameDedicated, AllocationResult: machine.NewCPUSet(1, 3, 8, 9, 10, 11), OriginalAllocationResult: machine.NewCPUSet(1, 3, 8, 9, 10, 11), TopologyAwareAssignments: map[int]machine.CPUSet{ @@ -254,14 +267,6 @@ func TestPackAllocationResponse(t *testing.T) { 0: machine.NewCPUSet(1, 8, 9), 1: machine.NewCPUSet(3, 10, 11), }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, RequestQuantity: 2, }, resourceName: string(v1.ResourceCPU), diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy.go index 650526dad..22223b2e5 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy.go @@ -1020,7 +1020,7 @@ func (p *DynamicPolicy) getContainerRequestedMemoryBytes(allocationInfo *state.A // TODO optimize this logic someday: // only for refresh cpu request for old pod with cpu ceil and old VPA pods. // we can remove refresh logic after upgrade all kubelet and qrm. - if allocationInfo.QoSLevel == apiconsts.PodAnnotationQoSLevelSharedCores { + if allocationInfo.CheckShared() { // if there is these two annotations in memory state, it is a new pod, // we don't need to check the pod request from podWatcher if allocationInfo.Annotations[apiconsts.PodAnnotationAggregatedRequestsKey] != "" || @@ -1028,7 +1028,7 @@ func (p *DynamicPolicy) getContainerRequestedMemoryBytes(allocationInfo *state.A return allocationInfo.AggregatedQuantity } - if allocationInfo.CheckNumaBinding() { + if allocationInfo.CheckNUMABinding() { // snb count all memory into main container, sidecar is zero if allocationInfo.CheckSideCar() { // sidecar container always is zero @@ -1136,7 +1136,7 @@ func (p *DynamicPolicy) checkNormalShareCoresResource(req *pluginapi.ResourceReq continue } // shareCoresAllocated should involve both main and sidecar containers - if containerAllocation.QoSLevel == apiconsts.PodAnnotationQoSLevelSharedCores && !containerAllocation.CheckNumaBinding() { + if containerAllocation.CheckDedicated() && !containerAllocation.CheckNUMABinding() { shareCoresAllocated += p.getContainerRequestedMemoryBytes(containerAllocation) } } diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go index cf4c92d62..cb2ccda98 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler.go @@ -404,7 +404,7 @@ func handleAdvisorCPUSetMems( return fmt.Errorf("setting high level cgroup path cpuset.mems isn't supported") } else if allocationInfo == nil { return fmt.Errorf("setting cpuset.mems for nil allocationInfo: %s/%s", entryName, subEntryName) - } else if allocationInfo.QoSLevel != apiconsts.PodAnnotationQoSLevelReclaimedCores { + } else if !allocationInfo.CheckReclaimed() { // cpuset.mems for numa_binding dedicated_cores isn't changed now // cpuset.mems for shared_cores is auto-adjusted in memory plugin return fmt.Errorf("setting cpuset.mems for container not with qosLevel: %s isn't supported", diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_allocation_handlers.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_allocation_handlers.go index 15dea2666..89cdfd094 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_allocation_handlers.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_allocation_handlers.go @@ -207,20 +207,10 @@ func (p *DynamicPolicy) numaBindingAllocationHandler(ctx context.Context, "numaAllocationResult", result.String()) allocationInfo = &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodRole: req.PodRole, - PodType: req.PodType, + AllocationMeta: state.GenerateMemoryContainerAllocationMeta(req, qosLevel), AggregatedQuantity: aggregatedQuantity, NumaAllocationResult: result.Clone(), TopologyAwareAllocations: topologyAwareAllocations, - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), - QoSLevel: qosLevel, } p.state.SetAllocationInfo(v1.ResourceMemory, req.PodUid, req.ContainerName, allocationInfo) @@ -277,20 +267,11 @@ func (p *DynamicPolicy) numaBindingAllocationSidecarHandler(_ context.Context, } allocationInfo := &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodRole: req.PodRole, - PodType: req.PodType, + AllocationMeta: state.GenerateMemoryContainerAllocationMeta(req, qosLevel), AggregatedQuantity: 0, // not count sidecar quantity TopologyAwareAllocations: nil, // not count sidecar quantity - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), - QoSLevel: qosLevel, } + applySidecarAllocationInfoFromMainContainer(allocationInfo, mainContainerAllocationInfo) // update pod entries directly. if one of subsequent steps is failed, @@ -340,18 +321,8 @@ func (p *DynamicPolicy) allocateNUMAsWithoutNUMABindingPods(_ context.Context, } allocationInfo = &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodRole: req.PodRole, - PodType: req.PodType, + AllocationMeta: state.GenerateMemoryContainerAllocationMeta(req, qosLevel), NumaAllocationResult: numaWithoutNUMABindingPods.Clone(), - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), - QoSLevel: qosLevel, AggregatedQuantity: uint64(reqInt), } @@ -392,18 +363,8 @@ func (p *DynamicPolicy) allocateTargetNUMAs(req *pluginapi.ResourceRequest, } allocationInfo = &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodRole: req.PodRole, - PodType: req.PodType, + AllocationMeta: state.GenerateMemoryContainerAllocationMeta(req, qosLevel), NumaAllocationResult: targetNUMAs.Clone(), - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), - QoSLevel: qosLevel, } p.state.SetAllocationInfo(v1.ResourceMemory, allocationInfo.PodUid, allocationInfo.ContainerName, allocationInfo) @@ -547,22 +508,12 @@ func calculateExclusiveMemory(req *pluginapi.ResourceRequest, } numaNodeState.PodEntries[req.PodUid][req.ContainerName] = &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodRole: req.PodRole, - PodType: req.PodType, + AllocationMeta: state.GenerateMemoryContainerAllocationMeta(req, qosLevel), AggregatedQuantity: curNumaNodeAllocated, NumaAllocationResult: machine.NewCPUSet(numaNode), TopologyAwareAllocations: map[int]uint64{ numaNode: curNumaNodeAllocated, }, - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), - QoSLevel: qosLevel, } } @@ -608,22 +559,12 @@ func calculateMemoryInNumaNodes(req *pluginapi.ResourceRequest, } numaNodeState.PodEntries[req.PodUid][req.ContainerName] = &state.AllocationInfo{ - PodUid: req.PodUid, - PodNamespace: req.PodNamespace, - PodName: req.PodName, - ContainerName: req.ContainerName, - ContainerType: req.ContainerType.String(), - ContainerIndex: req.ContainerIndex, - PodRole: req.PodRole, - PodType: req.PodType, + AllocationMeta: state.GenerateMemoryContainerAllocationMeta(req, qosLevel), AggregatedQuantity: curNumaNodeAllocated, NumaAllocationResult: machine.NewCPUSet(numaNode), TopologyAwareAllocations: map[int]uint64{ numaNode: curNumaNodeAllocated, }, - Labels: general.DeepCopyMap(req.Labels), - Annotations: general.DeepCopyMap(req.Annotations), - QoSLevel: qosLevel, } } @@ -683,12 +624,11 @@ func (p *DynamicPolicy) adjustAllocationEntriesForSharedCores(numaSetChangedCont } else if containerName == "" { general.Errorf("pod: %s has empty containerName entry", podUID) continue - } else if allocationInfo.QoSLevel != apiconsts.PodAnnotationQoSLevelSharedCores { - // not to adjust NUMA binding containers + } else if !allocationInfo.CheckShared() { continue } - if !allocationInfo.CheckNumaBinding() { + if !allocationInfo.CheckNUMABinding() { // update container to target numa set for normal share cores p.updateNUMASetChangedContainers(numaSetChangedContainers, allocationInfo, numaWithoutNUMABindingPods) @@ -733,11 +673,11 @@ func (p *DynamicPolicy) adjustAllocationEntriesForDedicatedCores(numaSetChangedC } else if containerName == "" { general.Errorf("pod: %s has empty containerName entry", podUID) continue - } else if allocationInfo.QoSLevel != apiconsts.PodAnnotationQoSLevelDedicatedCores { + } else if !allocationInfo.CheckDedicated() { continue } - if !allocationInfo.CheckNumaBinding() { + if !allocationInfo.CheckNUMABinding() { // not to adjust NUMA binding containers // update container to target numa set for normal share cores p.updateNUMASetChangedContainers(numaSetChangedContainers, allocationInfo, numaWithoutNUMABindingPods) @@ -760,11 +700,11 @@ func (p *DynamicPolicy) adjustAllocationEntriesForSystemCores(numaSetChangedCont } else if containerName == "" { general.Errorf("pod: %s has empty containerName entry", podUID) continue - } else if allocationInfo.QoSLevel != apiconsts.PodAnnotationQoSLevelSystemCores { + } else if !allocationInfo.CheckSystem() { continue } - if allocationInfo.CheckNumaBinding() { + if allocationInfo.CheckNUMABinding() { // update container to target numa set for system_cores pod with NUMA binding // todo: currently we only update cpuset.mems for system_cores pods to NUMAs without dedicated and NUMA binding and NUMA exclusive pod, // in the future, we will update cpuset.mems for system_cores according to their cpuset_pool annotation. diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_async_handler.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_async_handler.go index 5790d7f52..5c0de52a8 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_async_handler.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_async_handler.go @@ -272,7 +272,7 @@ func (p *DynamicPolicy) checkMemorySet(_ *coreconfig.Configuration, for containerName, allocationInfo := range containerEntries { if allocationInfo == nil || !allocationInfo.CheckMainContainer() { continue - } else if allocationInfo.QoSLevel == consts.PodAnnotationQoSLevelSharedCores && + } else if allocationInfo.CheckShared() && p.getContainerRequestedMemoryBytes(allocationInfo) == 0 { general.Warningf("skip memset checking for pod: %s/%s container: %s with zero memory request", allocationInfo.PodNamespace, allocationInfo.PodName, containerName) @@ -315,7 +315,7 @@ func (p *DynamicPolicy) checkMemorySet(_ *coreconfig.Configuration, allocationInfo.NumaAllocationResult.String(), actualMemorySets[podUID][containerName].String()) // only do comparison for dedicated_cores with numa_binding to avoid effect of adjustment for shared_cores - if !allocationInfo.CheckNumaBinding() { + if !allocationInfo.CheckNUMABinding() { continue } @@ -341,7 +341,7 @@ func (p *DynamicPolicy) checkMemorySet(_ *coreconfig.Configuration, switch allocationInfo.QoSLevel { case consts.PodAnnotationQoSLevelDedicatedCores: - if allocationInfo.CheckNumaBinding() { + if allocationInfo.CheckNUMABinding() { if !memorySetOverlap && cset.Intersection(unionNUMABindingActualMemorySet).Size() != 0 { memorySetOverlap = true general.Errorf("pod: %s/%s, container: %s memset: %s overlaps with others", diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go index 105ea4073..c208530c3 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go @@ -183,26 +183,27 @@ func TestCheckMemorySet(t *testing.T) { v1.ResourceMemory: state.PodEntries{ "podUID": state.ContainerEntries{ "testName": &state.AllocationInfo{ - PodUid: "podUID", - PodNamespace: "testName", - PodName: "testName", - ContainerName: "testName", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "podUID", + PodNamespace: "testName", + PodName: "testName", + ContainerName: "testName", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 9663676416, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 9663676416, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, }, }, }, @@ -262,38 +263,40 @@ func TestSetMemoryMigrate(t *testing.T) { v1.ResourceMemory: state.PodEntries{ "podUID": state.ContainerEntries{ "testName": &state.AllocationInfo{ - PodUid: "podUID", - PodNamespace: "testName", - PodName: "testName", - ContainerName: "testName", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "podUID", + PodNamespace: "testName", + PodName: "testName", + ContainerName: "testName", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 9663676416, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 9663676416, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, }, }, "podUID-1": state.ContainerEntries{ "testName-1": &state.AllocationInfo{ - PodUid: "podUID-1", - PodNamespace: "testName-1", - PodName: "testName-1", - ContainerName: "testName-1", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "podUID-1", + PodNamespace: "testName-1", + PodName: "testName-1", + ContainerName: "testName-1", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, AggregatedQuantity: 9663676416, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ @@ -1976,13 +1979,14 @@ func TestGenerateResourcesMachineStateFromPodEntries(t *testing.T) { podEntries := state.PodEntries{ podUID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: podUID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: podUID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + }, AggregatedQuantity: 9663676416, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ @@ -2043,65 +2047,68 @@ func TestHandleAdvisorResp(t *testing.T) { v1.ResourceMemory: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, }, }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(1, 2, 3), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(1, 2, 3), }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(0, 1, 2, 3), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(0, 1, 2, 3), }, }, }, @@ -2159,27 +2166,28 @@ func TestHandleAdvisorResp(t *testing.T) { v1.ResourceMemory: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, ExtraControlKnobInfo: map[string]commonstate.ControlKnobInfo{ string(memoryadvisor.ControlKnobKeyMemoryLimitInBytes): { ControlKnobValue: "5516192768", @@ -2190,41 +2198,43 @@ func TestHandleAdvisorResp(t *testing.T) { }, pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(1, 2, 3), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(1, 2, 3), ExtraControlKnobInfo: make(map[string]commonstate.ControlKnobInfo), }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(2, 3), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(2, 3), ExtraControlKnobInfo: make(map[string]commonstate.ControlKnobInfo), }, }, @@ -2241,27 +2251,28 @@ func TestHandleAdvisorResp(t *testing.T) { PodEntries: state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, ExtraControlKnobInfo: map[string]commonstate.ControlKnobInfo{ string(memoryadvisor.ControlKnobKeyMemoryLimitInBytes): { ControlKnobValue: "5516192768", @@ -2281,21 +2292,22 @@ func TestHandleAdvisorResp(t *testing.T) { PodEntries: state.PodEntries{ pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(1), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(1), ExtraControlKnobInfo: make(map[string]commonstate.ControlKnobInfo), }, }, @@ -2310,41 +2322,43 @@ func TestHandleAdvisorResp(t *testing.T) { PodEntries: state.PodEntries{ pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(2), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(2), ExtraControlKnobInfo: make(map[string]commonstate.ControlKnobInfo), }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(2), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(2), ExtraControlKnobInfo: make(map[string]commonstate.ControlKnobInfo), }, }, @@ -2359,41 +2373,43 @@ func TestHandleAdvisorResp(t *testing.T) { PodEntries: state.PodEntries{ pod2UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod2UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(3), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod2UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(3), ExtraControlKnobInfo: make(map[string]commonstate.ControlKnobInfo), }, }, pod3UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod3UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(3), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod3UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelReclaimedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(3), ExtraControlKnobInfo: make(map[string]commonstate.ControlKnobInfo), }, }, @@ -2507,27 +2523,28 @@ func TestSetExtraControlKnobByConfigForAllocationInfo(t *testing.T) { }, }, inputAllocationInfo: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, ExtraControlKnobInfo: map[string]commonstate.ControlKnobInfo{ string(memoryadvisor.ControlKnobKeyMemoryLimitInBytes): { ControlKnobValue: "5516192768", @@ -2549,27 +2566,28 @@ func TestSetExtraControlKnobByConfigForAllocationInfo(t *testing.T) { }, }, outputAllocationInfo: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, ExtraControlKnobInfo: map[string]commonstate.ControlKnobInfo{ string(memoryadvisor.ControlKnobKeyMemoryLimitInBytes): { ControlKnobValue: "5516192768", @@ -2586,27 +2604,28 @@ func TestSetExtraControlKnobByConfigForAllocationInfo(t *testing.T) { }, }, inputAllocationInfo: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, }, extraControlKnobConfigs: map[string]commonstate.ExtraControlKnobConfig{ string(memoryadvisor.ControlKnobKeyMemoryLimitInBytes): { @@ -2622,27 +2641,28 @@ func TestSetExtraControlKnobByConfigForAllocationInfo(t *testing.T) { }, }, outputAllocationInfo: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, ExtraControlKnobInfo: map[string]commonstate.ControlKnobInfo{ string(memoryadvisor.ControlKnobKeyMemoryLimitInBytes): { ControlKnobValue: "6516192768", @@ -2655,27 +2675,28 @@ func TestSetExtraControlKnobByConfigForAllocationInfo(t *testing.T) { description: "set allocationInfo default control knob value by qos level", pod: &v1.Pod{}, inputAllocationInfo: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, }, extraControlKnobConfigs: map[string]commonstate.ExtraControlKnobConfig{ string(memoryadvisor.ControlKnobKeyMemoryLimitInBytes): { @@ -2691,27 +2712,28 @@ func TestSetExtraControlKnobByConfigForAllocationInfo(t *testing.T) { }, }, outputAllocationInfo: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, ExtraControlKnobInfo: map[string]commonstate.ControlKnobInfo{ string(memoryadvisor.ControlKnobKeyMemoryLimitInBytes): { ControlKnobValue: "1516192768", @@ -2786,27 +2808,28 @@ func TestSetExtraControlKnobByConfigs(t *testing.T) { podEntries := state.PodEntries{ pod1UID: state.ContainerEntries{ testName: &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, }, }, } @@ -2831,27 +2854,28 @@ func TestSetExtraControlKnobByConfigs(t *testing.T) { dynamicPolicy.setExtraControlKnobByConfigs(nil, nil, nil, nil, nil) expectedAllocationInfo := &state.AllocationInfo{ - PodUid: pod1UID, - PodNamespace: testName, - PodName: testName, - ContainerName: testName, - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: pod1UID, + PodNamespace: testName, + PodName: testName, + ContainerName: testName, + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, ExtraControlKnobInfo: map[string]commonstate.ControlKnobInfo{ string(memoryadvisor.ControlKnobKeyMemoryLimitInBytes): { ControlKnobValue: "1516192768", @@ -2963,26 +2987,27 @@ func TestRemoveContainer(t *testing.T) { v1.ResourceMemory: state.PodEntries{ podUID: state.ContainerEntries{ containerName: &state.AllocationInfo{ - PodUid: "podUID", - PodNamespace: "testName", - PodName: "testName", - ContainerName: "testName", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "podUID", + PodNamespace: "testName", + PodName: "testName", + ContainerName: "testName", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 9663676416, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 9663676416, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, }, }, }, @@ -3052,26 +3077,27 @@ func TestDynamicPolicy_ListContainers(t *testing.T) { as.Nil(err) allocationInfo := &state.AllocationInfo{ - PodUid: "podUID", - PodNamespace: "testName", - PodName: "testName", - ContainerName: "testName", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "podUID", + PodNamespace: "testName", + PodName: "testName", + ContainerName: "testName", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 9663676416, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 9663676416, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, } dynamicPolicy.state.SetPodResourceEntries(state.PodResourceEntries{ @@ -3158,39 +3184,41 @@ func TestDynamicPolicy_hasLastLevelEnhancementKey(t *testing.T) { v1.ResourceMemory: state.PodEntries{ "podUID": state.ContainerEntries{ "testName": &state.AllocationInfo{ - PodUid: "podUID", - PodNamespace: "testName", - PodName: "testName", - ContainerName: "testName", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "podUID", + PodNamespace: "testName", + PodName: "testName", + ContainerName: "testName", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementOOMPriority: strconv.Itoa(qos.DefaultDedicatedCoresOOMPriorityScore), + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 9663676416, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 9663676416, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementOOMPriority: strconv.Itoa(qos.DefaultDedicatedCoresOOMPriorityScore), - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, }, }, "podUID-1": state.ContainerEntries{ "testName-1": &state.AllocationInfo{ - PodUid: "podUID-1", - PodNamespace: "testName-1", - PodName: "testName-1", - ContainerName: "testName-1", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "podUID-1", + PodNamespace: "testName-1", + PodName: "testName-1", + ContainerName: "testName-1", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + }, AggregatedQuantity: 9663676416, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ @@ -3678,46 +3706,48 @@ func TestDynamicPolicy_adjustAllocationEntries(t *testing.T) { v1.ResourceMemory: state.PodEntries{ "test-pod-2-uid": state.ContainerEntries{ "test-container-2": &state.AllocationInfo{ - PodUid: "test-pod-2-uid", - PodNamespace: "test", - PodName: "test-pod-2", - ContainerName: "test-container-2", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, - RampUp: false, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-2-uid", + PodNamespace: "test", + PodName: "test-pod-2", + ContainerName: "test-container-2", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelDedicatedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, + }, + }, AggregatedQuantity: 7516192768, NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: 7516192768, }, - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, - consts.PodAnnotationMemoryEnhancementNumaExclusive: consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelDedicatedCores, - }, }, }, "test-pod-1-uid": state.ContainerEntries{ "test-container-1": &state.AllocationInfo{ - PodUid: "test-pod-1-uid", - PodNamespace: "test", - PodName: "test-pod-1", - ContainerName: "test-container-1", - ContainerType: pluginapi.ContainerType_MAIN.String(), - ContainerIndex: 0, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - RampUp: false, - NumaAllocationResult: machine.NewCPUSet(0, 1, 2, 3), - Annotations: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, - }, - Labels: map[string]string{ - consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-1-uid", + PodNamespace: "test", + PodName: "test-pod-1", + ContainerName: "test-container-1", + ContainerType: pluginapi.ContainerType_MAIN.String(), + ContainerIndex: 0, + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, + Labels: map[string]string{ + consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores, + }, }, + NumaAllocationResult: machine.NewCPUSet(0, 1, 2, 3), }, }, }, @@ -4062,11 +4092,13 @@ func Test_getContainerRequestedMemoryBytes(t *testing.T) { // check normal share cores pod1Allocation := &state.AllocationInfo{ - PodUid: "test-pod-1-uid", - PodName: "test-pod-1", - ContainerName: "test-container-1", + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-1-uid", + PodName: "test-pod-1", + ContainerName: "test-container-1", + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, AggregatedQuantity: 512, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, } dynamicPolicy.state.SetAllocationInfo(v1.ResourceMemory, "test-pod-1-uid", "test-pod-1", pod1Allocation) // case 1. pod spec not found, return the current allocated memory @@ -4116,16 +4148,18 @@ func Test_getContainerRequestedMemoryBytes(t *testing.T) { // check normal snb pod2Allocation := &state.AllocationInfo{ - PodUid: "test-pod-2-uid", - PodName: "test-pod-2", - ContainerName: "test-container-2", - AggregatedQuantity: 512, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-2-uid", + PodName: "test-pod-2", + ContainerName: "test-container-2", + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, }, + AggregatedQuantity: 512, } - as.Equalf(true, pod2Allocation.CheckNumaBinding(), "check numa binding failed") + as.Equalf(true, pod2Allocation.CheckNUMABinding(), "check numa binding failed") // case 1. check pod spec not found as.Equal(uint64(512), dynamicPolicy.getContainerRequestedMemoryBytes(pod2Allocation)) @@ -4207,27 +4241,31 @@ func Test_getContainerRequestedMemoryBytes(t *testing.T) { }) pod3Container3Allocation := &state.AllocationInfo{ - PodUid: "test-pod-3-uid", - PodName: "test-pod-3", - ContainerName: "test-container-3", - AggregatedQuantity: 512, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-3-uid", + PodName: "test-pod-3", + ContainerName: "test-container-3", + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + ContainerType: pluginapi.ContainerType_MAIN.String(), }, - ContainerType: pluginapi.ContainerType_MAIN.String(), + AggregatedQuantity: 512, } as.Equal(true, pod3Container3Allocation.CheckMainContainer()) pod3Container4Allocation := &state.AllocationInfo{ - PodUid: "test-pod-3-uid", - PodName: "test-pod-3", - ContainerName: "test-container-4", - AggregatedQuantity: 512, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-3-uid", + PodName: "test-pod-3", + ContainerName: "test-container-4", + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + ContainerType: pluginapi.ContainerType_SIDECAR.String(), }, - ContainerType: pluginapi.ContainerType_SIDECAR.String(), + AggregatedQuantity: 512, } as.Equalf(true, pod3Container4Allocation.CheckSideCar(), "check sidecar container failed") @@ -4408,25 +4446,29 @@ func Test_adjustAllocationEntries(t *testing.T) { metaServer.PodFetcher = podFetcher pod1Allocation := &state.AllocationInfo{ - PodUid: "test-pod-1-uid", - PodName: "test-pod-1", - ContainerName: "test-container-1", + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-1-uid", + PodName: "test-pod-1", + ContainerName: "test-container-1", + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + }, AggregatedQuantity: 512, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, NumaAllocationResult: machine.NewCPUSet(3), } dynamicPolicy.state.SetAllocationInfo(v1.ResourceMemory, "test-pod-1-uid", "test-container-1", pod1Allocation) pod2Allocation := &state.AllocationInfo{ - PodUid: "test-pod-2-uid", - PodName: "test-pod-2", - ContainerName: "test-container-2", - AggregatedQuantity: 2 * uint64(memorySize1G.Value()), - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - Annotations: map[string]string{ - "katalyst.kubewharf.io/qos_level": "shared_cores", - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-2-uid", + PodName: "test-pod-2", + ContainerName: "test-container-2", + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + "katalyst.kubewharf.io/qos_level": "shared_cores", + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, }, + AggregatedQuantity: 2 * uint64(memorySize1G.Value()), NumaAllocationResult: machine.NewCPUSet(0), TopologyAwareAllocations: map[int]uint64{ 0: uint64(2 * memorySize1G.Value()), @@ -4435,16 +4477,18 @@ func Test_adjustAllocationEntries(t *testing.T) { dynamicPolicy.state.SetAllocationInfo(v1.ResourceMemory, "test-pod-2-uid", "test-container-2", pod2Allocation) pod3Container3Allocation := &state.AllocationInfo{ - PodUid: "test-pod-3-uid", - PodName: "test-pod-3", - ContainerName: "test-container-3", - AggregatedQuantity: 3 * uint64(memorySize1G.Value()), - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - Annotations: map[string]string{ - "katalyst.kubewharf.io/qos_level": "shared_cores", - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-3-uid", + PodName: "test-pod-3", + ContainerName: "test-container-3", + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + "katalyst.kubewharf.io/qos_level": "shared_cores", + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + ContainerType: pluginapi.ContainerType_MAIN.String(), }, - ContainerType: pluginapi.ContainerType_MAIN.String(), + AggregatedQuantity: 3 * uint64(memorySize1G.Value()), NumaAllocationResult: machine.NewCPUSet(1), TopologyAwareAllocations: map[int]uint64{ 1: uint64(3 * memorySize1G.Value()), @@ -4454,35 +4498,39 @@ func Test_adjustAllocationEntries(t *testing.T) { dynamicPolicy.state.SetAllocationInfo(v1.ResourceMemory, "test-pod-3-uid", "test-container-3", pod3Container3Allocation) pod3Container4Allocation := &state.AllocationInfo{ - PodUid: "test-pod-3-uid", - PodName: "test-pod-3", - ContainerName: "test-container-4", - AggregatedQuantity: 0, - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - Annotations: map[string]string{ - "katalyst.kubewharf.io/qos_level": "shared_cores", - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-3-uid", + PodName: "test-pod-3", + ContainerName: "test-container-4", + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + "katalyst.kubewharf.io/qos_level": "shared_cores", + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + ContainerType: pluginapi.ContainerType_SIDECAR.String(), }, - ContainerType: pluginapi.ContainerType_SIDECAR.String(), + AggregatedQuantity: 0, NumaAllocationResult: machine.NewCPUSet(1), } as.Equalf(true, pod3Container4Allocation.CheckSideCar(), "check sidecar container failed") dynamicPolicy.state.SetAllocationInfo(v1.ResourceMemory, "test-pod-3-uid", "test-container-4", pod3Container4Allocation) pod4Container1Allocation := &state.AllocationInfo{ - PodUid: "test-pod-4-uid", - PodName: "test-pod-4", - ContainerName: "test-container-1", - AggregatedQuantity: uint64(memorySize1G.Value() / 2), - QoSLevel: consts.PodAnnotationQoSLevelSharedCores, - Annotations: map[string]string{ - consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + AllocationMeta: commonstate.AllocationMeta{ + PodUid: "test-pod-4-uid", + PodName: "test-pod-4", + ContainerName: "test-container-1", + QoSLevel: consts.PodAnnotationQoSLevelSharedCores, + Annotations: map[string]string{ + consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable, + }, + ContainerType: pluginapi.ContainerType_MAIN.String(), }, + AggregatedQuantity: uint64(memorySize1G.Value() / 2), NumaAllocationResult: machine.NewCPUSet(2), TopologyAwareAllocations: map[int]uint64{ 2: uint64(memorySize1G.Value() / 2), }, - ContainerType: pluginapi.ContainerType_MAIN.String(), } as.Equal(true, pod3Container3Allocation.CheckMainContainer()) dynamicPolicy.state.SetAllocationInfo(v1.ResourceMemory, "test-pod-4-uid", "test-container-1", pod4Container1Allocation) diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go index eb86180fd..5914f9c5c 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go @@ -25,7 +25,6 @@ import ( "k8s.io/klog/v2" pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" - "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/util" "github.com/kubewharf/katalyst-core/pkg/util/general" @@ -33,15 +32,8 @@ import ( ) type AllocationInfo struct { - PodUid string `json:"pod_uid,omitempty"` - PodNamespace string `json:"pod_namespace,omitempty"` - PodName string `json:"pod_name,omitempty"` - ContainerName string `json:"container_name,omitempty"` - ContainerType string `json:"container_type,omitempty"` - ContainerIndex uint64 `json:"container_index,omitempty"` - RampUp bool `json:"ramp_up,omitempty"` - PodRole string `json:"pod_role,omitempty"` - PodType string `json:"pod_type,omitempty"` + commonstate.AllocationMeta `json:",inline"` + AggregatedQuantity uint64 `json:"aggregated_quantity"` NumaAllocationResult machine.CPUSet `json:"numa_allocation_result,omitempty"` @@ -50,9 +42,6 @@ type AllocationInfo struct { // keyed by control knob names referred in memoryadvisor package ExtraControlKnobInfo map[string]commonstate.ControlKnobInfo `json:"extra_control_knob_info"` - Labels map[string]string `json:"labels"` - Annotations map[string]string `json:"annotations"` - QoSLevel string `json:"qosLevel"` } type ( @@ -95,20 +84,9 @@ func (ai *AllocationInfo) Clone() *AllocationInfo { } clone := &AllocationInfo{ - PodUid: ai.PodUid, - PodNamespace: ai.PodNamespace, - PodName: ai.PodName, - ContainerName: ai.ContainerName, - ContainerType: ai.ContainerType, - ContainerIndex: ai.ContainerIndex, - RampUp: ai.RampUp, - PodRole: ai.PodRole, - PodType: ai.PodType, + AllocationMeta: *ai.AllocationMeta.Clone(), AggregatedQuantity: ai.AggregatedQuantity, NumaAllocationResult: ai.NumaAllocationResult.Clone(), - QoSLevel: ai.QoSLevel, - Labels: general.DeepCopyMap(ai.Labels), - Annotations: general.DeepCopyMap(ai.Annotations), } if ai.TopologyAwareAllocations != nil { @@ -130,39 +108,6 @@ func (ai *AllocationInfo) Clone() *AllocationInfo { return clone } -// CheckNumaBinding returns true if the AllocationInfo is for pod with numa-binding enhancement -func (ai *AllocationInfo) CheckNumaBinding() bool { - return ai.Annotations[consts.PodAnnotationMemoryEnhancementNumaBinding] == - consts.PodAnnotationMemoryEnhancementNumaBindingEnable -} - -// CheckNumaExclusive returns true if the AllocationInfo is for pod with numa-exclusive enhancement -func (ai *AllocationInfo) CheckNumaExclusive() bool { - return ai.Annotations[consts.PodAnnotationMemoryEnhancementNumaExclusive] == - consts.PodAnnotationMemoryEnhancementNumaExclusiveEnable -} - -// CheckSharedOrDedicatedNUMABinding returns true if the AllocationInfo is for pod with -// shared-qos or dedicated-qos and numa-binding enhancement -func (ai *AllocationInfo) CheckSharedOrDedicatedNUMABinding() bool { - if ai == nil { - return false - } - - return (ai.QoSLevel == consts.PodAnnotationQoSLevelSharedCores && ai.CheckNumaBinding()) || - (ai.QoSLevel == consts.PodAnnotationQoSLevelDedicatedCores && ai.CheckNumaBinding()) -} - -// CheckMainContainer returns true if the AllocationInfo is for main container -func (ai *AllocationInfo) CheckMainContainer() bool { - return ai.ContainerType == pluginapi.ContainerType_MAIN.String() -} - -// CheckSideCar returns true if the AllocationInfo is for side-car container -func (ai *AllocationInfo) CheckSideCar() bool { - return ai.ContainerType == pluginapi.ContainerType_SIDECAR.String() -} - // GetResourceAllocation transforms resource allocation information into *pluginapi.ResourceAllocation func (ai *AllocationInfo) GetResourceAllocation() (*pluginapi.ResourceAllocation, error) { if ai == nil { @@ -309,8 +254,8 @@ func (ns *NUMANodeState) HasDedicatedNUMABindingAndNUMAExclusivePods() bool { for _, containerEntries := range ns.PodEntries { for _, allocationInfo := range containerEntries { - if allocationInfo != nil && allocationInfo.QoSLevel == consts.PodAnnotationQoSLevelDedicatedCores && - allocationInfo.CheckNumaBinding() && allocationInfo.CheckNumaExclusive() { + if allocationInfo != nil && allocationInfo.CheckDedicatedNUMABinding() && + allocationInfo.CheckNumaExclusive() { return true } } diff --git a/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/util.go b/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/util.go index 2203d3756..3112844ee 100644 --- a/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/util.go +++ b/pkg/agent/qrm-plugins/memory/dynamicpolicy/state/util.go @@ -22,10 +22,28 @@ import ( info "github.com/google/cadvisor/info/v1" v1 "k8s.io/api/core/v1" "k8s.io/klog/v2" + pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" + "github.com/kubewharf/katalyst-api/pkg/consts" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/util/machine" ) +// GenerateMemoryContainerAllocationMeta generates allocation metadata specifically for a memory resource request. +// This function is a wrapper around GenerateGenericContainerAllocationMeta, but it automatically computes the owner pool +// name using a QoS level and a specific annotation from the request. +// Parameters: +// - req: The resource request for memory, containing information about the pod and container. +// - qosLevel: The QoS (Quality of Service) level for the container. +// Returns: +// - A pointer to a commonstate.AllocationMeta struct generated based on the memory-specific logic. +func GenerateMemoryContainerAllocationMeta(req *pluginapi.ResourceRequest, qosLevel string) commonstate.AllocationMeta { + return commonstate.GenerateGenericContainerAllocationMeta(req, + // Determine the pool name based on QoS level and a CPU enhancement annotation from the request. + commonstate.GetSpecifiedPoolName(qosLevel, req.Annotations[consts.PodAnnotationCPUEnhancementCPUSet]), + qosLevel) +} + // GenerateMachineState returns NUMANodeResourcesMap based on // machine info and reserved resources func GenerateMachineState(machineInfo *info.MachineInfo, reserved map[v1.ResourceName]map[int]uint64) (NUMANodeResourcesMap, error) { diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor.go index 2f01a26ec..44b0ea501 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor.go @@ -32,7 +32,7 @@ import ( configapi "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" "github.com/kubewharf/katalyst-api/pkg/consts" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler" @@ -253,7 +253,7 @@ func (cra *cpuResourceAdvisor) updateWithIsolationGuardian(tryIsolation bool) er } // sanity check: if reserve pool exists - reservePoolInfo, ok := cra.metaCache.GetPoolInfo(state.PoolNameReserve) + reservePoolInfo, ok := cra.metaCache.GetPoolInfo(commonstate.PoolNameReserve) if !ok || reservePoolInfo == nil { klog.Errorf("[qosaware-cpu] skip update: reserve pool does not exist") return nil @@ -404,7 +404,7 @@ func (cra *cpuResourceAdvisor) assignContainersToRegions() error { cra.setContainerRegions(ci, regions) // update pool info - if ci.OwnerPoolName == state.PoolNameDedicated { + if ci.OwnerPoolName == commonstate.PoolNameDedicated { // dedicated pool should not exist in metaCache.poolEntries return true } else if ci.Isolated || cra.conf.IsolationForceEnablePools.Has(ci.OriginOwnerPoolName) { @@ -444,7 +444,7 @@ func (cra *cpuResourceAdvisor) assignToRegions(ci *types.ContainerInfo) ([]regio } func (cra *cpuResourceAdvisor) assignShareContainerToRegions(ci *types.ContainerInfo) ([]region.QoSRegion, error) { - numaID := state.FakedNUMAID + numaID := commonstate.FakedNUMAID if cra.conf.GenericSysAdvisorConfiguration.EnableShareCoresNumaBinding && ci.IsNumaBinding() { if ci.OwnerPoolName == "" { return nil, fmt.Errorf("empty owner pool name, %v/%v", ci.PodUID, ci.ContainerName) @@ -625,7 +625,7 @@ func (cra *cpuResourceAdvisor) emitMetrics(calculationResult types.InternalCPUCa _ = cra.emitter.StoreInt64(metricCPUAdvisorPoolSize, int64(size), metrics.MetricTypeNameRaw, metrics.MetricTag{Key: "name", Val: poolName}, metrics.MetricTag{Key: "numa_id", Val: strconv.Itoa(numaID)}, - metrics.MetricTag{Key: "pool_type", Val: state.GetPoolType(poolName)}) + metrics.MetricTag{Key: "pool_type", Val: commonstate.GetPoolType(poolName)}) } } } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_helper.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_helper.go index 97f4e25ab..5881073d9 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_helper.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_helper.go @@ -25,7 +25,7 @@ import ( "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" configapi "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region" @@ -151,7 +151,7 @@ func (cra *cpuResourceAdvisor) initializeHeadroomAssembler() error { // available = total - reserved pool - reserved for reclaim func (cra *cpuResourceAdvisor) updateNumasAvailableResource() { cra.numaAvailable = make(map[int]int) - reservePoolInfo, _ := cra.metaCache.GetPoolInfo(state.PoolNameReserve) + reservePoolInfo, _ := cra.metaCache.GetPoolInfo(commonstate.PoolNameReserve) cpusPerNuma := cra.metaServer.CPUsPerNuma() coreNumReservedForReclaim := cra.conf.GetDynamicConfiguration().MinReclaimedResourceForAllocate[v1.ResourceCPU] diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_test.go index cf32ceab5..2c489f047 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/advisor_test.go @@ -41,7 +41,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" katalyst_base "github.com/kubewharf/katalyst-core/cmd/base" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" @@ -177,8 +177,8 @@ func TestAdvisorUpdate(t *testing.T) { { name: "provision:reserve_pool_only", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -188,8 +188,8 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: true, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: {-1: 2}, - state.PoolNameReclaim: {-1: 94}, + commonstate.PoolNameReserve: {-1: 2}, + commonstate.PoolNameReclaim: {-1: 94}, }, }, headroomPolicies: map[configapi.QoSRegionType][]types.CPUHeadroomPolicyName{ @@ -201,15 +201,15 @@ func TestAdvisorUpdate(t *testing.T) { { name: "provision:single_small_share_pool", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("25"), @@ -217,7 +217,7 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("25"), @@ -235,9 +235,9 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: true, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: {-1: 2}, - state.PoolNameShare: {-1: 8}, - state.PoolNameReclaim: {-1: 86}, + commonstate.PoolNameReserve: {-1: 2}, + commonstate.PoolNameShare: {-1: 8}, + commonstate.PoolNameReclaim: {-1: 86}, }, }, wantHeadroom: resource.Quantity{}, @@ -245,15 +245,15 @@ func TestAdvisorUpdate(t *testing.T) { { name: "provision:single_large_share_pool", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1-23,48-71"), 1: machine.MustParse("25-47,72-95"), @@ -261,7 +261,7 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), @@ -279,9 +279,9 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: true, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: {-1: 2}, - state.PoolNameShare: {-1: 90}, - state.PoolNameReclaim: {-1: 4}, + commonstate.PoolNameReserve: {-1: 2}, + commonstate.PoolNameShare: {-1: 90}, + commonstate.PoolNameReclaim: {-1: 4}, }, }, wantHeadroom: resource.Quantity{}, @@ -289,15 +289,15 @@ func TestAdvisorUpdate(t *testing.T) { { name: "provision:multi_small_share_pools", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("25"), @@ -312,7 +312,7 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("25"), @@ -342,10 +342,10 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: true, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: {-1: 2}, - state.PoolNameShare: {-1: 6}, - "batch": {-1: 8}, - state.PoolNameReclaim: {-1: 80}, + commonstate.PoolNameReserve: {-1: 2}, + commonstate.PoolNameShare: {-1: 6}, + "batch": {-1: 8}, + commonstate.PoolNameReclaim: {-1: 80}, }, }, wantHeadroom: resource.Quantity{}, @@ -353,15 +353,15 @@ func TestAdvisorUpdate(t *testing.T) { { name: "provision:multi_large_share_pools", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1-5,48-52"), 1: machine.MustParse("25-29,72-76"), @@ -376,7 +376,7 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-5,48-52"), 1: machine.MustParse("25-29,72-76"), @@ -406,10 +406,10 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: true, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: {-1: 2}, - state.PoolNameShare: {-1: 30}, - "batch": {-1: 60}, - state.PoolNameReclaim: {-1: 4}, + commonstate.PoolNameReserve: {-1: 2}, + commonstate.PoolNameShare: {-1: 30}, + "batch": {-1: 60}, + commonstate.PoolNameReclaim: {-1: 4}, }, }, wantHeadroom: resource.Quantity{}, @@ -417,15 +417,15 @@ func TestAdvisorUpdate(t *testing.T) { { name: "provision:single_dedicated_numa_exclusive", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("70-71"), 1: machine.MustParse("25-46"), @@ -433,7 +433,7 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, state.PoolNameDedicated, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, commonstate.PoolNameDedicated, map[string]string{consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable}, map[int]machine.CPUSet{ 0: machine.MustParse("1-23,48-71"), @@ -452,10 +452,10 @@ func TestAdvisorUpdate(t *testing.T) { headroomAssembler: types.CPUHeadroomAssemblerDedicated, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: { + commonstate.PoolNameReserve: { -1: 2, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 4, -1: 47, }, @@ -467,15 +467,15 @@ func TestAdvisorUpdate(t *testing.T) { { name: "provision:single_dedicated_numa_exclusive with invalid headroom policy", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("70-71"), 1: machine.MustParse("25-46"), @@ -483,7 +483,7 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, state.PoolNameDedicated, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, commonstate.PoolNameDedicated, map[string]string{consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable}, map[int]machine.CPUSet{ 0: machine.MustParse("1-23,48-71"), @@ -505,10 +505,10 @@ func TestAdvisorUpdate(t *testing.T) { }, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: { + commonstate.PoolNameReserve: { -1: 2, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 4, -1: 47, }, @@ -521,15 +521,15 @@ func TestAdvisorUpdate(t *testing.T) { { name: "single_dedicated_numa_exclusive pod un-reclaimed", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("70-71"), 1: machine.MustParse("25-47,72-95"), @@ -537,7 +537,7 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, state.PoolNameDedicated, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, commonstate.PoolNameDedicated, map[string]string{consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable}, map[int]machine.CPUSet{ 0: machine.MustParse("1-23,48-71"), @@ -561,10 +561,10 @@ func TestAdvisorUpdate(t *testing.T) { }, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: { + commonstate.PoolNameReserve: { -1: 2, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 2, -1: 47, }, @@ -575,15 +575,15 @@ func TestAdvisorUpdate(t *testing.T) { { name: "single_dedicated_numa_exclusive pod with performance score", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("70-71"), 1: machine.MustParse("25-47,72-95"), @@ -591,7 +591,7 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, state.PoolNameDedicated, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, commonstate.PoolNameDedicated, map[string]string{consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable}, map[int]machine.CPUSet{ 0: machine.MustParse("1-23,48-71"), @@ -615,10 +615,10 @@ func TestAdvisorUpdate(t *testing.T) { }, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: { + commonstate.PoolNameReserve: { -1: 2, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 4, -1: 47, }, @@ -629,21 +629,21 @@ func TestAdvisorUpdate(t *testing.T) { { name: "dedicated_numa_exclusive_&_share", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.MustParse("25-30"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("70-71"), 1: machine.MustParse("31-47,72-95"), @@ -651,12 +651,12 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, state.PoolNameDedicated, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, commonstate.PoolNameDedicated, map[string]string{consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable}, map[int]machine.CPUSet{ 0: machine.MustParse("1-23,48-71"), }, 36), - makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 1: machine.MustParse("25-28"), }, 4), @@ -680,13 +680,13 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: true, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: { + commonstate.PoolNameReserve: { -1: 2, }, - state.PoolNameShare: { + commonstate.PoolNameShare: { -1: 6, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 4, -1: 41, }, @@ -697,21 +697,21 @@ func TestAdvisorUpdate(t *testing.T) { { name: "dedicated_numa_exclusive_&_share_disable_reclaim", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 1: machine.MustParse("25-30"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("70-71"), 1: machine.MustParse("31-47,72-95"), @@ -719,12 +719,12 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, state.PoolNameDedicated, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelDedicatedCores, commonstate.PoolNameDedicated, map[string]string{consts.PodAnnotationMemoryEnhancementNumaBinding: consts.PodAnnotationMemoryEnhancementNumaBindingEnable}, map[int]machine.CPUSet{ 0: machine.MustParse("1-23,48-71"), }, 36), - makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 1: machine.MustParse("25-28"), }, 4), @@ -748,13 +748,13 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: false, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: { + commonstate.PoolNameReserve: { -1: 2, }, - state.PoolNameShare: { + commonstate.PoolNameShare: { -1: 45, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 2, -1: 2, }, @@ -766,22 +766,22 @@ func TestAdvisorUpdate(t *testing.T) { name: "provision:single_large_share_pool&isolation_within_limits", preUpdate: true, pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1-21,48-69"), 1: machine.MustParse("25-45,72-93"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("22-23,70-71"), 1: machine.MustParse("46-47,94-95"), @@ -789,17 +789,17 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), }, 2), - makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), }, 20), - makeContainerInfo("uid3", "default", "pod3", "c3", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid3", "default", "pod3", "c3", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), @@ -831,10 +831,10 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: true, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: {-1: 2}, - state.PoolNameShare: {-1: 84}, - state.PoolNameReclaim: {-1: 8}, - "isolation-pod1": {-1: 2}, + commonstate.PoolNameReserve: {-1: 2}, + commonstate.PoolNameShare: {-1: 84}, + commonstate.PoolNameReclaim: {-1: 8}, + "isolation-pod1": {-1: 2}, }, }, wantHeadroom: resource.Quantity{}, @@ -892,15 +892,15 @@ func TestAdvisorUpdate(t *testing.T) { name: "provision:single_large_share_pool&isolation_exceed_limit", preUpdate: true, pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1-23,48-71"), 1: machine.MustParse("25-47,72-95"), @@ -908,22 +908,22 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), }, 8), - makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), }, 20), - makeContainerInfo("uid3", "default", "pod3", "c3", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid3", "default", "pod3", "c3", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), }, 30), - makeContainerInfo("uid4", "default", "pod4", "c4", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid4", "default", "pod4", "c4", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), @@ -962,9 +962,9 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: true, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: {-1: 2}, - state.PoolNameShare: {-1: 90}, - state.PoolNameReclaim: {-1: 4}, + commonstate.PoolNameReserve: {-1: 2}, + commonstate.PoolNameShare: {-1: 90}, + commonstate.PoolNameReclaim: {-1: 4}, }, }, wantHeadroom: resource.Quantity{}, @@ -995,15 +995,15 @@ func TestAdvisorUpdate(t *testing.T) { name: "provision:ignore_share_cores_without_request", preUpdate: true, pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1-23,48-71"), 1: machine.MustParse("25-47,72-95"), @@ -1011,22 +1011,22 @@ func TestAdvisorUpdate(t *testing.T) { }, }, containers: []*types.ContainerInfo{ - makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid1", "default", "pod1", "c1", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), }, 8), - makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid2", "default", "pod2", "c2", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), }, 20), - makeContainerInfo("uid3", "default", "pod3", "c3", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid3", "default", "pod3", "c3", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), }, 30), - makeContainerInfo("uid4", "default", "pod4", "c4", consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, + makeContainerInfo("uid4", "default", "pod4", "c4", consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{ 0: machine.MustParse("1-22,48-70"), 1: machine.MustParse("25-46,72-94"), @@ -1077,9 +1077,9 @@ func TestAdvisorUpdate(t *testing.T) { nodeEnableReclaim: true, wantInternalCalculationResult: types.InternalCPUCalculationResult{ PoolEntries: map[string]map[int]int{ - state.PoolNameReserve: {-1: 2}, - state.PoolNameShare: {-1: 90}, - state.PoolNameReclaim: {-1: 4}, + commonstate.PoolNameReserve: {-1: 2}, + commonstate.PoolNameShare: {-1: 90}, + commonstate.PoolNameReclaim: {-1: 4}, }, }, wantHeadroom: resource.Quantity{}, diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common.go index c378542dd..be0a50abc 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common.go @@ -24,7 +24,7 @@ import ( "k8s.io/klog/v2" configapi "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" @@ -104,7 +104,7 @@ func (ha *HeadroomAssemblerCommon) GetHeadroom() (resource.Quantity, error) { } // add non binding reclaim pool size - reclaimPoolInfo, reclaimPoolExist := ha.metaReader.GetPoolInfo(state.PoolNameReclaim) + reclaimPoolInfo, reclaimPoolExist := ha.metaReader.GetPoolInfo(commonstate.PoolNameReclaim) if reclaimPoolExist && reclaimPoolInfo != nil { reclaimPoolNUMAs := machine.GetCPUAssignmentNUMAs(reclaimPoolInfo.TopologyAwareAssignments) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common_test.go index e03428d02..1360a9017 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler/assembler_common_test.go @@ -33,7 +33,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1" "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" @@ -149,8 +149,8 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) { store.SetCgroupMetric("/kubepods/besteffort", pkgconsts.MetricCPUUsageCgroup, utilmetric.MetricData{Value: 3, Time: &now}) }, setMetaCache: func(cache *metacache.MetaCacheImp) { - err := cache.SetPoolInfo(state.PoolNameReclaim, &types.PoolInfo{ - PoolName: state.PoolNameReclaim, + err := cache.SetPoolInfo(commonstate.PoolNameReclaim, &types.PoolInfo{ + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0-9"), }, @@ -203,8 +203,8 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) { store.SetContainerMetric("pod1", "container1", metric_consts.MetricCPUUsageContainer, metric_util.MetricData{Value: 4}) }, setMetaCache: func(cache *metacache.MetaCacheImp) { - err := cache.SetPoolInfo(state.PoolNameReclaim, &types.PoolInfo{ - PoolName: state.PoolNameReclaim, + err := cache.SetPoolInfo(commonstate.PoolNameReclaim, &types.PoolInfo{ + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0-9"), }, @@ -260,8 +260,8 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) { store.SetCgroupMetric("/kubepods/besteffort", pkgconsts.MetricCPUUsageCgroup, utilmetric.MetricData{Value: 3, Time: &now}) }, setMetaCache: func(cache *metacache.MetaCacheImp) { - err := cache.SetPoolInfo(state.PoolNameReclaim, &types.PoolInfo{ - PoolName: state.PoolNameReclaim, + err := cache.SetPoolInfo(commonstate.PoolNameReclaim, &types.PoolInfo{ + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0-9"), }, @@ -308,8 +308,8 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) { store.SetCgroupMetric("/kubepods/besteffort", pkgconsts.MetricCPUUsageCgroup, utilmetric.MetricData{Value: 0, Time: &now}) }, setMetaCache: func(cache *metacache.MetaCacheImp) { - err := cache.SetPoolInfo(state.PoolNameReclaim, &types.PoolInfo{ - PoolName: state.PoolNameReclaim, + err := cache.SetPoolInfo(commonstate.PoolNameReclaim, &types.PoolInfo{ + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0-9"), }, @@ -356,8 +356,8 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) { store.SetCgroupMetric("/kubepods/besteffort", pkgconsts.MetricCPUUsageCgroup, utilmetric.MetricData{Value: 9, Time: &now}) }, setMetaCache: func(cache *metacache.MetaCacheImp) { - err := cache.SetPoolInfo(state.PoolNameReclaim, &types.PoolInfo{ - PoolName: state.PoolNameReclaim, + err := cache.SetPoolInfo(commonstate.PoolNameReclaim, &types.PoolInfo{ + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0-9"), }, @@ -406,8 +406,8 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) { store.SetCgroupMetric("/kubepods/besteffort", pkgconsts.MetricCPUUsageCgroup, utilmetric.MetricData{Value: 28.8, Time: &now}) }, setMetaCache: func(cache *metacache.MetaCacheImp) { - err := cache.SetPoolInfo(state.PoolNameReclaim, &types.PoolInfo{ - PoolName: state.PoolNameReclaim, + err := cache.SetPoolInfo(commonstate.PoolNameReclaim, &types.PoolInfo{ + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0-85"), }, @@ -460,8 +460,8 @@ func TestHeadroomAssemblerCommon_GetHeadroom(t *testing.T) { store.SetCgroupMetric("/kubepods/besteffort", pkgconsts.MetricCPUUsageCgroup, utilmetric.MetricData{Value: 28.8, Time: &now}) }, setMetaCache: func(cache *metacache.MetaCacheImp) { - err := cache.SetPoolInfo(state.PoolNameReclaim, &types.PoolInfo{ - PoolName: state.PoolNameReclaim, + err := cache.SetPoolInfo(commonstate.PoolNameReclaim, &types.PoolInfo{ + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0-85"), }, diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler/assembler_common.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler/assembler_common.go index 4b45fcbfd..cb8e04b4a 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler/assembler_common.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler/assembler_common.go @@ -24,7 +24,7 @@ import ( "k8s.io/klog/v2" configapi "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/helper" @@ -78,8 +78,8 @@ func (pa *ProvisionAssemblerCommon) AssembleProvision() (types.InternalCPUCalcul } // fill in reserve pool entry - reservePoolSize, _ := pa.metaReader.GetPoolSize(state.PoolNameReserve) - calculationResult.SetPoolEntry(state.PoolNameReserve, state.FakedNUMAID, reservePoolSize) + reservePoolSize, _ := pa.metaReader.GetPoolSize(commonstate.PoolNameReserve) + calculationResult.SetPoolEntry(commonstate.PoolNameReserve, commonstate.FakedNUMAID, reservePoolSize) shares := 0 isolationUppers := 0 @@ -151,7 +151,7 @@ func (pa *ProvisionAssemblerCommon) AssembleProvision() (types.InternalCPUCalcul } reclaimedCoresSize = general.Max(pa.getNumasReservedForReclaim(r.GetBindingNumas()), reclaimedCoresAvail) reclaimedCoresSize = general.Min(reclaimedCoresSize, poolSizes[r.OwnerPoolName()]) - calculationResult.SetPoolOverlapInfo(state.PoolNameReclaim, regionNuma, r.OwnerPoolName(), reclaimedCoresSize) + calculationResult.SetPoolOverlapInfo(commonstate.PoolNameReclaim, regionNuma, r.OwnerPoolName(), reclaimedCoresSize) } else { reclaimedCoresSize = available - general.SumUpMapValues(poolSizes) + reservedForReclaim if !nodeEnableReclaim { @@ -159,7 +159,7 @@ func (pa *ProvisionAssemblerCommon) AssembleProvision() (types.InternalCPUCalcul } } - calculationResult.SetPoolEntry(state.PoolNameReclaim, regionNuma, reclaimedCoresSize) + calculationResult.SetPoolEntry(commonstate.PoolNameReclaim, regionNuma, reclaimedCoresSize) } else { // save raw share pool sizes sharePoolRequirements[r.OwnerPoolName()] = int(controlKnob[configapi.ControlKnobNonReclaimedCPURequirement].Value) @@ -172,7 +172,7 @@ func (pa *ProvisionAssemblerCommon) AssembleProvision() (types.InternalCPUCalcul if shareRegions := regionHelper.GetRegions(regionNuma, configapi.QoSRegionTypeShare); len(shareRegions) == 0 { calculationResult.SetPoolEntry(r.Name(), regionNuma, int(controlKnob[configapi.ControlKnobNonReclaimedCPURequirementUpper].Value)) - _, ok := calculationResult.GetPoolEntry(state.PoolNameReclaim, regionNuma) + _, ok := calculationResult.GetPoolEntry(commonstate.PoolNameReclaim, regionNuma) if !ok { available := getNUMAsResource(*pa.numaAvailable, r.GetBindingNumas()) reservedForReclaim := getNUMAsResource(*pa.reservedForReclaim, r.GetBindingNumas()) @@ -187,7 +187,7 @@ func (pa *ProvisionAssemblerCommon) AssembleProvision() (types.InternalCPUCalcul isolationSizes += int(ck[configapi.ControlKnobNonReclaimedCPURequirementUpper].Value) } reclaimedCoresSize := general.Max(available-isolationSizes, 0) + reservedForReclaim - calculationResult.SetPoolEntry(state.PoolNameReclaim, regionNuma, reclaimedCoresSize) + calculationResult.SetPoolEntry(commonstate.PoolNameReclaim, regionNuma, reclaimedCoresSize) } } } else { @@ -215,14 +215,14 @@ func (pa *ProvisionAssemblerCommon) AssembleProvision() (types.InternalCPUCalcul // fill in reclaim pool entry for dedicated numa exclusive regions if !enableReclaim { if reservedForReclaim > 0 { - calculationResult.SetPoolEntry(state.PoolNameReclaim, regionNuma, reservedForReclaim) + calculationResult.SetPoolEntry(commonstate.PoolNameReclaim, regionNuma, reservedForReclaim) } } else { available := getNUMAsResource(*pa.numaAvailable, r.GetBindingNumas()) nonReclaimRequirement := int(controlKnob[configapi.ControlKnobNonReclaimedCPURequirement].Value) reclaimed := available - nonReclaimRequirement + reservedForReclaim - calculationResult.SetPoolEntry(state.PoolNameReclaim, regionNuma, reclaimed) + calculationResult.SetPoolEntry(commonstate.PoolNameReclaim, regionNuma, reclaimed) klog.InfoS("assemble info", "regionName", r.Name(), "reclaimed", reclaimed, "available", available, "nonReclaimRequirement", nonReclaimRequirement, @@ -255,7 +255,7 @@ func (pa *ProvisionAssemblerCommon) AssembleProvision() (types.InternalCPUCalcul // fill in regulated share-and-isolated pool entries for poolName, poolSize := range shareAndIsolatePoolSizes { - calculationResult.SetPoolEntry(poolName, state.FakedNUMAID, poolSize) + calculationResult.SetPoolEntry(poolName, commonstate.FakedNUMAID, poolSize) } var reclaimPoolSizeOfNonBindingNUMAs int @@ -284,7 +284,7 @@ func (pa *ProvisionAssemblerCommon) AssembleProvision() (types.InternalCPUCalcul } for overlapPoolName, size := range sharedOverlapReclaimSize { - calculationResult.SetPoolOverlapInfo(state.PoolNameReclaim, state.FakedNUMAID, overlapPoolName, size) + calculationResult.SetPoolOverlapInfo(commonstate.PoolNameReclaim, commonstate.FakedNUMAID, overlapPoolName, size) } } } else { @@ -294,7 +294,7 @@ func (pa *ProvisionAssemblerCommon) AssembleProvision() (types.InternalCPUCalcul } } - calculationResult.SetPoolEntry(state.PoolNameReclaim, state.FakedNUMAID, reclaimPoolSizeOfNonBindingNUMAs) + calculationResult.SetPoolEntry(commonstate.PoolNameReclaim, commonstate.FakedNUMAID, reclaimPoolSizeOfNonBindingNUMAs) return calculationResult, nil } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_load.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_load.go index 457ac4016..2eb1f7efb 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_load.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_load.go @@ -25,7 +25,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "github.com/kubewharf/katalyst-api/pkg/consts" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/config" @@ -82,7 +82,7 @@ func NewLoadIsolator(conf *config.Configuration, _ interface{}, emitter metrics. metaReader: metaCache, metaServer: metaServer, - configTranslator: general.NewCommonSuffixTranslator(state.NUMAPoolInfix), + configTranslator: general.NewCommonSuffixTranslator(commonstate.NUMAPoolInfix), } } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_test.go index fe19ae11d..6b10160be 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation/isolator_test.go @@ -33,7 +33,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" katalyst_base "github.com/kubewharf/katalyst-core/cmd/base" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/qosaware/resource/cpu" @@ -170,9 +170,9 @@ func TestLoadIsolator(t *testing.T) { // construct containers containers := []*types.ContainerInfo{ makeContainerInfo("uid1", "default", "pod1", "c1-1", - consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), + consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), makeContainerInfo("uid1", "default", "pod1", "c1-2", - consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, map[int]machine.CPUSet{}, 4, 0), + consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{}, 4, 0), makeContainerInfo("uid2", "default", "pod2", "c2-1", consts.PodAnnotationQoSLevelSharedCores, "batch", nil, map[int]machine.CPUSet{}, 0, 4), @@ -190,16 +190,16 @@ func TestLoadIsolator(t *testing.T) { consts.PodAnnotationQoSLevelDedicatedCores, "", nil, map[int]machine.CPUSet{}, 4, 4), makeContainerInfo("uid5", "default", "pod5", "c5-1", - consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), + consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), makeContainerInfo("uid5", "default", "pod5", "c5-2", - consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), + consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), makeContainerInfo("uid6", "default", "pod6", "c6-1", - consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), + consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), makeContainerInfo("uid6", "default", "pod6", "c6-2", - consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), + consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{}, 0, 4), makeContainerInfo("uid6", "default", "pod6", "c6-3", - consts.PodAnnotationQoSLevelSharedCores, state.PoolNameShare, nil, map[int]machine.CPUSet{}, 4, 0), + consts.PodAnnotationQoSLevelSharedCores, commonstate.PoolNameShare, nil, map[int]machine.CPUSet{}, 4, 0), makeContainerInfo("uid7", "default", "pod7", "c7-1", consts.PodAnnotationQoSLevelSharedCores, "batch", nil, map[int]machine.CPUSet{}, 0, 4), @@ -214,10 +214,10 @@ func TestLoadIsolator(t *testing.T) { // construct pools pools := map[string]*types.PoolInfo{ - state.PoolNameReserve: {}, - state.PoolNameShare: {}, - "batch": {}, - "flink": {}, + commonstate.PoolNameReserve: {}, + commonstate.PoolNameShare: {}, + "batch": {}, + "flink": {}, } for poolName, poolInfo := range pools { err := metaCache.SetPoolInfo(poolName, poolInfo) @@ -273,7 +273,7 @@ func TestLoadIsolator(t *testing.T) { IsolatedMaxPoolResourceRatios: map[string]float32{}, IsolatedMaxPodRatio: 1, IsolationDisabled: false, - IsolationDisabledPools: sets.NewString(state.PoolNameShare), + IsolationDisabledPools: sets.NewString(commonstate.PoolNameShare), }, expects: []string{"uid2"}, }, diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region.go index 64c80d461..360c52a2f 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region.go @@ -18,7 +18,7 @@ package region import ( configapi "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/metrics" "github.com/kubewharf/katalyst-core/pkg/util/machine" @@ -93,7 +93,7 @@ func GetRegionBasicMetricTags(r QoSRegion) []metrics.MetricTag { {Key: "region_name", Val: r.Name()}, {Key: "region_type", Val: string(r.Type())}, {Key: "owner_pool_name", Val: r.OwnerPoolName()}, - {Key: "pool_type", Val: state.GetPoolType(r.OwnerPoolName())}, + {Key: "pool_type", Val: commonstate.GetPoolType(r.OwnerPoolName())}, {Key: "binding_numas", Val: r.GetBindingNumas().String()}, {Key: "provision_policy_prior", Val: string(provisionPolicyPrior)}, {Key: "provision_policy_in_use", Val: string(provisionPolicyInUse)}, diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_dedicated_numa_exclusive.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_dedicated_numa_exclusive.go index 718b12c99..66f9a9fb9 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_dedicated_numa_exclusive.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_dedicated_numa_exclusive.go @@ -26,7 +26,7 @@ import ( configapi "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" workloadapis "github.com/kubewharf/katalyst-api/pkg/apis/workload/v1alpha1" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/helper" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" @@ -176,7 +176,7 @@ out: func (r *QoSRegionDedicatedNumaExclusive) getControlKnobs() types.ControlKnob { reclaimedCPUSize := 0 - if reclaimedInfo, ok := r.metaReader.GetPoolInfo(state.PoolNameReclaim); ok { + if reclaimedInfo, ok := r.metaReader.GetPoolInfo(commonstate.PoolNameReclaim); ok { for _, numaID := range r.bindingNumas.ToSliceInt() { reclaimedCPUSize += reclaimedInfo.TopologyAwareAssignments[numaID].Size() } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_isolation.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_isolation.go index 65a8c6046..1733cc778 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_isolation.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_isolation.go @@ -20,7 +20,7 @@ import ( "k8s.io/apimachinery/pkg/util/uuid" configapi "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/config" @@ -50,7 +50,7 @@ func NewQoSRegionIsolation(ci *types.ContainerInfo, customRegionName string, con } } - isNumaBinding := numaID != state.FakedNUMAID + isNumaBinding := numaID != commonstate.FakedNUMAID ownerPoolName := isolationRegionDefaultOwnerPoolName if isNumaBinding { ownerPoolName = isolationRegionNUMAOwnerPoolName diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_share.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_share.go index 4b8408ab1..309dd27c0 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_share.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_share.go @@ -25,7 +25,7 @@ import ( configapi "github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1" "github.com/kubewharf/katalyst-api/pkg/apis/workload/v1alpha1" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/config" @@ -62,7 +62,7 @@ func NewQoSRegionShare(ci *types.ContainerInfo, conf *config.Configuration, extr // When receive a new pod with new share pool from QRM, advisor should create a new share region with OwnerPoolName (OriginOwnerPoolName == OwnerPoolName). // Case 2. create a share pool with OriginOwnerPoolName: // When put isolation pods back to share pool, advisor should create a new share region with OriginOwnerPoolName (OriginOwnerPoolName != OwnerPoolName). - isNumaBinding := numaID != state.FakedNUMAID + isNumaBinding := numaID != commonstate.FakedNUMAID r := &QoSRegionShare{ QoSRegionBase: NewQoSRegionBase(regionName, ci.OriginOwnerPoolName, configapi.QoSRegionTypeShare, conf, extraConf, isNumaBinding, metaReader, metaServer, emitter), } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_test.go index 3f2263b0b..0bc4e6258 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/region_test.go @@ -32,7 +32,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" katalyst_base "github.com/kubewharf/katalyst-core/cmd/base" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/metaserver" @@ -183,7 +183,7 @@ func TestIsNumaBinding(t *testing.T) { QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RegionNames: sets.NewString("share"), } - share2 := NewQoSRegionShare(&ci2, conf, nil, state.FakedNUMAID, metaCache, metaServer, metrics.DummyMetrics{}) + share2 := NewQoSRegionShare(&ci2, conf, nil, commonstate.FakedNUMAID, metaCache, metaServer, metrics.DummyMetrics{}) require.False(t, share2.IsNumaBinding(), "test IsNumaBinding failed") ci3 := types.ContainerInfo{ @@ -199,7 +199,7 @@ func TestIsNumaBinding(t *testing.T) { RegionNames: sets.NewString("isolation-1"), Isolated: true, } - isolation2 := NewQoSRegionIsolation(&ci4, "isolation-1", conf, nil, state.FakedNUMAID, metaCache, metaServer, metrics.DummyMetrics{}) + isolation2 := NewQoSRegionIsolation(&ci4, "isolation-1", conf, nil, commonstate.FakedNUMAID, metaCache, metaServer, metrics.DummyMetrics{}) require.False(t, isolation2.IsNumaBinding(), "test IsNumaBinding failed") } @@ -269,7 +269,7 @@ func TestRestrictProvisionControlKnob(t *testing.T) { QoSLevel: consts.PodAnnotationQoSLevelSharedCores, RegionNames: sets.NewString("share"), } - share := NewQoSRegionShare(&ci, conf, nil, state.FakedNUMAID, metaCache, metaServer, metrics.DummyMetrics{}) + share := NewQoSRegionShare(&ci, conf, nil, commonstate.FakedNUMAID, metaCache, metaServer, metrics.DummyMetrics{}) restrictedControlKnobs := share.(*QoSRegionShare).restrictProvisionControlKnob(tt.originControlKnob) assert.Equal(t, tt.wantControlKnob, restrictedControlKnobs) }) diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/memory_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/memory_test.go index 6ec673991..531ef5103 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/memory_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/helper/memory_test.go @@ -29,7 +29,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options" - qrmstate "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/config" @@ -45,10 +45,10 @@ import ( ) var qosLevel2PoolName = map[string]string{ - consts.PodAnnotationQoSLevelSharedCores: qrmstate.PoolNameShare, - consts.PodAnnotationQoSLevelReclaimedCores: qrmstate.PoolNameReclaim, - consts.PodAnnotationQoSLevelSystemCores: qrmstate.PoolNameReserve, - consts.PodAnnotationQoSLevelDedicatedCores: qrmstate.PoolNameDedicated, + consts.PodAnnotationQoSLevelSharedCores: commonstate.PoolNameShare, + consts.PodAnnotationQoSLevelReclaimedCores: commonstate.PoolNameReclaim, + consts.PodAnnotationQoSLevelSystemCores: commonstate.PoolNameReserve, + consts.PodAnnotationQoSLevelDedicatedCores: commonstate.PoolNameDedicated, } func makeContainerInfo(podUID, namespace, podName, containerName, qoSLevel string, annotations map[string]string, diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/advisor_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/advisor_test.go index d2bfb25f9..33ffced3d 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/advisor_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/advisor_test.go @@ -39,8 +39,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" katalyst_base "github.com/kubewharf/katalyst-core/cmd/base" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" - qrmstate "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/memoryadvisor" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" memadvisorplugin "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin" @@ -61,10 +60,10 @@ import ( ) var qosLevel2PoolName = map[string]string{ - consts.PodAnnotationQoSLevelSharedCores: qrmstate.PoolNameShare, - consts.PodAnnotationQoSLevelReclaimedCores: qrmstate.PoolNameReclaim, - consts.PodAnnotationQoSLevelSystemCores: qrmstate.PoolNameReserve, - consts.PodAnnotationQoSLevelDedicatedCores: qrmstate.PoolNameDedicated, + consts.PodAnnotationQoSLevelSharedCores: commonstate.PoolNameShare, + consts.PodAnnotationQoSLevelReclaimedCores: commonstate.PoolNameReclaim, + consts.PodAnnotationQoSLevelSystemCores: commonstate.PoolNameReserve, + consts.PodAnnotationQoSLevelDedicatedCores: commonstate.PoolNameDedicated, } func makeContainerInfo(podUID, namespace, podName, containerName, qoSLevel string, annotations map[string]string, @@ -454,8 +453,8 @@ func TestUpdate(t *testing.T) { { name: "reserve pool only", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -475,8 +474,8 @@ func TestUpdate(t *testing.T) { { name: "normal case", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -486,8 +485,8 @@ func TestUpdate(t *testing.T) { 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("25"), @@ -523,8 +522,8 @@ func TestUpdate(t *testing.T) { { name: "reclaimed disable case", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -534,8 +533,8 @@ func TestUpdate(t *testing.T) { 1: machine.MustParse("24"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("25"), @@ -571,8 +570,8 @@ func TestUpdate(t *testing.T) { { name: "node pressure drop cache", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -643,8 +642,8 @@ func TestUpdate(t *testing.T) { { name: "numa0 pressure drop cache", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -739,8 +738,8 @@ func TestUpdate(t *testing.T) { { name: "set reclaimed group memory limit(succeeded)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -771,8 +770,8 @@ func TestUpdate(t *testing.T) { { name: "set reclaimed group memory limit(failed)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -796,8 +795,8 @@ func TestUpdate(t *testing.T) { { name: "memory offloading", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -1275,8 +1274,8 @@ func TestUpdate(t *testing.T) { { name: "bind memset", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -1339,8 +1338,8 @@ func TestUpdate(t *testing.T) { { name: "bind memset(numa1 pressure)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -1444,8 +1443,8 @@ func TestUpdate(t *testing.T) { { name: "bind memset(numa1-3 pressure)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("24"), @@ -1549,8 +1548,8 @@ func TestUpdate(t *testing.T) { { name: "numa memory balance(grace balance)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("0"), @@ -1564,8 +1563,8 @@ func TestUpdate(t *testing.T) { 3: machine.MustParse("0"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("24"), @@ -1575,8 +1574,8 @@ func TestUpdate(t *testing.T) { 1: machine.MustParse("24"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("2"), 1: machine.MustParse("25"), @@ -1708,8 +1707,8 @@ func TestUpdate(t *testing.T) { { name: "numa memory balance(force balance,evict)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("0"), @@ -1723,8 +1722,8 @@ func TestUpdate(t *testing.T) { 3: machine.MustParse("0"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("24"), @@ -1734,8 +1733,8 @@ func TestUpdate(t *testing.T) { 1: machine.MustParse("24"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("2"), 1: machine.MustParse("25"), @@ -1861,8 +1860,8 @@ func TestUpdate(t *testing.T) { { name: "numa memory balance(force balance,no reclaimed pod)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("0"), @@ -1876,8 +1875,8 @@ func TestUpdate(t *testing.T) { 3: machine.MustParse("0"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("24"), @@ -1993,8 +1992,8 @@ func TestUpdate(t *testing.T) { { name: "numa memory balance(grace balance,latency gap)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("0"), @@ -2008,8 +2007,8 @@ func TestUpdate(t *testing.T) { 3: machine.MustParse("0"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("24"), @@ -2019,8 +2018,8 @@ func TestUpdate(t *testing.T) { 1: machine.MustParse("24"), }, }, - state.PoolNameReclaim: { - PoolName: state.PoolNameReclaim, + commonstate.PoolNameReclaim: { + PoolName: commonstate.PoolNameReclaim, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("2"), 1: machine.MustParse("25"), @@ -2152,8 +2151,8 @@ func TestUpdate(t *testing.T) { { name: "numa memory balance(force balance,bandwidth level medium)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("0"), @@ -2167,8 +2166,8 @@ func TestUpdate(t *testing.T) { 3: machine.MustParse("0"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("24"), @@ -2286,8 +2285,8 @@ func TestUpdate(t *testing.T) { { name: "numa memory balance(force balance,bandwidth level low)", pools: map[string]*types.PoolInfo{ - state.PoolNameReserve: { - PoolName: state.PoolNameReserve, + commonstate.PoolNameReserve: { + PoolName: commonstate.PoolNameReserve, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("0"), 1: machine.MustParse("0"), @@ -2301,8 +2300,8 @@ func TestUpdate(t *testing.T) { 3: machine.MustParse("0"), }, }, - state.PoolNameShare: { - PoolName: state.PoolNameShare, + commonstate.PoolNameShare: { + PoolName: commonstate.PoolNameShare, TopologyAwareAssignments: map[int]machine.CPUSet{ 0: machine.MustParse("1"), 1: machine.MustParse("24"), diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_canonical_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_canonical_test.go index 36967ef03..878558edc 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_canonical_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/headroompolicy/policy_canonical_test.go @@ -32,7 +32,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options" - qrmstate "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/config" @@ -52,10 +52,10 @@ import ( ) var qosLevel2PoolName = map[string]string{ - consts.PodAnnotationQoSLevelSharedCores: qrmstate.PoolNameShare, - consts.PodAnnotationQoSLevelReclaimedCores: qrmstate.PoolNameReclaim, - consts.PodAnnotationQoSLevelSystemCores: qrmstate.PoolNameReserve, - consts.PodAnnotationQoSLevelDedicatedCores: qrmstate.PoolNameDedicated, + consts.PodAnnotationQoSLevelSharedCores: commonstate.PoolNameShare, + consts.PodAnnotationQoSLevelReclaimedCores: commonstate.PoolNameReclaim, + consts.PodAnnotationQoSLevelSystemCores: commonstate.PoolNameReserve, + consts.PodAnnotationQoSLevelDedicatedCores: commonstate.PoolNameDedicated, } func generateTestConfiguration(t *testing.T, checkpointDir, stateFileDir string) *config.Configuration { diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/cache_reaper.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/cache_reaper.go index 7c35fe165..71fc5b246 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/cache_reaper.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/cache_reaper.go @@ -24,7 +24,7 @@ import ( "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1" apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/memoryadvisor" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" @@ -143,7 +143,7 @@ func (cp *cacheReaper) Reconcile(status *types.MemoryPressureStatus) error { containers := make([]*types.ContainerInfo, 0) cp.metaReader.RangeContainer(func(podUID string, containerName string, containerInfo *types.ContainerInfo) bool { - if cp.reclaimedContainersFilter(containerInfo, state.FakedNUMAID, minCacheUtilizationThreshold) { + if cp.reclaimedContainersFilter(containerInfo, commonstate.FakedNUMAID, minCacheUtilizationThreshold) { containers = append(containers, containerInfo) } return true diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/memory_balancer.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/memory_balancer.go index 56e923551..0cda15f8f 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/memory_balancer.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/memory_balancer.go @@ -33,7 +33,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/plugins/registration" "github.com/kubewharf/katalyst-api/pkg/plugins/skeleton" pluginapi "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/memoryadvisor" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" @@ -381,7 +381,7 @@ func (m *memoryBalancer) getBalanceInfo() (balanceInfo *BalanceInfo, err error) } func (m *memoryBalancer) getEvictPods(sourceNuma *NumaLatencyInfo) ([]EvictPod, error) { - reclaimedPods, err := m.getPodsInPool(state.PoolNameReclaim) + reclaimedPods, err := m.getPodsInPool(commonstate.PoolNameReclaim) if err != nil { return nil, err } @@ -410,7 +410,7 @@ func (m *memoryBalancer) getDestNumaList(orderedDestNumaList []NumaInfo, sourceN func (m *memoryBalancer) getCandidatePods(poolName string) (reclaimedPods, poolPods []*v1.Pod, err error) { var getPodErr error - reclaimedPods, getPodErr = m.getPodsInPool(state.PoolNameReclaim) + reclaimedPods, getPodErr = m.getPodsInPool(commonstate.PoolNameReclaim) if getPodErr != nil { err = getPodErr return @@ -605,7 +605,7 @@ func (m *memoryBalancer) getBalancePodsForPool(poolName string, srcNuma *NumaLat func (m *memoryBalancer) getBalancePods(supportPools []string, srcNuma *NumaLatencyInfo, destNumas []NumaInfo) ([]BalancePod, float64, error) { var totalRSS float64 = 0 poolPodSortList := make([]PodSort, 0) - reclaimedPodSortList, err := m.getBalancePodsForPool(state.PoolNameReclaim, srcNuma, destNumas, m.conf.BalancedReclaimedPodSourceNumaRSSMin, m.conf.BalancedReclaimedPodSourceNumaRSSMax) + reclaimedPodSortList, err := m.getBalancePodsForPool(commonstate.PoolNameReclaim, srcNuma, destNumas, m.conf.BalancedReclaimedPodSourceNumaRSSMin, m.conf.BalancedReclaimedPodSourceNumaRSSMax) if err != nil { return nil, totalRSS, err } diff --git a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/provisioner/policy/policy_canonical_test.go b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/provisioner/policy/policy_canonical_test.go index 9580d9718..f4e591975 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/provisioner/policy/policy_canonical_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/provisioner/policy/policy_canonical_test.go @@ -30,7 +30,7 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options" - qrmstate "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/config" @@ -48,10 +48,10 @@ import ( ) var qosLevel2PoolName = map[string]string{ - consts.PodAnnotationQoSLevelSharedCores: qrmstate.PoolNameShare, - consts.PodAnnotationQoSLevelReclaimedCores: qrmstate.PoolNameReclaim, - consts.PodAnnotationQoSLevelSystemCores: qrmstate.PoolNameReserve, - consts.PodAnnotationQoSLevelDedicatedCores: qrmstate.PoolNameDedicated, + consts.PodAnnotationQoSLevelSharedCores: commonstate.PoolNameShare, + consts.PodAnnotationQoSLevelReclaimedCores: commonstate.PoolNameReclaim, + consts.PodAnnotationQoSLevelSystemCores: commonstate.PoolNameReserve, + consts.PodAnnotationQoSLevelDedicatedCores: commonstate.PoolNameDedicated, } func makeContainerInfo(podUID, namespace, podName, containerName, qoSLevel string, annotations map[string]string, diff --git a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server.go b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server.go index 637b0c25a..80747f163 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server.go @@ -29,9 +29,8 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" - qrmstate "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/config" @@ -190,7 +189,7 @@ func (cs *cpuServer) syncCheckpoint(ctx context.Context, resp *cpuadvisor.GetChe // parse pool entries first, which are needed for parsing container entries for entryName, entry := range resp.Entries { - if poolInfo, ok := entry.Entries[state.FakedContainerName]; ok { + if poolInfo, ok := entry.Entries[commonstate.FakedContainerName]; ok { poolName := entryName livingPoolNameSet.Insert(poolName) if err := cs.updatePoolInfo(poolName, poolInfo); err != nil { @@ -201,7 +200,7 @@ func (cs *cpuServer) syncCheckpoint(ctx context.Context, resp *cpuadvisor.GetChe // parse container entries after pool entries for entryName, entry := range resp.Entries { - if _, ok := entry.Entries[state.FakedContainerName]; !ok { + if _, ok := entry.Entries[commonstate.FakedContainerName]; !ok { podUID := entryName pod, err := cs.metaServer.GetPod(ctx, podUID) if err != nil { @@ -318,7 +317,7 @@ func (cs *cpuServer) updateContainerInfo(podUID string, containerName string, po func (cs *cpuServer) assemblePoolEntries(advisorResp *types.InternalCPUCalculationResult, calculationEntriesMap map[string]*cpuadvisor.CalculationEntries, bs blockSet) { for poolName, entries := range advisorResp.PoolEntries { // join reclaim pool lastly - if poolName == qrmstate.PoolNameReclaim && advisorResp.AllowSharedCoresOverlapReclaimedCores { + if poolName == commonstate.PoolNameReclaim && advisorResp.AllowSharedCoresOverlapReclaimedCores { continue } poolEntry := NewPoolCalculationEntries(poolName) @@ -329,41 +328,41 @@ func (cs *cpuServer) assemblePoolEntries(advisorResp *types.InternalCPUCalculati innerBlock := NewInnerBlock(block, int64(numaID), poolName, nil, numaCalculationResult) innerBlock.join(block.BlockId, bs) - poolEntry.Entries[state.FakedContainerName].CalculationResultsByNumas[int64(numaID)] = numaCalculationResult + poolEntry.Entries[commonstate.FakedContainerName].CalculationResultsByNumas[int64(numaID)] = numaCalculationResult } calculationEntriesMap[poolName] = poolEntry } - if reclaimEntries, ok := advisorResp.PoolEntries[qrmstate.PoolNameReclaim]; ok && advisorResp.AllowSharedCoresOverlapReclaimedCores { - poolEntry := NewPoolCalculationEntries(qrmstate.PoolNameReclaim) + if reclaimEntries, ok := advisorResp.PoolEntries[commonstate.PoolNameReclaim]; ok && advisorResp.AllowSharedCoresOverlapReclaimedCores { + poolEntry := NewPoolCalculationEntries(commonstate.PoolNameReclaim) for numaID, reclaimSize := range reclaimEntries { - overlapSize := advisorResp.GetPoolOverlapInfo(qrmstate.PoolNameReclaim, numaID) + overlapSize := advisorResp.GetPoolOverlapInfo(commonstate.PoolNameReclaim, numaID) if len(overlapSize) == 0 { // If share pool not exists,join reclaim pool directly block := NewBlock(uint64(reclaimSize), "") numaCalculationResult := &cpuadvisor.NumaCalculationResult{Blocks: []*cpuadvisor.Block{block}} - innerBlock := NewInnerBlock(block, int64(numaID), qrmstate.PoolNameReclaim, nil, numaCalculationResult) + innerBlock := NewInnerBlock(block, int64(numaID), commonstate.PoolNameReclaim, nil, numaCalculationResult) innerBlock.join(block.BlockId, bs) - poolEntry.Entries[state.FakedContainerName].CalculationResultsByNumas[int64(numaID)] = numaCalculationResult + poolEntry.Entries[commonstate.FakedContainerName].CalculationResultsByNumas[int64(numaID)] = numaCalculationResult } else { numaCalculationResult := &cpuadvisor.NumaCalculationResult{Blocks: []*cpuadvisor.Block{}} for sharedPoolName, reclaimedSize := range overlapSize { block := NewBlock(uint64(reclaimedSize), "") - sharedPoolCalculationResults, ok := getNumaCalculationResult(calculationEntriesMap, sharedPoolName, state.FakedContainerName, int64(numaID)) + sharedPoolCalculationResults, ok := getNumaCalculationResult(calculationEntriesMap, sharedPoolName, commonstate.FakedContainerName, int64(numaID)) if ok && len(sharedPoolCalculationResults.Blocks) == 1 { - innerBlock := NewInnerBlock(block, int64(numaID), qrmstate.PoolNameReclaim, nil, numaCalculationResult) + innerBlock := NewInnerBlock(block, int64(numaID), commonstate.PoolNameReclaim, nil, numaCalculationResult) numaCalculationResult.Blocks = append(numaCalculationResult.Blocks, block) innerBlock.join(sharedPoolCalculationResults.Blocks[0].BlockId, bs) } - poolEntry.Entries[state.FakedContainerName].CalculationResultsByNumas[int64(numaID)] = numaCalculationResult + poolEntry.Entries[commonstate.FakedContainerName].CalculationResultsByNumas[int64(numaID)] = numaCalculationResult } } } - calculationEntriesMap[qrmstate.PoolNameReclaim] = poolEntry + calculationEntriesMap[commonstate.PoolNameReclaim] = poolEntry } } @@ -425,8 +424,8 @@ func (cs *cpuServer) assemblePodEntries(calculationEntriesMap map[string]*cpuadv } else { // if this podUID appears firstly, we should generate a new Block - reclaimPoolCalculationResults, ok := getNumaCalculationResult(calculationEntriesMap, qrmstate.PoolNameReclaim, - state.FakedContainerName, int64(numaID)) + reclaimPoolCalculationResults, ok := getNumaCalculationResult(calculationEntriesMap, commonstate.PoolNameReclaim, + commonstate.FakedContainerName, int64(numaID)) if !ok { // if no reclaimed pool exists, return the generated Block diff --git a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server_test.go b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server_test.go index d3a42cde0..6363a1c09 100644 --- a/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server_test.go +++ b/pkg/agent/sysadvisor/plugin/qosaware/server/cpu_server_test.go @@ -38,8 +38,8 @@ import ( "github.com/kubewharf/katalyst-api/pkg/consts" "github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc" + "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate" "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache" "github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types" "github.com/kubewharf/katalyst-core/pkg/config" @@ -309,9 +309,9 @@ func TestCPUServerListAndWatch(t *testing.T) { provision: types.InternalCPUCalculationResult{ TimeStamp: time.Now(), PoolEntries: map[string]map[int]int{ - state.PoolNameShare: {-1: 2}, - state.PoolNameReclaim: {-1: 4}, - state.PoolNamePrefixIsolation + "-test-1": {-1: 4}, + commonstate.PoolNameShare: {-1: 2}, + commonstate.PoolNameReclaim: {-1: 4}, + commonstate.PoolNamePrefixIsolation + "-test-1": {-1: 4}, }, }, infos: []*ContainerInfo{ @@ -339,19 +339,19 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, allocationInfo: &cpuadvisor.AllocationInfo{ - OwnerPoolName: state.PoolNameShare, + OwnerPoolName: commonstate.PoolNameShare, }, isolated: true, - regions: sets.NewString(state.PoolNamePrefixIsolation + "-test-1"), + regions: sets.NewString(commonstate.PoolNamePrefixIsolation + "-test-1"), }, }, wantErr: false, wantRes: &cpuadvisor.ListAndWatchResponse{ Entries: map[string]*cpuadvisor.CalculationEntries{ - state.PoolNameShare: { + commonstate.PoolNameShare: { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameShare, + OwnerPoolName: commonstate.PoolNameShare, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ -1: { Blocks: []*cpuadvisor.Block{ @@ -364,10 +364,10 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ -1: { Blocks: []*cpuadvisor.Block{ @@ -380,10 +380,10 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, }, - state.PoolNamePrefixIsolation + "-test-1": { + commonstate.PoolNamePrefixIsolation + "-test-1": { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNamePrefixIsolation + "-test-1", + OwnerPoolName: commonstate.PoolNamePrefixIsolation + "-test-1", CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ -1: { Blocks: []*cpuadvisor.Block{ @@ -400,7 +400,7 @@ func TestCPUServerListAndWatch(t *testing.T) { "pod1": { Entries: map[string]*cpuadvisor.CalculationInfo{ "c1": { - OwnerPoolName: state.PoolNamePrefixIsolation + "-test-1", + OwnerPoolName: commonstate.PoolNamePrefixIsolation + "-test-1", }, }, }, @@ -412,7 +412,7 @@ func TestCPUServerListAndWatch(t *testing.T) { provision: types.InternalCPUCalculationResult{ TimeStamp: time.Now(), PoolEntries: map[string]map[int]int{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 4, 1: 8, }, @@ -447,7 +447,7 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, allocationInfo: &cpuadvisor.AllocationInfo{ - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, TopologyAwareAssignments: map[uint64]string{ 0: "0-3", 1: "24-47", @@ -458,10 +458,10 @@ func TestCPUServerListAndWatch(t *testing.T) { wantErr: false, wantRes: &cpuadvisor.ListAndWatchResponse{ Entries: map[string]*cpuadvisor.CalculationEntries{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -498,7 +498,7 @@ func TestCPUServerListAndWatch(t *testing.T) { "pod1": { Entries: map[string]*cpuadvisor.CalculationInfo{ "c1": { - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -506,7 +506,7 @@ func TestCPUServerListAndWatch(t *testing.T) { Result: 4, OverlapTargets: []*cpuadvisor.OverlapTarget{ { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -523,7 +523,7 @@ func TestCPUServerListAndWatch(t *testing.T) { Result: 8, OverlapTargets: []*cpuadvisor.OverlapTarget{ { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -542,7 +542,7 @@ func TestCPUServerListAndWatch(t *testing.T) { provision: types.InternalCPUCalculationResult{ TimeStamp: time.Now(), PoolEntries: map[string]map[int]int{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 4, 1: 8, }, @@ -577,7 +577,7 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, allocationInfo: &cpuadvisor.AllocationInfo{ - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, TopologyAwareAssignments: map[uint64]string{ 0: "0-3", 1: "24-47", @@ -612,7 +612,7 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, allocationInfo: &cpuadvisor.AllocationInfo{ - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, TopologyAwareAssignments: map[uint64]string{ 0: "0-3", 1: "24-47", @@ -623,10 +623,10 @@ func TestCPUServerListAndWatch(t *testing.T) { wantErr: false, wantRes: &cpuadvisor.ListAndWatchResponse{ Entries: map[string]*cpuadvisor.CalculationEntries{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -673,7 +673,7 @@ func TestCPUServerListAndWatch(t *testing.T) { "pod1": { Entries: map[string]*cpuadvisor.CalculationInfo{ "c1": { - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -686,7 +686,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -714,7 +714,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -724,7 +724,7 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, "c2": { - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -737,7 +737,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -765,7 +765,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -784,7 +784,7 @@ func TestCPUServerListAndWatch(t *testing.T) { provision: types.InternalCPUCalculationResult{ TimeStamp: time.Now(), PoolEntries: map[string]map[int]int{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 4, 1: 8, }, @@ -819,7 +819,7 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, allocationInfo: &cpuadvisor.AllocationInfo{ - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, TopologyAwareAssignments: map[uint64]string{ 0: "0-3", 1: "24-47", @@ -854,7 +854,7 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, allocationInfo: &cpuadvisor.AllocationInfo{ - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, TopologyAwareAssignments: map[uint64]string{ 0: "0-3", 1: "24-47", @@ -889,7 +889,7 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, allocationInfo: &cpuadvisor.AllocationInfo{ - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, TopologyAwareAssignments: map[uint64]string{ 0: "0-3", 1: "24-47", @@ -900,10 +900,10 @@ func TestCPUServerListAndWatch(t *testing.T) { wantErr: false, wantRes: &cpuadvisor.ListAndWatchResponse{ Entries: map[string]*cpuadvisor.CalculationEntries{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -960,7 +960,7 @@ func TestCPUServerListAndWatch(t *testing.T) { "pod1": { Entries: map[string]*cpuadvisor.CalculationInfo{ "c1": { - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -978,7 +978,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -1016,7 +1016,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -1026,7 +1026,7 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, "c2": { - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -1044,7 +1044,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -1082,7 +1082,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -1092,7 +1092,7 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, "c3": { - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -1110,7 +1110,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -1148,7 +1148,7 @@ func TestCPUServerListAndWatch(t *testing.T) { OverlapType: cpuadvisor.OverlapType_OverlapWithPod, }, { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -1168,13 +1168,13 @@ func TestCPUServerListAndWatch(t *testing.T) { AllowSharedCoresOverlapReclaimedCores: true, TimeStamp: time.Now(), PoolEntries: map[string]map[int]int{ - strings.Join([]string{state.PoolNameShare, "1"}, "-"): {-1: 2}, - strings.Join([]string{state.PoolNameShare, "2"}, "-"): {-1: 2}, - state.PoolNameReclaim: {-1: 4}, - state.PoolNamePrefixIsolation + "-test-1": {-1: 4}, + strings.Join([]string{commonstate.PoolNameShare, "1"}, "-"): {-1: 2}, + strings.Join([]string{commonstate.PoolNameShare, "2"}, "-"): {-1: 2}, + commonstate.PoolNameReclaim: {-1: 4}, + commonstate.PoolNamePrefixIsolation + "-test-1": {-1: 4}, }, PoolOverlapInfo: map[string]map[int]map[string]int{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { -1: map[string]int{ "share-1": 2, "share-2": 2, @@ -1230,10 +1230,10 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ -1: { Blocks: []*cpuadvisor.Block{ @@ -1261,10 +1261,10 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, }, - state.PoolNamePrefixIsolation + "-test-1": { + commonstate.PoolNamePrefixIsolation + "-test-1": { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNamePrefixIsolation + "-test-1", + OwnerPoolName: commonstate.PoolNamePrefixIsolation + "-test-1", CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ -1: { Blocks: []*cpuadvisor.Block{ @@ -1286,13 +1286,13 @@ func TestCPUServerListAndWatch(t *testing.T) { AllowSharedCoresOverlapReclaimedCores: true, TimeStamp: time.Now(), PoolEntries: map[string]map[int]int{ - strings.Join([]string{state.PoolNameShare, "1"}, "-"): {-1: 4}, - strings.Join([]string{state.PoolNameShare, "2"}, "-"): {-1: 4}, - state.PoolNameReclaim: {-1: 2}, - state.PoolNamePrefixIsolation + "-test-1": {-1: 4}, + strings.Join([]string{commonstate.PoolNameShare, "1"}, "-"): {-1: 4}, + strings.Join([]string{commonstate.PoolNameShare, "2"}, "-"): {-1: 4}, + commonstate.PoolNameReclaim: {-1: 2}, + commonstate.PoolNamePrefixIsolation + "-test-1": {-1: 4}, }, PoolOverlapInfo: map[string]map[int]map[string]int{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { -1: map[string]int{ "share-1": 1, "share-2": 1, @@ -1354,10 +1354,10 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, }, - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ -1: { Blocks: []*cpuadvisor.Block{ @@ -1385,10 +1385,10 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, }, - state.PoolNamePrefixIsolation + "-test-1": { + commonstate.PoolNamePrefixIsolation + "-test-1": { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNamePrefixIsolation + "-test-1", + OwnerPoolName: commonstate.PoolNamePrefixIsolation + "-test-1", CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ -1: { Blocks: []*cpuadvisor.Block{ @@ -1410,18 +1410,18 @@ func TestCPUServerListAndWatch(t *testing.T) { AllowSharedCoresOverlapReclaimedCores: true, TimeStamp: time.Now(), PoolEntries: map[string]map[int]int{ - state.PoolNameReclaim: {-1: 2}, - state.PoolNamePrefixIsolation + "-test-1": {-1: 4}, + commonstate.PoolNameReclaim: {-1: 2}, + commonstate.PoolNamePrefixIsolation + "-test-1": {-1: 4}, }, }, wantErr: false, wantRes: &cpuadvisor.ListAndWatchResponse{ AllowSharedCoresOverlapReclaimedCores: true, Entries: map[string]*cpuadvisor.CalculationEntries{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ -1: { Blocks: []*cpuadvisor.Block{ @@ -1434,10 +1434,10 @@ func TestCPUServerListAndWatch(t *testing.T) { }, }, }, - state.PoolNamePrefixIsolation + "-test-1": { + commonstate.PoolNamePrefixIsolation + "-test-1": { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNamePrefixIsolation + "-test-1", + OwnerPoolName: commonstate.PoolNamePrefixIsolation + "-test-1", CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ -1: { Blocks: []*cpuadvisor.Block{ @@ -1752,7 +1752,7 @@ func TestCPUServerDropOldAdvice(t *testing.T) { provision := types.InternalCPUCalculationResult{ TimeStamp: time.Now(), PoolEntries: map[string]map[int]int{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { 0: 4, 1: 8, }, @@ -1787,7 +1787,7 @@ func TestCPUServerDropOldAdvice(t *testing.T) { }, }, allocationInfo: &cpuadvisor.AllocationInfo{ - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, TopologyAwareAssignments: map[uint64]string{ 0: "0-3", 1: "24-47", @@ -1815,10 +1815,10 @@ func TestCPUServerDropOldAdvice(t *testing.T) { assert.NoError(t, err) wantRes := &cpuadvisor.ListAndWatchResponse{ Entries: map[string]*cpuadvisor.CalculationEntries{ - state.PoolNameReclaim: { + commonstate.PoolNameReclaim: { Entries: map[string]*cpuadvisor.CalculationInfo{ "": { - OwnerPoolName: state.PoolNameReclaim, + OwnerPoolName: commonstate.PoolNameReclaim, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -1855,7 +1855,7 @@ func TestCPUServerDropOldAdvice(t *testing.T) { "pod1": { Entries: map[string]*cpuadvisor.CalculationInfo{ "c1": { - OwnerPoolName: state.PoolNameDedicated, + OwnerPoolName: commonstate.PoolNameDedicated, CalculationResultsByNumas: map[int64]*cpuadvisor.NumaCalculationResult{ 0: { Blocks: []*cpuadvisor.Block{ @@ -1863,7 +1863,7 @@ func TestCPUServerDropOldAdvice(t *testing.T) { Result: 4, OverlapTargets: []*cpuadvisor.OverlapTarget{ { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, @@ -1880,7 +1880,7 @@ func TestCPUServerDropOldAdvice(t *testing.T) { Result: 8, OverlapTargets: []*cpuadvisor.OverlapTarget{ { - OverlapTargetPoolName: state.PoolNameReclaim, + OverlapTargetPoolName: commonstate.PoolNameReclaim, OverlapType: cpuadvisor.OverlapType_OverlapWithPool, }, }, diff --git a/pkg/config/generic/qos.go b/pkg/config/generic/qos.go index 28c427f5b..b5127903e 100644 --- a/pkg/config/generic/qos.go +++ b/pkg/config/generic/qos.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" apiconsts "github.com/kubewharf/katalyst-api/pkg/consts" - "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state" "github.com/kubewharf/katalyst-core/pkg/util/general" ) @@ -321,21 +320,6 @@ func (c *QoSConfiguration) checkQosMatched(annotations map[string]string, qosVal return true, false, nil } -func (c *QoSConfiguration) GetSpecifiedPoolNameForPod(pod *v1.Pod) (string, error) { - return c.GetSpecifiedPoolName(pod, map[string]string{}) -} - -// GetSpecifiedPoolName returns the specified cpuset pool name for given enhancements and annotations; -func (c *QoSConfiguration) GetSpecifiedPoolName(pod *v1.Pod, expandedAnnotations map[string]string) (string, error) { - qosLevel, err := c.GetQoSLevel(pod, expandedAnnotations) - if err != nil { - return "", fmt.Errorf("GetQoSLevel failed with error: %v", err) - } - - enhancementKVs := c.GetQoSEnhancementKVs(pod, expandedAnnotations, apiconsts.PodAnnotationCPUEnhancementKey) - return state.GetSpecifiedPoolName(qosLevel, enhancementKVs[apiconsts.PodAnnotationCPUEnhancementCPUSet]), nil -} - // GetQoSEnhancementKVs parses enhancements from annotations by given key, // since enhancement values are stored as k-v, so we should unmarshal it into maps. func (c *QoSConfiguration) GetQoSEnhancementKVs(pod *v1.Pod, expandedAnnotations map[string]string, enhancementKey string) (flattenedEnhancements map[string]string) {