Skip to content

Commit

Permalink
add resource policy in nodeResourceTopologyArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
WangZzzhe committed Sep 26, 2023
1 parent 4041a1f commit d39ed2d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ replace (
k8s.io/kube-proxy => k8s.io/kube-proxy v0.24.6
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.24.6
k8s.io/kubectl => k8s.io/kubectl v0.24.6
k8s.io/kubelet => github.com/kubewharf/kubelet v1.24.6-kubewharf.5
k8s.io/kubelet => github.com/WangZzzhe/kubelet v0.0.0-20230921082135-659f02530842
k8s.io/kubernetes => k8s.io/kubernetes v1.24.6
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.24.6
k8s.io/metrics => k8s.io/metrics v0.24.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/WangZzzhe/kubelet v0.0.0-20230921082135-659f02530842 h1:b3evJL9bAgi/i9dzA/7Sr+T1nPv5V8oDVquH9y0yJg0=
github.com/WangZzzhe/kubelet v0.0.0-20230921082135-659f02530842/go.mod h1:MxbSZUx3wXztFneeelwWWlX7NAAStJ6expqq7gY2J3c=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -392,8 +394,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubewharf/kubelet v1.24.6-kubewharf.5 h1:i3BcfBY3fFTzPWi5BCYyhkiSZCrIGczaGNAwgUvga6U=
github.com/kubewharf/kubelet v1.24.6-kubewharf.5/go.mod h1:MxbSZUx3wXztFneeelwWWlX7NAAStJ6expqq7gY2J3c=
github.com/libopenstorage/openstorage v1.0.0/go.mod h1:Sp1sIObHjat1BeXhfMqLZ14wnOzEhNx2YQedreMcUyc=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=
Expand Down
14 changes: 11 additions & 3 deletions pkg/apis/scheduling/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,28 @@ type QoSAwareNodeResourcesBalancedAllocationArgs struct {

// NodeResourceTopologyArgs holds arguments used to configure the NodeResourceTopologyMatch plugin
type NodeResourceTopologyArgs struct {
metav1.TypeMeta
metav1.TypeMeta `json:",inline"`

// ScoringStrategy a scoring model that determine how the plugin will score the nodes.
ScoringStrategy *ScoringStrategy
ScoringStrategy *ScoringStrategy `json:"scoringStrategy,omitempty"`

// AlignedResources are resources should be aligned for dedicated pods.
AlignedResources []string
AlignedResources []string `json:"alignedResources,omitempty"`

// ResourcePolicy are QRMPlugin resource policy to allocate topology resource for containers.
ResourcePolicy string `json:"resourcePolicy,omitempty"`
}

const (
// BalancedAllocation strategy favors nodes with balanced resource usage rate
BalancedAllocation kubeschedulerconfig.ScoringStrategyType = "BalancedAllocation"
// LeastNUMANodes strategy favors nodes which requires least amount of NUMA nodes to satisfy resource requests for given pod
LeastNUMANodes kubeschedulerconfig.ScoringStrategyType = "LeastNUMANodes"

// ResourcePluginPolicyNameDynamic is the name of the dynamic policy.
ResourcePluginPolicyNameDynamic = "dynamic"
// ResourcePluginPolicyNameNative is the name of the native policy.
ResourcePluginPolicyNameNative = "native"
)

// ScoringStrategy define ScoringStrategyType for node resource plugin
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/scheduling/config/v1beta3/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ func SetDefaults_NodeResourceTopologyArgs(obj *NodeResourceTopologyArgs) {
obj.ScoringStrategy.Resources[i].Weight = 1
}
}
if obj.ResourcePolicy == "" {
obj.ResourcePolicy = ResourcePluginPolicyNameDynamic
}
}
1 change: 1 addition & 0 deletions pkg/apis/scheduling/config/v1beta3/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&QoSAwareNodeResourcesFitArgs{},
&QoSAwareNodeResourcesBalancedAllocationArgs{},
&NodeResourceTopologyArgs{},
)
return nil
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/apis/scheduling/config/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,26 @@ type ScoringStrategy struct {

// NodeResourceTopologyArgs holds arguments used to configure the NodeResourceTopologyMatch plugin
type NodeResourceTopologyArgs struct {
metav1.TypeMeta
metav1.TypeMeta `json:",inline"`

// ScoringStrategy a scoring model that determine how the plugin will score the nodes.
ScoringStrategy *ScoringStrategy
ScoringStrategy *ScoringStrategy `json:"scoringStrategy,omitempty"`

// AlignedResources are resources should be aligned for dedicated pods.
AlignedResources []string
AlignedResources []string `json:"alignedResources,omitempty"`

// ResourcePolicy are QRMPlugin resource policy to allocate topology resource for containers.
ResourcePolicy string `json:"resourcePolicy,omitempty"`
}

const (
// BalancedAllocation strategy favors nodes with balanced resource usage rate
BalancedAllocation kubeschedulerconfig.ScoringStrategyType = "BalancedAllocation"
// LeastNUMANodes strategy favors nodes which requires least amount of NUMA nodes to satisfy resource requests for given pod
LeastNUMANodes kubeschedulerconfig.ScoringStrategyType = "LeastNUMANodes"

// ResourcePluginPolicyNameDynamic is the name of the dynamic policy.
ResourcePluginPolicyNameDynamic = "dynamic"
// ResourcePluginPolicyNameNative is the name of the native policy.
ResourcePluginPolicyNameNative = "native"
)
2 changes: 2 additions & 0 deletions pkg/apis/scheduling/config/v1beta3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/apis/scheduling/config/validation/validation_pluginargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func ValidateNodeResourceTopologyMatchArgs(path *field.Path, args *config.NodeRe
allErrs = append(allErrs, err)
}

resourcePolicyPath := path.Child("resourcePolicy")
if err := validateResourcePolicy(args.ResourcePolicy, resourcePolicyPath); err != nil {
allErrs = append(allErrs, err)
}

return allErrs.ToAggregate()
}

