Skip to content

Commit

Permalink
Merge pull request #3169 from sttts/sttts-no-syncs-secondary-informers
Browse files Browse the repository at this point in the history
🐛 reconcilers: ignore sync events for secondary informers
  • Loading branch information
kcp-ci-bot authored Sep 19, 2024
2 parents 8cdddb0 + 5ce1a43 commit e8bc945
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 123 deletions.
4 changes: 3 additions & 1 deletion pkg/proxy/options/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
kcpauthentication "github.com/kcp-dev/kcp/pkg/proxy/authentication"
)

const resyncPeriod = 10 * time.Hour

// Authentication wraps BuiltInAuthenticationOptions so we can minimize the
// dependencies on apiserver auth machinery, specifically by overriding the
// ApplyTo so we can remove those config dependencies not relevant to the
Expand Down Expand Up @@ -113,7 +115,7 @@ func (c *Authentication) ApplyTo(ctx context.Context, authenticationInfo *generi
return fmt.Errorf("failed to create client for ServiceAccountTokenGetter: %w", err)
}

versionedInformers := kcpkubernetesinformers.NewSharedInformerFactory(tokenGetterClient, 10*time.Minute)
versionedInformers := kcpkubernetesinformers.NewSharedInformerFactory(tokenGetterClient, resyncPeriod)

authenticatorConfig.ServiceAccountTokenGetter = serviceaccountcontroller.NewClusterGetterFromClient(
tokenGetterClient,
Expand Down
25 changes: 13 additions & 12 deletions pkg/reconciler/apis/apibinding/apibinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/kcp-dev/kcp/pkg/informer"
"github.com/kcp-dev/kcp/pkg/logging"
"github.com/kcp-dev/kcp/pkg/reconciler/committer"
"github.com/kcp-dev/kcp/pkg/reconciler/events"
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
"github.com/kcp-dev/kcp/sdk/apis/core"
kcpclientset "github.com/kcp-dev/kcp/sdk/client/clientset/versioned/cluster"
Expand Down Expand Up @@ -162,7 +163,7 @@ func NewController(
})

// CRD handlers
_, _ = crdInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
_, _ = crdInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
crd := obj.(*apiextensionsv1.CustomResourceDefinition)
return logicalcluster.From(crd) == SystemBoundCRDsClusterName
Expand All @@ -185,22 +186,22 @@ func NewController(
c.enqueueCRD(crd, logger)
},
},
})
}))

// APIExport handlers
_, _ = apiExportInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
_, _ = apiExportInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { c.enqueueAPIExport(objOrTombstone[*apisv1alpha1.APIExport](obj), logger, "") },
UpdateFunc: func(_, obj interface{}) { c.enqueueAPIExport(objOrTombstone[*apisv1alpha1.APIExport](obj), logger, "") },
DeleteFunc: func(obj interface{}) { c.enqueueAPIExport(objOrTombstone[*apisv1alpha1.APIExport](obj), logger, "") },
})
_, _ = globalAPIExportInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
}))
_, _ = globalAPIExportInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { c.enqueueAPIExport(objOrTombstone[*apisv1alpha1.APIExport](obj), logger, "") },
UpdateFunc: func(_, obj interface{}) { c.enqueueAPIExport(objOrTombstone[*apisv1alpha1.APIExport](obj), logger, "") },
DeleteFunc: func(obj interface{}) { c.enqueueAPIExport(objOrTombstone[*apisv1alpha1.APIExport](obj), logger, "") },
})
}))

// APIResourceSchema handlers
_, _ = apiResourceSchemaInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
_, _ = apiResourceSchemaInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueAPIResourceSchema(objOrTombstone[*apisv1alpha1.APIResourceSchema](obj), logger, "")
},
Expand All @@ -210,8 +211,8 @@ func NewController(
DeleteFunc: func(obj interface{}) {
c.enqueueAPIResourceSchema(objOrTombstone[*apisv1alpha1.APIResourceSchema](obj), logger, "")
},
})
_, _ = globalAPIResourceSchemaInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
}))
_, _ = globalAPIResourceSchemaInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueAPIResourceSchema(objOrTombstone[*apisv1alpha1.APIResourceSchema](obj), logger, "")
},
Expand All @@ -221,10 +222,10 @@ func NewController(
DeleteFunc: func(obj interface{}) {
c.enqueueAPIResourceSchema(objOrTombstone[*apisv1alpha1.APIResourceSchema](obj), logger, "")
},
})
}))

