Skip to content
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

spd indicator plugin init function support spd workload informer #103

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/controller/spd/indicator-plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"sync"

"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/cache"

apiworkload "github.com/kubewharf/katalyst-api/pkg/apis/workload/v1alpha1"
katalystbase "github.com/kubewharf/katalyst-core/cmd/base"
"github.com/kubewharf/katalyst-core/pkg/config/controller"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

// IndicatorPlugin represent an implementation for indicator sources;
Expand Down Expand Up @@ -68,7 +68,7 @@ func (d DummyIndicatorPlugin) GetSupportedBusinessIndicatorStatus() []apiworkloa
var pluginInitializers sync.Map

type InitFunc func(ctx context.Context, conf *controller.SPDConfig, extraConf interface{},
workloadLister map[schema.GroupVersionResource]cache.GenericLister,
spdWorkloadInformer map[schema.GroupVersionResource]native.DynamicInformer,
controlCtx *katalystbase.GenericContext, updater IndicatorUpdater) (IndicatorPlugin, error)

// RegisterPluginInitializer is used to register user-defined indicator plugins
Expand Down
30 changes: 17 additions & 13 deletions pkg/controller/spd/spd.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ type SPDController struct {
spdIndexer cache.Indexer
podIndexer cache.Indexer

podLister corelisters.PodLister
spdLister apiListers.ServiceProfileDescriptorLister
workloadLister map[schema.GroupVersionResource]cache.GenericLister
podLister corelisters.PodLister
spdLister apiListers.ServiceProfileDescriptorLister
workloadLister map[schema.GroupVersionResource]cache.GenericLister
spdWorkloadInformer map[schema.GroupVersionResource]native.DynamicInformer

syncedFunc []cache.InformerSynced
spdQueue workqueue.RateLimitingInterface
Expand All @@ -106,15 +107,16 @@ func NewSPDController(ctx context.Context, controlCtx *katalystbase.GenericConte
spdInformer := controlCtx.InternalInformerFactory.Workload().V1alpha1().ServiceProfileDescriptors()

spdController := &SPDController{
ctx: ctx,
conf: conf,
podUpdater: &control.DummyPodUpdater{},
spdControl: &control.DummySPDControl{},
workloadControl: &control.DummyUnstructuredControl{},
spdQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "spd"),
workloadSyncQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "workload"),
metricsEmitter: controlCtx.EmitterPool.GetDefaultMetricsEmitter().WithTags(spdControllerName),
workloadLister: make(map[schema.GroupVersionResource]cache.GenericLister),
ctx: ctx,
conf: conf,
podUpdater: &control.DummyPodUpdater{},
spdControl: &control.DummySPDControl{},
workloadControl: &control.DummyUnstructuredControl{},
spdQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "spd"),
workloadSyncQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "workload"),
metricsEmitter: controlCtx.EmitterPool.GetDefaultMetricsEmitter().WithTags(spdControllerName),
workloadLister: make(map[schema.GroupVersionResource]cache.GenericLister),
spdWorkloadInformer: make(map[schema.GroupVersionResource]native.DynamicInformer),
}

spdController.podLister = podInformer.Lister()
Expand All @@ -136,6 +138,7 @@ func NewSPDController(ctx context.Context, controlCtx *katalystbase.GenericConte
continue
}

spdController.spdWorkloadInformer[wf.GVR] = wf
wf.Informer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: spdController.addWorkload(workload),
UpdateFunc: spdController.updateWorkload(workload),
Expand Down Expand Up @@ -236,7 +239,8 @@ func (sc *SPDController) initializeIndicatorPlugins(controlCtx *katalystbase.Gen
sc.indicatorsStatusBusiness = make(map[apiworkload.ServiceBusinessIndicatorName]interface{})

for pluginName, initFunc := range indicator_plugin.GetPluginInitializers() {
plugin, err := initFunc(sc.ctx, sc.conf, extraConf, sc.workloadLister, controlCtx, sc.indicatorManager)
plugin, err := initFunc(sc.ctx, sc.conf, extraConf, sc.spdWorkloadInformer,
controlCtx, sc.indicatorManager)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/spd/spd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/kubewharf/katalyst-core/pkg/config/controller"
"github.com/kubewharf/katalyst-core/pkg/config/generic"
indicator_plugin "github.com/kubewharf/katalyst-core/pkg/controller/spd/indicator-plugin"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

var (
Expand Down Expand Up @@ -468,12 +469,12 @@ func TestIndicatorUpdater(t *testing.T) {
}

indicator_plugin.RegisterPluginInitializer("d1", func(_ context.Context, _ *controller.SPDConfig,
_ interface{}, _ map[schema.GroupVersionResource]cache.GenericLister, _ *katalystbase.GenericContext,
_ interface{}, _ map[schema.GroupVersionResource]native.DynamicInformer, _ *katalystbase.GenericContext,
_ indicator_plugin.IndicatorUpdater) (indicator_plugin.IndicatorPlugin, error) {
return d1, nil
})
indicator_plugin.RegisterPluginInitializer("d2", func(_ context.Context, _ *controller.SPDConfig,
_ interface{}, _ map[schema.GroupVersionResource]cache.GenericLister, _ *katalystbase.GenericContext,
_ interface{}, _ map[schema.GroupVersionResource]native.DynamicInformer, _ *katalystbase.GenericContext,
_ indicator_plugin.IndicatorUpdater) (indicator_plugin.IndicatorPlugin, error) {
return d2, nil
})
Expand Down