Expand All @@ -142,3 +147,11 @@ func validateScoringStrategyType(scoringStrategy kubeschedulerconfig.ScoringStra
}
return nil
}

func validateResourcePolicy(resourcePolicy string, path *field.Path) *field.Error {
if resourcePolicy != config.ResourcePluginPolicyNameDynamic &&
resourcePolicy != config.ResourcePluginPolicyNameNative {
return field.Invalid(path, resourcePolicy, "invalid ResourcePolicy")
}
return nil
}
5 changes: 5 additions & 0 deletions pkg/utils/topology_policy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"k8s.io/kubelet/config/v1beta1"
"k8s.io/kubernetes/pkg/kubelet/apis/config"

nodev1alpha1 "github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1"
Expand Down Expand Up @@ -28,6 +29,8 @@ func generateTopologyPolicyPodScope(policy string) nodev1alpha1.TopologyPolicy {
return nodev1alpha1.TopologyPolicyBestEffortPodLevel
case config.NoneTopologyManagerPolicy:
return nodev1alpha1.TopologyPolicyNone
case v1beta1.NumericTopologyManagerPolicy:
return nodev1alpha1.TopologyPolicyNumericPodLevel
default:
return nodev1alpha1.TopologyPolicyNone
}
Expand All @@ -43,6 +46,8 @@ func generateTopologyPolicyContainerScope(policy string) nodev1alpha1.TopologyPo
return nodev1alpha1.TopologyPolicyBestEffortContainerLevel
case config.NoneTopologyManagerPolicy:
return nodev1alpha1.TopologyPolicyNone
case v1beta1.NumericTopologyManagerPolicy:
return nodev1alpha1.TopologyPolicyNumericContainerLevel
default:
return nodev1alpha1.TopologyPolicyNone
}
Expand Down

0 comments on commit d39ed2d

Please sign in to comment.