// APIConversion handlers
_, _ = apiConversionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
_, _ = apiConversionInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueAPIConversion(objOrTombstone[*apisv1alpha1.APIConversion](obj), logger)
},
Expand All @@ -234,7 +235,7 @@ func NewController(
DeleteFunc: func(obj interface{}) {
c.enqueueAPIConversion(objOrTombstone[*apisv1alpha1.APIConversion](obj), logger)
},
})
}))

return c, nil
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/reconciler/apis/apiexport/apiexport_controller.go
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/events"
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
kcpclientset "github.com/kcp-dev/kcp/sdk/client/clientset/versioned/cluster"
Expand Down Expand Up @@ -136,7 +137,7 @@ func NewController(
},
})

_, _ = secretInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
_, _ = secretInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueSecret(obj.(*corev1.Secret))
},
Expand All @@ -146,21 +147,20 @@ func NewController(
DeleteFunc: func(obj interface{}) {
c.enqueueSecret(obj.(*corev1.Secret))
},
})
}))

_, _ = globalShardInformer.Informer().AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueAllAPIExports(obj.(*corev1alpha1.Shard))
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueAllAPIExports(newObj.(*corev1alpha1.Shard))
},
DeleteFunc: func(obj interface{}) {
c.enqueueAllAPIExports(obj.(*corev1alpha1.Shard))
},
_, _ = globalShardInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueAllAPIExports(obj.(*corev1alpha1.Shard))
},
)
UpdateFunc: func(_, newObj interface{}) {
c.enqueueAllAPIExports(newObj.(*corev1alpha1.Shard))
},
DeleteFunc: func(obj interface{}) {
c.enqueueAllAPIExports(obj.(*corev1alpha1.Shard))
},
},
))

return c, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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/events"
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
"github.com/kcp-dev/kcp/sdk/apis/core"
corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
Expand Down Expand Up @@ -115,16 +116,16 @@ func NewController(
},
})

_, _ = globalAPIExportClusterInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
_, _ = globalAPIExportClusterInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueAPIExportEndpointSlicesForAPIExport(obj)
},
DeleteFunc: func(obj interface{}) {
c.enqueueAPIExportEndpointSlicesForAPIExport(obj)
},
})
}))

_, _ = globalShardClusterInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
_, _ = globalShardClusterInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueAllAPIExportEndpointSlices(obj)
},
Expand All @@ -136,22 +137,19 @@ func NewController(
DeleteFunc: func(obj interface{}) {
c.enqueueAllAPIExportEndpointSlices(obj)
},
},
)
}))

_, _ = partitionClusterInformer.Informer().AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueuePartition(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueuePartition(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueuePartition(obj)
},
_, _ = partitionClusterInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueuePartition(obj)
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueuePartition(newObj)
},
DeleteFunc: func(obj interface{}) {
c.enqueuePartition(obj)
},
)
}))

return c, nil
}
Expand Down
17 changes: 8 additions & 9 deletions pkg/reconciler/apis/crdcleanup/crdcleanup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/kcp-dev/kcp/pkg/indexers"
"github.com/kcp-dev/kcp/pkg/logging"
"github.com/kcp-dev/kcp/pkg/reconciler/apis/apibinding"
"github.com/kcp-dev/kcp/pkg/reconciler/events"
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
apisv1alpha1informers "github.com/kcp-dev/kcp/sdk/client/informers/externalversions/apis/v1alpha1"
)
Expand Down Expand Up @@ -92,16 +93,14 @@ func NewController(
},
})

_, _ = apiBindingInformer.Informer().AddEventHandler(
cache.ResourceEventHandlerFuncs{
UpdateFunc: func(oldObj, newObj interface{}) {
c.enqueueFromAPIBinding(oldObj.(*apisv1alpha1.APIBinding), newObj.(*apisv1alpha1.APIBinding))
},
DeleteFunc: func(obj interface{}) {
c.enqueueFromAPIBinding(nil, obj.(*apisv1alpha1.APIBinding))
},
_, _ = apiBindingInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
UpdateFunc: func(oldObj, newObj interface{}) {
c.enqueueFromAPIBinding(oldObj.(*apisv1alpha1.APIBinding), newObj.(*apisv1alpha1.APIBinding))
},
)
DeleteFunc: func(obj interface{}) {
c.enqueueFromAPIBinding(nil, obj.(*apisv1alpha1.APIBinding))
},
}))

