Files
open-cluster-management/pkg/plugins/interface.go
Qing Hao d13d0dbe48 placement extensible scheduling (#51)
* placement extensible scheduling

Signed-off-by: haoqing0110 <qhao@redhat.com>

* resync every 5 minutes

Signed-off-by: haoqing0110 <qhao@redhat.com>

* use ScoreCoordinate as map key, and add score lister

Signed-off-by: haoqing0110 <qhao@redhat.com>

* update go.mod

Signed-off-by: haoqing0110 <qhao@redhat.com>

* requeue placement with ScoreCoordinateTypeAddOn

Signed-off-by: haoqing0110 <qhao@redhat.com>

* update integration test case

Signed-off-by: haoqing0110 <qhao@redhat.com>

* fix review comments and remove resync from this PR

Signed-off-by: haoqing0110 <qhao@redhat.com>

* update api

Signed-off-by: haoqing0110 <qhao@redhat.com>
2022-01-12 02:56:07 +01:00

65 lines
2.1 KiB
Go

package plugins
import (
"context"
"math"
"k8s.io/client-go/tools/events"
clusterclient "open-cluster-management.io/api/client/cluster/clientset/versioned"
clusterlisterv1alpha1 "open-cluster-management.io/api/client/cluster/listers/cluster/v1alpha1"
clusterapiv1 "open-cluster-management.io/api/cluster/v1"
clusterapiv1alpha1 "open-cluster-management.io/api/cluster/v1alpha1"
)
const (
// MaxClusterScore is the maximum score a Prioritizer plugin is expected to return.
MaxClusterScore int64 = 100
// MinClusterScore is the minimum score a Prioritizer plugin is expected to return.
MinClusterScore int64 = -100
// MaxTotalScore is the maximum total score.
MaxTotalScore int64 = math.MaxInt64
)
// Plugin is the parent type for all the scheduling plugins.
type Plugin interface {
Name() string
// Set is to set the placement for the current scheduling.
Description() string
}
// Fitler defines a filter plugin that filter unsatisfied cluster.
type Filter interface {
Plugin
// Filter returns a list of clusters satisfying the certain condition.
Filter(ctx context.Context, placement *clusterapiv1alpha1.Placement, clusters []*clusterapiv1.ManagedCluster) ([]*clusterapiv1.ManagedCluster, error)
}
// Prioritizer defines a prioritizer plugin that score each cluster. The score is normalized
// as a floating betwween 0 and 1.
type Prioritizer interface {
Plugin
// Score gives the score to a list of the clusters, it returns a map with the key as
// the cluster name.
Score(ctx context.Context, placement *clusterapiv1alpha1.Placement, clusters []*clusterapiv1.ManagedCluster) (map[string]int64, error)
}
// Handle provides data and some tools that plugins can use. It is
// passed to the plugin factories at the time of plugin initialization.
type Handle interface {
// DecisionLister lists all decisions
DecisionLister() clusterlisterv1alpha1.PlacementDecisionLister
// ScoreLister lists all AddOnPlacementScores
ScoreLister() clusterlisterv1alpha1.AddOnPlacementScoreLister
// ClusterClient returns the cluster client
ClusterClient() clusterclient.Interface
// EventRecorder returns an event recorder.
EventRecorder() events.EventRecorder
}