Skip to content

Commit 59822ba

Browse files
authored
fixup (#2139)
Signed-off-by: jose.vazquez <[email protected]>
1 parent 6af154a commit 59822ba

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

internal/controller/registry.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"go.uber.org/zap"
88
ctrl "sigs.k8s.io/controller-runtime"
9+
"sigs.k8s.io/controller-runtime/pkg/client"
910
"sigs.k8s.io/controller-runtime/pkg/cluster"
1011
"sigs.k8s.io/controller-runtime/pkg/predicate"
1112
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -68,28 +69,28 @@ func (r *Registry) RegisterWithManager(mgr ctrl.Manager, skipNameValidation bool
6869

6970
func (r *Registry) registerControllers(c cluster.Cluster, ap atlas.Provider) {
7071
var reconcilers []AkoReconciler
71-
reconcilers = append(reconcilers, atlasproject.NewAtlasProjectReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.logger))
72-
reconcilers = append(reconcilers, atlasdeployment.NewAtlasDeploymentReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.independentSyncPeriod, r.logger))
73-
reconcilers = append(reconcilers, atlasdatabaseuser.NewAtlasDatabaseUserReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.independentSyncPeriod, r.featureFlags, r.logger))
74-
reconcilers = append(reconcilers, atlasdatafederation.NewAtlasDataFederationReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.logger))
75-
reconcilers = append(reconcilers, atlasfederatedauth.NewAtlasFederatedAuthReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.logger))
76-
reconcilers = append(reconcilers, atlasstream.NewAtlasStreamsInstanceReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.logger))
77-
reconcilers = append(reconcilers, atlasstream.NewAtlasStreamsConnectionReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.logger))
78-
reconcilers = append(reconcilers, atlassearchindexconfig.NewAtlasSearchIndexConfigReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.logger))
79-
reconcilers = append(reconcilers, atlasbackupcompliancepolicy.NewAtlasBackupCompliancePolicyReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.logger))
80-
reconcilers = append(reconcilers, atlascustomrole.NewAtlasCustomRoleReconciler(c, r.legacyPredicates(), ap, r.deletionProtection, r.independentSyncPeriod, r.logger))
72+
reconcilers = append(reconcilers, atlasproject.NewAtlasProjectReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.logger))
73+
reconcilers = append(reconcilers, atlasdeployment.NewAtlasDeploymentReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.independentSyncPeriod, r.logger))
74+
reconcilers = append(reconcilers, atlasdatabaseuser.NewAtlasDatabaseUserReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.independentSyncPeriod, r.featureFlags, r.logger))
75+
reconcilers = append(reconcilers, atlasdatafederation.NewAtlasDataFederationReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.logger))
76+
reconcilers = append(reconcilers, atlasfederatedauth.NewAtlasFederatedAuthReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.logger))
77+
reconcilers = append(reconcilers, atlasstream.NewAtlasStreamsInstanceReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.logger))
78+
reconcilers = append(reconcilers, atlasstream.NewAtlasStreamsConnectionReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.logger))
79+
reconcilers = append(reconcilers, atlassearchindexconfig.NewAtlasSearchIndexConfigReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.logger))
80+
reconcilers = append(reconcilers, atlasbackupcompliancepolicy.NewAtlasBackupCompliancePolicyReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.logger))
81+
reconcilers = append(reconcilers, atlascustomrole.NewAtlasCustomRoleReconciler(c, r.deprecatedPredicates(), ap, r.deletionProtection, r.independentSyncPeriod, r.logger))
8182
reconcilers = append(reconcilers, atlasprivateendpoint.NewAtlasPrivateEndpointReconciler(c, r.defaultPredicates(), ap, r.deletionProtection, r.independentSyncPeriod, r.logger))
8283
reconcilers = append(reconcilers, atlasipaccesslist.NewAtlasIPAccessListReconciler(c, r.defaultPredicates(), ap, r.deletionProtection, r.independentSyncPeriod, r.logger))
8384
r.reconcilers = reconcilers
8485
}
8586

