Files
open-cluster-management/pkg/controllers/manager.go
Jian Qiu 81dd4ec841 Update deps and actions
Signed-off-by: Jian Qiu <jqiu@redhat.com>
2021-06-22 14:15:31 +08:00

39 lines
1.3 KiB
Go

package hub
import (
"context"
"time"
"github.com/openshift/library-go/pkg/controller/controllercmd"
clusterclient "open-cluster-management.io/api/client/cluster/clientset/versioned"
clusterinformers "open-cluster-management.io/api/client/cluster/informers/externalversions"
scheduling "open-cluster-management.io/placement/pkg/controllers/scheduling"
)
// RunControllerManager starts the controllers on hub to make placement decisions.
func RunControllerManager(ctx context.Context, controllerContext *controllercmd.ControllerContext) error {
clusterClient, err := clusterclient.NewForConfig(controllerContext.KubeConfig)
if err != nil {
return err
}
clusterInformers := clusterinformers.NewSharedInformerFactory(clusterClient, 10*time.Minute)
schedulingController := scheduling.NewSchedulingController(
clusterClient,
clusterInformers.Cluster().V1().ManagedClusters(),
clusterInformers.Cluster().V1alpha1().ManagedClusterSets(),
clusterInformers.Cluster().V1alpha1().ManagedClusterSetBindings(),
clusterInformers.Cluster().V1alpha1().Placements(),
clusterInformers.Cluster().V1alpha1().PlacementDecisions(),
controllerContext.EventRecorder,
)
go clusterInformers.Start(ctx.Done())
go schedulingController.Run(ctx, 1)
<-ctx.Done()
return nil
}