Skip to content

Commit

Permalink
refactor(cluster-controller): bootstrap controller-manager with clust…
Browse files Browse the repository at this point in the history
…er controller
  • Loading branch information
limhawjia committed Jul 25, 2023
1 parent f562ab3 commit 0903ef9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cmd/controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ import (
const (
FederatedClusterControllerName = "cluster"
FederateControllerName = "federate"
MonitorControllerName = "monitor"
FollowerControllerName = "follower"
)

var knownControllers = map[string]controllermanager.StartControllerFunc{
FederateControllerName: startFederateController,
FederateControllerName: startFederateController,
FederatedClusterControllerName: startFederatedClusterController,
}

var controllersDisabledByDefault = sets.New(MonitorControllerName)
var controllersDisabledByDefault = sets.New[string]()

// Run starts the controller manager according to the given options.
func Run(ctx context.Context, opts *options.Options) {
Expand Down
25 changes: 25 additions & 0 deletions cmd/controller-manager/app/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/kubewharf/kubeadmiral/pkg/controllermanager"
controllercontext "github.com/kubewharf/kubeadmiral/pkg/controllers/context"
"github.com/kubewharf/kubeadmiral/pkg/controllers/federate"
"github.com/kubewharf/kubeadmiral/pkg/controllers/federatedcluster"
)

func startFederateController(
Expand All @@ -51,3 +52,27 @@ func startFederateController(

return federateController, nil
}

func startFederatedClusterController(
ctx context.Context,
controllerCtx *controllercontext.Context,
) (controllermanager.Controller, error) {
federatedClusterController, err := federatedcluster.NewFederatedClusterController(
controllerCtx.KubeClientset,
controllerCtx.FedClientset,
controllerCtx.FedInformerFactory.Core().V1alpha1().FederatedClusters(),
controllerCtx.FederatedInformerManager,
controllerCtx.Metrics,
klog.Background(),
controllerCtx.ComponentConfig.ClusterJoinTimeout,
controllerCtx.WorkerCount,
controllerCtx.FedSystemNamespace,
)
if err != nil {
return nil, fmt.Errorf("error creating federate controller: %w", err)
}

go federatedClusterController.Run(ctx)

return federatedClusterController, nil
}

0 comments on commit 0903ef9

Please sign in to comment.