86-
// legacyPredicates are to be phased out in favor of defaultPredicates
87-
func (r *Registry) legacyPredicates() []predicate.Predicate {
88-
return append(r.sharedPredicates, watch.CommonPredicates())
87+
// deprecatedPredicates are to be phased out in favor of defaultPredicates
88+
func (r *Registry) deprecatedPredicates() []predicate.Predicate {
89+
return append(r.sharedPredicates, watch.DeprecatedCommonPredicates())
8990
}
9091

9192
// defaultPredicates minimize the reconciliations controllers actually do, avoiding
9293
// spurious after delete handling and acting on finalizers setting or unsetting
9394
func (r *Registry) defaultPredicates() []predicate.Predicate {
94-
return append(r.sharedPredicates, watch.DefaultPredicates())
95+
return append(r.sharedPredicates, watch.DefaultPredicates[client.Object]())
9596
}

internal/controller/watch/predicates.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package watch
33
import (
44
"reflect"
55

6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
67
"sigs.k8s.io/controller-runtime/pkg/client"
78
"sigs.k8s.io/controller-runtime/pkg/event"
89
"sigs.k8s.io/controller-runtime/pkg/predicate"
910
)
1011

11-
// CommonPredicates returns the predicate which filter out the changes done to any field except for spec (e.g. status)
12+
// DeprecatedCommonPredicates returns the predicate which filter out the changes done to any field except for spec (e.g. status)
1213
// Also we should reconcile if finalizers have changed (see https://blog.openshift.com/kubernetes-operators-best-practices/)
1314
// This will be phased out gradually to be replaced by DefaultPredicates
14-
func CommonPredicates() predicate.Funcs {
15+
func DeprecatedCommonPredicates() predicate.Funcs {
1516
return predicate.Funcs{
1617
UpdateFunc: func(e event.UpdateEvent) bool {
1718
if e.ObjectOld.GetResourceVersion() == e.ObjectNew.GetResourceVersion() {
@@ -45,27 +46,27 @@ func SelectNamespacesPredicate(namespaces []string) predicate.Funcs {
4546

4647
// GlobalResyncAwareGenerationChangePredicate reconcile on unfrequent global
4748
// resyncs or on spec generation changes, but ignore finalizer changes
48-
func GlobalResyncAwareGenerationChangePredicate() predicate.Predicate {
49-
return predicate.Or[client.Object](
50-
predicate.Not[client.Object](predicate.ResourceVersionChangedPredicate{}), // for the global resync
51-
predicate.GenerationChangedPredicate{},
49+
func GlobalResyncAwareGenerationChangePredicate[T metav1.Object]() predicate.TypedPredicate[T] {
50+
return predicate.Or[T](
51+
predicate.Not[T](predicate.TypedResourceVersionChangedPredicate[T]{}), // for the global resync
52+
predicate.TypedGenerationChangedPredicate[T]{},
5253
)
5354
}
5455

5556
// IgnoreDeletedPredicate ignore after deletion handling, use unless some after
5657
// deletion cleanup is needed
57-
func IgnoreDeletedPredicate() predicate.Predicate {
58-
return predicate.Funcs{
59-
DeleteFunc: func(e event.DeleteEvent) bool {
58+
func IgnoreDeletedPredicate[T metav1.Object]() predicate.TypedPredicate[T] {
59+
return predicate.TypedFuncs[T]{
60+
DeleteFunc: func(e event.TypedDeleteEvent[T]) bool {
6061
return false
6162
},
6263
}
6364
}
6465

6566
// DefaultPredicates avoid spurious after deletion or finalizer changes handling
66-
func DefaultPredicates() predicate.Predicate {
67-
return predicate.And(
68-
GlobalResyncAwareGenerationChangePredicate(),
69-
IgnoreDeletedPredicate(),
67+
func DefaultPredicates[T metav1.Object]() predicate.TypedPredicate[T] {
68+
return predicate.And[T](
69+
GlobalResyncAwareGenerationChangePredicate[T](),
70+
IgnoreDeletedPredicate[T](),
7071
)
7172
}

internal/operator/builder.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ func mergeDefaults(b *Builder) {
266266

267267
if len(b.predicates) == 0 {
268268
b.predicates = []predicate.Predicate{
269-
watch.CommonPredicates(),
270269
watch.SelectNamespacesPredicate(b.namespaces),
271270
}
272271
}

0 commit comments

Comments
 (0)