Files
open-cluster-management/pkg/placement/controllers/manager.go
Jian Zhu 7332a585c0 🌱 add a verify rule for golang files import order (#177)
* 🌱 add a verify rule for golang files import order

This PR uses the [gci tool](https://github.com/daixiang0/gci) to make all go files' import section with a specific order, it will organize import with group with order:
1. standard library modules
2. 3rd party modules
3. modules in OCM org, like the `open-cluster-management.io/api`
4. current project `open-cluster-management.io/ocm` modules

developers can use the `make fmt-imports` to format the import automatically and the `make verify-fmt-imports` to check for any violation.

Signed-off-by: zhujian <jiazhu@redhat.com>

* 🌱 format the go files import

Signed-off-by: zhujian <jiazhu@redhat.com>

---------

Signed-off-by: zhujian <jiazhu@redhat.com>
2023-06-12 10:23:04 -04:00

86 lines
2.7 KiB
Go

package hub
import (
"context"
"net/http"
"time"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"k8s.io/apiserver/pkg/server/mux"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/events"
clusterclient "open-cluster-management.io/api/client/cluster/clientset/versioned"
clusterscheme "open-cluster-management.io/api/client/cluster/clientset/versioned/scheme"
clusterinformers "open-cluster-management.io/api/client/cluster/informers/externalversions"
scheduling "open-cluster-management.io/ocm/pkg/placement/controllers/scheduling"
"open-cluster-management.io/ocm/pkg/placement/debugger"
)
// RunControllerManager starts the controllers on hub to make placement decisions.
func RunControllerManager(ctx context.Context, controllerContext *controllercmd.ControllerContext) error {
kubeConf := controllerContext.KubeConfig
kubeConf.QPS = 50
kubeConf.Burst = 100
clusterClient, err := clusterclient.NewForConfig(controllerContext.KubeConfig)
if err != nil {
return err
}
kubeClient, err := kubernetes.NewForConfig(controllerContext.KubeConfig)
if err != nil {
return err
}
clusterInformers := clusterinformers.NewSharedInformerFactory(clusterClient, 10*time.Minute)
broadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: kubeClient.EventsV1()})
broadcaster.StartRecordingToSink(ctx.Done())
recorder := broadcaster.NewRecorder(clusterscheme.Scheme, "placementController")
scheduler := scheduling.NewPluginScheduler(
scheduling.NewSchedulerHandler(
clusterClient,
clusterInformers.Cluster().V1beta1().PlacementDecisions().Lister(),
clusterInformers.Cluster().V1alpha1().AddOnPlacementScores().Lister(),
clusterInformers.Cluster().V1().ManagedClusters().Lister(),
recorder),
)
if controllerContext.Server != nil {
debug := debugger.NewDebugger(
scheduler,
clusterInformers.Cluster().V1beta1().Placements(),
clusterInformers.Cluster().V1().ManagedClusters(),
)
installDebugger(controllerContext.Server.Handler.NonGoRestfulMux, debug)
}
schedulingController := scheduling.NewSchedulingController(
clusterClient,
clusterInformers.Cluster().V1().ManagedClusters(),
clusterInformers.Cluster().V1beta2().ManagedClusterSets(),
clusterInformers.Cluster().V1beta2().ManagedClusterSetBindings(),
clusterInformers.Cluster().V1beta1().Placements(),
clusterInformers.Cluster().V1beta1().PlacementDecisions(),
clusterInformers.Cluster().V1alpha1().AddOnPlacementScores(),
scheduler,
controllerContext.EventRecorder, recorder,
)
go clusterInformers.Start(ctx.Done())
go schedulingController.Run(ctx, 1)
<-ctx.Done()
return nil
}
func installDebugger(mux *mux.PathRecorderMux, d *debugger.Debugger) {
mux.HandlePrefix(debugger.DebugPath, http.HandlerFunc(d.Handler))
}