From 01cbf499b91f0c89f804b79006800c378a4d2d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Fri, 20 Dec 2024 17:25:44 +0100 Subject: [PATCH] fix(konnect): fix EnqueueRequestsFromMapFunc predicates for konnect entities --- CHANGELOG.md | 5 +++++ controller/konnect/reconciler_kongplugin.go | 13 +++++++++++++ controller/konnect/watch_credentialacl.go | 3 +++ controller/konnect/watch_credentialapikey.go | 3 +++ controller/konnect/watch_credentialbasicauth.go | 3 +++ controller/konnect/watch_credentialhmac.go | 3 +++ controller/konnect/watch_credentialjwt.go | 3 +++ controller/konnect/watch_kongconsumer.go | 3 +++ controller/konnect/watch_kongpluginbinding.go | 12 ++++++++++++ controller/konnect/watch_kongroute.go | 3 +++ controller/konnect/watch_kongsni.go | 3 +++ 11 files changed, 54 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eff94380..c8968d10f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,11 @@ ## Unreleased +### Fixes + +- Fix watch predicates for types shared between KGO and KIC. + [#948](https://github.com/Kong/gateway-operator/pull/948) + ### Changed - `KonnectExtension` does not require `spec.serverHostname` to be set by a user diff --git a/controller/konnect/reconciler_kongplugin.go b/controller/konnect/reconciler_kongplugin.go index e43b7a53b..67809adf1 100644 --- a/controller/konnect/reconciler_kongplugin.go +++ b/controller/konnect/reconciler_kongplugin.go @@ -17,6 +17,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/predicate" "github.com/kong/gateway-operator/controller/pkg/log" "github.com/kong/gateway-operator/pkg/consts" @@ -60,6 +61,9 @@ func (r *KongPluginReconciler) SetupWithManager(_ context.Context, mgr ctrl.Mana builder.WithPredicates( kongPluginsAnnotationChangedPredicate, ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1alpha1.KongService]), + ), ). Watches( &configurationv1alpha1.KongRoute{}, @@ -67,6 +71,9 @@ func (r *KongPluginReconciler) SetupWithManager(_ context.Context, mgr ctrl.Mana builder.WithPredicates( kongPluginsAnnotationChangedPredicate, ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1alpha1.KongRoute]), + ), ). Watches( &configurationv1.KongConsumer{}, @@ -74,6 +81,9 @@ func (r *KongPluginReconciler) SetupWithManager(_ context.Context, mgr ctrl.Mana builder.WithPredicates( kongPluginsAnnotationChangedPredicate, ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1.KongConsumer]), + ), ). Watches( &configurationv1beta1.KongConsumerGroup{}, @@ -81,6 +91,9 @@ func (r *KongPluginReconciler) SetupWithManager(_ context.Context, mgr ctrl.Mana builder.WithPredicates( kongPluginsAnnotationChangedPredicate, ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1beta1.KongConsumerGroup]), + ), ). Complete(r) } diff --git a/controller/konnect/watch_credentialacl.go b/controller/konnect/watch_credentialacl.go index a2f975378..117a3f6a8 100644 --- a/controller/konnect/watch_credentialacl.go +++ b/controller/konnect/watch_credentialacl.go @@ -46,6 +46,9 @@ func kongCredentialACLReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( kongCredentialACLForKongConsumer(cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1.KongConsumer]), + ), ) }, func(b *ctrl.Builder) *ctrl.Builder { diff --git a/controller/konnect/watch_credentialapikey.go b/controller/konnect/watch_credentialapikey.go index 0764568dd..aa0fb7314 100644 --- a/controller/konnect/watch_credentialapikey.go +++ b/controller/konnect/watch_credentialapikey.go @@ -46,6 +46,9 @@ func kongCredentialAPIKeyReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( kongCredentialAPIKeyForKongConsumer(cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1.KongConsumer]), + ), ) }, func(b *ctrl.Builder) *ctrl.Builder { diff --git a/controller/konnect/watch_credentialbasicauth.go b/controller/konnect/watch_credentialbasicauth.go index cabd7a401..2d2d16e31 100644 --- a/controller/konnect/watch_credentialbasicauth.go +++ b/controller/konnect/watch_credentialbasicauth.go @@ -46,6 +46,9 @@ func kongCredentialBasicAuthReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( kongCredentialBasicAuthForKongConsumer(cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1.KongConsumer]), + ), ) }, func(b *ctrl.Builder) *ctrl.Builder { diff --git a/controller/konnect/watch_credentialhmac.go b/controller/konnect/watch_credentialhmac.go index ed00f41fe..d7b08ced9 100644 --- a/controller/konnect/watch_credentialhmac.go +++ b/controller/konnect/watch_credentialhmac.go @@ -46,6 +46,9 @@ func kongCredentialHMACReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( kongCredentialHMACForKongConsumer(cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1.KongConsumer]), + ), ) }, func(b *ctrl.Builder) *ctrl.Builder { diff --git a/controller/konnect/watch_credentialjwt.go b/controller/konnect/watch_credentialjwt.go index d4fe698fe..097f1e0af 100644 --- a/controller/konnect/watch_credentialjwt.go +++ b/controller/konnect/watch_credentialjwt.go @@ -46,6 +46,9 @@ func kongCredentialJWTReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( kongCredentialJWTForKongConsumer(cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1.KongConsumer]), + ), ) }, func(b *ctrl.Builder) *ctrl.Builder { diff --git a/controller/konnect/watch_kongconsumer.go b/controller/konnect/watch_kongconsumer.go index 385c96660..e87176996 100644 --- a/controller/konnect/watch_kongconsumer.go +++ b/controller/konnect/watch_kongconsumer.go @@ -66,6 +66,9 @@ func KongConsumerReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( enqueueKongConsumerForKongConsumerGroup(cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1beta1.KongConsumerGroup]), + ), ) }, } diff --git a/controller/konnect/watch_kongpluginbinding.go b/controller/konnect/watch_kongpluginbinding.go index dd9731356..3c80ccf40 100644 --- a/controller/konnect/watch_kongpluginbinding.go +++ b/controller/konnect/watch_kongpluginbinding.go @@ -80,6 +80,9 @@ func KongPluginBindingReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( enqueueKongPluginBindingFor[configurationv1alpha1.KongService](cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1alpha1.KongService]), + ), ) }, func(b *ctrl.Builder) *ctrl.Builder { @@ -88,6 +91,9 @@ func KongPluginBindingReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( enqueueKongPluginBindingFor[configurationv1alpha1.KongRoute](cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1alpha1.KongRoute]), + ), ) }, func(b *ctrl.Builder) *ctrl.Builder { @@ -96,6 +102,9 @@ func KongPluginBindingReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( enqueueKongPluginBindingFor[configurationv1.KongConsumer](cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1.KongConsumer]), + ), ) }, func(b *ctrl.Builder) *ctrl.Builder { @@ -104,6 +113,9 @@ func KongPluginBindingReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( enqueueKongPluginBindingFor[configurationv1beta1.KongConsumerGroup](cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1beta1.KongConsumerGroup]), + ), ) }, } diff --git a/controller/konnect/watch_kongroute.go b/controller/konnect/watch_kongroute.go index 09c404271..6d0216b0c 100644 --- a/controller/konnect/watch_kongroute.go +++ b/controller/konnect/watch_kongroute.go @@ -45,6 +45,9 @@ func KongRouteReconciliationWatchOptions( handler.EnqueueRequestsFromMapFunc( enqueueKongRouteForKongService(cl), ), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1alpha1.KongService]), + ), ) }, } diff --git a/controller/konnect/watch_kongsni.go b/controller/konnect/watch_kongsni.go index f97d6ab9b..02fabdcde 100644 --- a/controller/konnect/watch_kongsni.go +++ b/controller/konnect/watch_kongsni.go @@ -32,6 +32,9 @@ func KongSNIReconciliationWatchOptions(cl client.Client, return b.Watches( &configurationv1alpha1.KongCertificate{}, handler.EnqueueRequestsFromMapFunc(enqueueKongSNIForKongCertificate(cl)), + builder.WithPredicates( + predicate.NewPredicateFuncs(objRefersToKonnectGatewayControlPlane[configurationv1alpha1.KongCertificate]), + ), ) }, }