-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add loadaware scheduler plugin and npd controller plugin #654
Open
WangZzzhe
wants to merge
6
commits into
kubewharf:main
Choose a base branch
from
WangZzzhe:dev/npd-loadaware-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
435a024
feat: add npd controller
WangZzzhe 839501c
fix: run all plugins when npdController run
WangZzzhe d5633b9
add npd loadAware plugin
WangZzzhe 006c1ff
add loadaware scheduler plugin
WangZzzhe 0802c8a
add spd portrait loadaware scheduler plugin
WangZzzhe 7bdce6a
add ut for loadaware scheduler plugin and npd plugin
WangZzzhe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
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 controller | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
katalyst "github.com/kubewharf/katalyst-core/cmd/base" | ||
"github.com/kubewharf/katalyst-core/pkg/config" | ||
"github.com/kubewharf/katalyst-core/pkg/controller/npd" | ||
) | ||
|
||
const ( | ||
NPDControllerName = "npd" | ||
) | ||
|
||
func StartNPDController(ctx context.Context, controlCtx *katalyst.GenericContext, | ||
conf *config.Configuration, extraConf interface{}, _ string, | ||
) (bool, error) { | ||
if controlCtx == nil || conf == nil { | ||
err := fmt.Errorf("controlCtx and controllerConf can't be nil") | ||
klog.Error(err) | ||
return false, err | ||
} | ||
|
||
npdController, err := npd.NewNPDController( | ||
ctx, | ||
controlCtx, conf.GenericConfiguration, | ||
conf.GenericControllerConfiguration, | ||
conf.NPDConfig, | ||
extraConf, | ||
) | ||
if err != nil { | ||
klog.Errorf("failed to new npd controller") | ||
return false, err | ||
} | ||
|
||
go npdController.Run() | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
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 options | ||
|
||
import ( | ||
"time" | ||
|
||
cliflag "k8s.io/component-base/cli/flag" | ||
|
||
"github.com/kubewharf/katalyst-core/pkg/config/controller" | ||
) | ||
|
||
type NPDOptions struct { | ||
NPDIndicatorPlugins []string | ||
EnableScopeDuplicated bool | ||
SyncWorkers int | ||
*LoadAwarePluginOptions | ||
} | ||
|
||
func NewNPDOptions() *NPDOptions { | ||
return &NPDOptions{ | ||
NPDIndicatorPlugins: []string{}, | ||
EnableScopeDuplicated: false, | ||
SyncWorkers: 1, | ||
LoadAwarePluginOptions: NewLoadAwarePluginOptions(), | ||
} | ||
} | ||
|
||
func (o *NPDOptions) AddFlags(fss *cliflag.NamedFlagSets) { | ||
fs := fss.FlagSet("npd") | ||
|
||
fs.StringSliceVar(&o.NPDIndicatorPlugins, "npd-indicator-plugins", o.NPDIndicatorPlugins, | ||
"A list of indicator plugins to be used") | ||
fs.BoolVar(&o.EnableScopeDuplicated, "npd-enable-scope-duplicated", o.EnableScopeDuplicated, | ||
"Whether metrics with the same scope can be updated by multiple plugins") | ||
fs.IntVar(&o.SyncWorkers, "npd-sync-workers", o.SyncWorkers, | ||
"Number of workers to sync npd status") | ||
|
||
fs.IntVar(&o.Workers, "loadaware-sync-workers", o.Workers, | ||
"num of workers to sync node metrics") | ||
fs.DurationVar(&o.SyncMetricInterval, "loadaware-sync-interval", o.SyncMetricInterval, | ||
"interval of syncing node metrics") | ||
fs.DurationVar(&o.ListMetricTimeout, "loadaware-list-metric-timeout", o.ListMetricTimeout, | ||
"timeout duration when list metrics from metrics server") | ||
|
||
fs.StringVar(&o.PodUsageSelectorNamespace, "loadaware-podusage-selector-namespace", o.PodUsageSelectorNamespace, | ||
"pod namespace used to detect whether podusage should be calculated") | ||
fs.StringVar(&o.PodUsageSelectorKey, "loadaware-podusage-selector-key", o.PodUsageSelectorKey, | ||
"pod label key used to detect whether podusage should be calculated") | ||
fs.StringVar(&o.PodUsageSelectorVal, "loadaware-podusage-selector-val", o.PodUsageSelectorVal, | ||
"pod label value used to detect whether podusage should be calculated") | ||
fs.IntVar(&o.MaxPodUsageCount, "loadaware-max-podusage-count", o.MaxPodUsageCount, | ||
"max podusage count on nodemonitor") | ||
} | ||
|
||
func (o *NPDOptions) ApplyTo(c *controller.NPDConfig) error { | ||
c.NPDIndicatorPlugins = o.NPDIndicatorPlugins | ||
c.EnableScopeDuplicated = o.EnableScopeDuplicated | ||
c.SyncWorkers = o.SyncWorkers | ||
|
||
c.Workers = o.Workers | ||
c.SyncMetricInterval = o.SyncMetricInterval | ||
c.ListMetricTimeout = o.ListMetricTimeout | ||
c.PodUsageSelectorNamespace = o.PodUsageSelectorNamespace | ||
c.PodUsageSelectorKey = o.PodUsageSelectorKey | ||
c.PodUsageSelectorVal = o.PodUsageSelectorVal | ||
c.MaxPodUsageCount = o.MaxPodUsageCount | ||
return nil | ||
} | ||
|
||
func (o *NPDOptions) Config() (*controller.NPDConfig, error) { | ||
c := &controller.NPDConfig{} | ||
if err := o.ApplyTo(c); err != nil { | ||
return nil, err | ||
} | ||
|
||
return c, nil | ||
} | ||
|
||
type LoadAwarePluginOptions struct { | ||
// number of workers to sync node metrics | ||
Workers int | ||
// time interval of sync node metrics | ||
SyncMetricInterval time.Duration | ||
// timeout of list metrics from apiserver | ||
ListMetricTimeout time.Duration | ||
|
||
// pod selector for checking if pod usage is required | ||
PodUsageSelectorNamespace string | ||
PodUsageSelectorKey string | ||
PodUsageSelectorVal string | ||
|
||
MaxPodUsageCount int | ||
} | ||
|
||
func NewLoadAwarePluginOptions() *LoadAwarePluginOptions { | ||
return &LoadAwarePluginOptions{ | ||
Workers: 3, | ||
SyncMetricInterval: time.Minute * 1, | ||
ListMetricTimeout: time.Second * 10, | ||
PodUsageSelectorNamespace: "", | ||
PodUsageSelectorKey: "", | ||
PodUsageSelectorVal: "", | ||
MaxPodUsageCount: 20, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
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 control | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1" | ||
clientset "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned" | ||
) | ||
|
||
type NodeProfileControl interface { | ||
CreateNPD(ctx context.Context, npd *v1alpha1.NodeProfileDescriptor, opts metav1.CreateOptions) (*v1alpha1.NodeProfileDescriptor, error) | ||
UpdateNPDStatus(ctx context.Context, npd *v1alpha1.NodeProfileDescriptor, opts metav1.UpdateOptions) (*v1alpha1.NodeProfileDescriptor, error) | ||
DeleteNPD(ctx context.Context, npdName string, opts metav1.DeleteOptions) error | ||
} | ||
|
||
type DummyNPDControl struct{} | ||
|
||
func (d *DummyNPDControl) CreateNPD(ctx context.Context, npd *v1alpha1.NodeProfileDescriptor, opts metav1.CreateOptions) (*v1alpha1.NodeProfileDescriptor, error) { | ||
return nil, nil | ||
} | ||
|
||
func (d *DummyNPDControl) UpdateNPDStatus(ctx context.Context, npd *v1alpha1.NodeProfileDescriptor, opts metav1.UpdateOptions) (*v1alpha1.NodeProfileDescriptor, error) { | ||
return nil, nil | ||
} | ||
|
||
func (d *DummyNPDControl) DeleteNPD(ctx context.Context, npdName string, opts metav1.DeleteOptions) error { | ||
return nil | ||
} | ||
|
||
type NPDControlImp struct { | ||
client clientset.Interface | ||
} | ||
|
||
func NewNPDControlImp(client clientset.Interface) *NPDControlImp { | ||
return &NPDControlImp{ | ||
client: client, | ||
} | ||
} | ||
|
||
func (n *NPDControlImp) CreateNPD(ctx context.Context, npd *v1alpha1.NodeProfileDescriptor, opts metav1.CreateOptions) (*v1alpha1.NodeProfileDescriptor, error) { | ||
if npd == nil { | ||
return nil, fmt.Errorf("npd is nil") | ||
} | ||
|
||
return n.client.NodeV1alpha1().NodeProfileDescriptors().Create(ctx, npd, opts) | ||
} | ||
|
||
func (n *NPDControlImp) UpdateNPDStatus(ctx context.Context, npd *v1alpha1.NodeProfileDescriptor, opts metav1.UpdateOptions) (*v1alpha1.NodeProfileDescriptor, error) { | ||
if npd == nil { | ||
return nil, fmt.Errorf("npd is nil") | ||
} | ||
|
||
return n.client.NodeV1alpha1().NodeProfileDescriptors().UpdateStatus(ctx, npd, opts) | ||
} | ||
|
||
func (n *NPDControlImp) DeleteNPD(ctx context.Context, npdName string, opts metav1.DeleteOptions) error { | ||
return n.client.NodeV1alpha1().NodeProfileDescriptors().Delete(ctx, npdName, opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NPDMetricsPlugins