Skip to content

Commit

Permalink
refactor: namespace auto propagation controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlihanbo committed Jul 26, 2023
1 parent 16bee50 commit 5fc802d
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 146 deletions.
12 changes: 7 additions & 5 deletions cmd/controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ import (
)

const (
FederatedClusterControllerName = "cluster"
FederateControllerName = "federate"
MonitorControllerName = "monitor"
FollowerControllerName = "follower"
FederatedClusterControllerName = "cluster"
FederateControllerName = "federate"
MonitorControllerName = "monitor"
FollowerControllerName = "follower"
NamespaceAutoPropagationControllerName = "nsautoprop"
)

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

var controllersDisabledByDefault = sets.New(MonitorControllerName)
Expand Down
27 changes: 27 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/nsautoprop"
)

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

return federateController, nil
}

func startNamespaceAutoPropagationController(
ctx context.Context,
controllerCtx *controllercontext.Context,
) (controllermanager.Controller, error) {
nsAutoPropController, err := nsautoprop.NewNamespaceAutoPropagationController(
controllerCtx.KubeClientset,
controllerCtx.InformerManager,
controllerCtx.FedClientset,
controllerCtx.FedInformerFactory.Core().V1alpha1().FederatedClusters(),
controllerCtx.FedInformerFactory.Core().V1alpha1().ClusterFederatedObjects(),
controllerCtx.KubeInformerFactory.Core().V1().Namespaces(),
controllerCtx.ComponentConfig.NSAutoPropExcludeRegexp,
controllerCtx.FedSystemNamespace,
controllerCtx.Metrics,
klog.Background(),
controllerCtx.WorkerCount,
)
if err != nil {
return nil, fmt.Errorf("error creating namespace auto propagation controller: %w", err)
}

go nsAutoPropController.Run(ctx)

return nsAutoPropController, nil
}
Loading

0 comments on commit 5fc802d

Please sign in to comment.