return c, nil
}
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/indexers"
"github.com/kcp-dev/kcp/pkg/logging"
"github.com/kcp-dev/kcp/pkg/reconciler/events"
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
"github.com/kcp-dev/kcp/sdk/apis/core"
kcpclientset "github.com/kcp-dev/kcp/sdk/client/clientset/versioned/cluster"
Expand Down Expand Up @@ -109,10 +110,10 @@ func NewController(

logger := logging.WithReconciler(klog.Background(), ControllerName)

_, _ = apiExportInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
_, _ = apiExportInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { c.enqueueAPIExport(obj, logger) },
UpdateFunc: func(_, obj interface{}) { c.enqueueAPIExport(obj, logger) },
})
}))

_, _ = apiBindingInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { c.enqueueAPIBinding(obj, logger, "") },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (

configshard "github.com/kcp-dev/kcp/config/shard"
"github.com/kcp-dev/kcp/pkg/logging"
"github.com/kcp-dev/kcp/pkg/reconciler/events"
apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
"github.com/kcp-dev/kcp/sdk/apis/core"
apisv1alpha1informers "github.com/kcp-dev/kcp/sdk/client/informers/externalversions/apis/v1alpha1"
Expand Down Expand Up @@ -82,7 +83,7 @@ func NewApiExportIdentityProviderController(
},
}

_, _ = globalAPIExportInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
_, _ = globalAPIExportInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
key, err := kcpcache.DeletionHandlingMetaClusterNamespaceKeyFunc(obj)
if err != nil {
Expand All @@ -102,7 +103,7 @@ func NewApiExportIdentityProviderController(
UpdateFunc: func(old, new interface{}) { c.queue.Add(workKey) },
DeleteFunc: func(obj interface{}) { c.queue.Add(workKey) },
},
})
}))

_, _ = configMapInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
ResourceControllerName = "kcp-resource-permissionclaimlabel"
)

// NewController returns a new controller for labeling resources for accepted permission claims.
// NewResourceController returns a new controller for labeling resources for accepted permission claims.
func NewResourceController(
kcpClusterClient kcpclientset.ClusterInterface,
dynamicClusterClient kcpdynamic.ClusterInterface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/kcp-dev/kcp/pkg/reconciler/cache/labelclusterroles"
"github.com/kcp-dev/kcp/pkg/reconciler/cache/replication"
"github.com/kcp-dev/kcp/pkg/reconciler/committer"
"github.com/kcp-dev/kcp/pkg/reconciler/events"
)

type Controller interface {
Expand Down Expand Up @@ -101,7 +102,7 @@ func NewController(
},
})

_, _ = clusterRoleInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
_, _ = clusterRoleInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.FilteringResourceEventHandler{
FilterFunc: replication.IsNoSystemClusterName,
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand All @@ -114,7 +115,7 @@ func NewController(
c.enqueueClusterRole(obj)
},
},
})
}))

return c
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/kcp-dev/kcp/pkg/logging"
"github.com/kcp-dev/kcp/pkg/reconciler/cache/replication"
"github.com/kcp-dev/kcp/pkg/reconciler/committer"
"github.com/kcp-dev/kcp/pkg/reconciler/events"
)

type Controller interface {
Expand Down Expand Up @@ -100,7 +101,7 @@ func NewController(
},
})

_, _ = clusterRoleBindingInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
_, _ = clusterRoleBindingInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.FilteringResourceEventHandler{
FilterFunc: replication.IsNoSystemClusterName,
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand All @@ -113,7 +114,7 @@ func NewController(
c.enqueueClusterRoleBinding(obj)
},
},
})
}))

return c
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/kcp-dev/kcp/pkg/reconciler/cache/labelclusterroles"
"github.com/kcp-dev/kcp/pkg/reconciler/cache/replication"
"github.com/kcp-dev/kcp/pkg/reconciler/events"
"github.com/kcp-dev/kcp/sdk/apis/core"
corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
corev1alpha1informers "github.com/kcp-dev/kcp/sdk/client/informers/externalversions/core/v1alpha1"
Expand Down Expand Up @@ -61,7 +62,7 @@ func NewController(
)

// requeue all ClusterRoles when a LogicalCluster changes replication status
_, _ = logicalClusterInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
_, _ = logicalClusterInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.FilteringResourceEventHandler{
FilterFunc: replication.IsNoSystemClusterName,
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand All @@ -82,7 +83,7 @@ func NewController(
}
},
},
})
}))

return c
}
Expand Down
Loading

0 comments on commit e8bc945

Please sign in to comment.