Skip to content

Commit

Permalink
refactor: follower controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlihanbo committed Jul 27, 2023
1 parent 0e385a7 commit 05216de
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 267 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions cmd/controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var knownControllers = map[string]controllermanager.StartControllerFunc{
OverrideControllerName: startOverridePolicyController,
NamespaceAutoPropagationControllerName: startNamespaceAutoPropagationController,
StatusControllerName: startStatusController,
FollowerControllerName: startFollowerController,
}

var controllersDisabledByDefault = sets.New(MonitorControllerName)
Expand Down
24 changes: 24 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/follower"
"github.com/kubewharf/kubeadmiral/pkg/controllers/nsautoprop"
"github.com/kubewharf/kubeadmiral/pkg/controllers/override"
"github.com/kubewharf/kubeadmiral/pkg/controllers/policyrc"
Expand Down Expand Up @@ -152,3 +153,26 @@ func startStatusController(

return statusController, nil
}

func startFollowerController(
ctx context.Context,
controllerCtx *controllercontext.Context,
) (controllermanager.Controller, error) {
controller, err := follower.NewFollowerController(
controllerCtx.KubeClientset,
controllerCtx.FedClientset,
controllerCtx.InformerManager,
controllerCtx.FedInformerFactory.Core().V1alpha1().FederatedObjects(),
controllerCtx.FedInformerFactory.Core().V1alpha1().ClusterFederatedObjects(),
controllerCtx.Metrics,
klog.Background(),
controllerCtx.WorkerCount,
)
if err != nil {
return nil, fmt.Errorf("error creating follower controller: %w", err)
}

go controller.Run(ctx)

return controller, nil
}
5 changes: 2 additions & 3 deletions pkg/controllers/follower/bidirectional_cache.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build exclude
/*
Copyright 2023 The KubeAdmiral Authors.
Expand Down Expand Up @@ -40,13 +39,13 @@ type bidirectionalCache[V1, V2 comparable] struct {
func (c *bidirectionalCache[V1, V2]) lookup(key V1) sets.Set[V2] {
c.RLock()
defer c.RUnlock()
return c.cache[key]
return c.cache[key].Clone()
}

func (c *bidirectionalCache[V1, V2]) reverseLookup(key V2) sets.Set[V1] {
c.RLock()
defer c.RUnlock()
return c.reverseCache[key]
return c.reverseCache[key].Clone()
}

func (c *bidirectionalCache[V1, V2]) update(key V1, newValues sets.Set[V2]) {
Expand Down
Loading

0 comments on commit 05216de

Please sign in to comment.