Skip to content

Commit

Permalink
reconciler/cache/reconciler: ignore system:* clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
sttts committed Jan 12, 2023
1 parent 57c7b68 commit df7ce89
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/kcp-dev/kcp/pkg/indexers"
"github.com/kcp-dev/kcp/pkg/logging"
"github.com/kcp-dev/kcp/pkg/reconciler/committer"
"github.com/kcp-dev/kcp/pkg/reconciler/cache/replication"
)

const (
Expand Down Expand Up @@ -72,27 +73,33 @@ func NewController(
ClusterRoleBindingByClusterRoleName: IndexClusterRoleBindingByClusterRoleName,
})

clusterRoleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueClusterRole(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueClusterRole(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueueClusterRole(obj)
clusterRoleInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: replication.IsNoSystemClusterName,
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueClusterRole(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueClusterRole(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueueClusterRole(obj)
},
},
})

clusterRoleBindingInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueClusterRoleBinding(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueClusterRoleBinding(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueueClusterRoleBinding(obj)
clusterRoleBindingInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: replication.IsNoSystemClusterName,
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueClusterRoleBinding(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueClusterRoleBinding(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueueClusterRoleBinding(obj)
},
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/kcp-dev/kcp/pkg/logging"
"github.com/kcp-dev/kcp/pkg/reconciler/apis/replicationclusterrole"
"github.com/kcp-dev/kcp/pkg/reconciler/committer"
"github.com/kcp-dev/kcp/pkg/reconciler/cache/replication"
)

const (
Expand Down Expand Up @@ -72,27 +73,33 @@ func NewController(
replicationclusterrole.ClusterRoleBindingByClusterRoleName: replicationclusterrole.IndexClusterRoleBindingByClusterRoleName,
})

clusterRoleBindingInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueClusterRoleBinding(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueClusterRoleBinding(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueueClusterRoleBinding(obj)
clusterRoleBindingInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: replication.IsNoSystemClusterName,
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueClusterRoleBinding(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueClusterRoleBinding(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueueClusterRoleBinding(obj)
},
},
})

clusterRoleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueClusterRole(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueClusterRole(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueueClusterRole(obj)
clusterRoleInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: replication.IsNoSystemClusterName,
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueClusterRole(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueClusterRole(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueueClusterRole(obj)
},
},
})

Expand Down
41 changes: 33 additions & 8 deletions pkg/reconciler/cache/replication/replication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package replication
import (
"context"
"fmt"
"strings"
"time"

kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache"
Expand Down Expand Up @@ -119,16 +120,22 @@ func NewController(
// shadow gvr to get the right value in the closure
gvr := gvr

info.local.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { c.enqueueObject(obj, gvr) },
UpdateFunc: func(_, obj interface{}) { c.enqueueObject(obj, gvr) },
DeleteFunc: func(obj interface{}) { c.enqueueObject(obj, gvr) },
info.local.AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: IsNoSystemClusterName,
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { c.enqueueObject(obj, gvr) },
UpdateFunc: func(_, obj interface{}) { c.enqueueObject(obj, gvr) },
DeleteFunc: func(obj interface{}) { c.enqueueObject(obj, gvr) },
},
})

info.global.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { c.enqueueCacheObject(obj, gvr) },
UpdateFunc: func(_, obj interface{}) { c.enqueueCacheObject(obj, gvr) },
DeleteFunc: func(obj interface{}) { c.enqueueCacheObject(obj, gvr) },
info.global.AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: IsNoSystemClusterName, // not really needed, but cannot harm
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { c.enqueueCacheObject(obj, gvr) },
UpdateFunc: func(_, obj interface{}) { c.enqueueCacheObject(obj, gvr) },
DeleteFunc: func(obj interface{}) { c.enqueueCacheObject(obj, gvr) },
},
})
}

Expand Down Expand Up @@ -197,6 +204,24 @@ func (c *controller) processNextWorkItem(ctx context.Context) bool {
return true
}

func IsNoSystemClusterName(obj interface{}) bool {
key, err := kcpcache.DeletionHandlingMetaClusterNamespaceKeyFunc(obj)
if err != nil {
runtime.HandleError(err)
return false
}

clusterName, _, _, err := kcpcache.SplitMetaClusterNamespaceKey(key)
if err != nil {
runtime.HandleError(err)
return false
}
if strings.HasPrefix(clusterName.String(), "system:") {
return false
}
return true
}

type controller struct {
shardName string
queue workqueue.RateLimitingInterface
Expand Down

0 comments on commit df7ce89

Please sign in to comment.