Skip to content

Commit

Permalink
chore: fix index consts comments and remove unused cluster plugin (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek authored Sep 25, 2024
1 parent da533ac commit f1fd23a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 63 deletions.
25 changes: 3 additions & 22 deletions controller/konnect/index_kongpluginbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import (
const (
// IndexFieldKongPluginBindingKongPluginReference is the index field for KongPlugin -> KongPluginBinding.
IndexFieldKongPluginBindingKongPluginReference = "kongPluginRef"
// IndexFieldKongPluginBindingKongClusterPluginReference is the index field for KongClusterPlugin -> KongPluginBinding.
IndexFieldKongPluginBindingKongClusterPluginReference = "kongClusterPluginRef"
// IndexFieldKongPluginBindingKongServiceReference is the index field for KongService -> KongPluginBinding.
IndexFieldKongPluginBindingKongServiceReference = "kongServiceRef"
// IndexFieldKongPluginBindingKongServiceReference is the index field for KongRoute -> KongPluginBinding.
// IndexFieldKongPluginBindingKongRouteReference is the index field for KongRoute -> KongPluginBinding.
IndexFieldKongPluginBindingKongRouteReference = "kongRouteRef"
// IndexFieldKongPluginBindingKongServiceReference is the index field for KongConsumer -> KongPluginBinding.
// IndexFieldKongPluginBindingKongConsumerReference is the index field for KongConsumer -> KongPluginBinding.
IndexFieldKongPluginBindingKongConsumerReference = "kongConsumerRef"
// IndexFieldKongPluginBindingKongServiceReference is the index field for KongConsumerGroup -> KongPluginBinding.
// IndexFieldKongPluginBindingKongConsumerGroupReference is the index field for KongConsumerGroup -> KongPluginBinding.
IndexFieldKongPluginBindingKongConsumerGroupReference = "kongConsumerGroupRef"
)

Expand All @@ -29,11 +27,6 @@ func IndexOptionsForKongPluginBinding() []ReconciliationIndexOption {
IndexField: IndexFieldKongPluginBindingKongPluginReference,
ExtractValue: kongPluginReferencesFromKongPluginBinding,
},
{
IndexObject: &configurationv1alpha1.KongPluginBinding{},
IndexField: IndexFieldKongPluginBindingKongClusterPluginReference,
ExtractValue: kongClusterPluginReferencesFromKongPluginBinding,
},
{
IndexObject: &configurationv1alpha1.KongPluginBinding{},
IndexField: IndexFieldKongPluginBindingKongServiceReference,
Expand Down Expand Up @@ -69,18 +62,6 @@ func kongPluginReferencesFromKongPluginBinding(obj client.Object) []string {
return []string{binding.Namespace + "/" + binding.Spec.PluginReference.Name}
}

// kongClusterPluginReferencesFromKongPluginBinding returns name of referenced KongClusterPlugin in KongPluginBinding spec.
func kongClusterPluginReferencesFromKongPluginBinding(obj client.Object) []string {
binding, ok := obj.(*configurationv1alpha1.KongPluginBinding)
if !ok {
return nil
}
if binding.Spec.PluginReference.Kind == nil || *binding.Spec.PluginReference.Kind != "KongClusterPlugin" {
return nil
}
return []string{binding.Spec.PluginReference.Name}
}

// kongServiceReferencesFromKongPluginBinding returns name of referenced KongService in KongPluginBinding spec.
func kongServiceReferencesFromKongPluginBinding(obj client.Object) []string {
binding, ok := obj.(*configurationv1alpha1.KongPluginBinding)
Expand Down
41 changes: 0 additions & 41 deletions controller/konnect/watch_kongpluginbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ func KongPluginBindingReconciliationWatchOptions(
),
)
},
func(b *ctrl.Builder) *ctrl.Builder {
return b.Watches(
&configurationv1.KongClusterPlugin{},
handler.EnqueueRequestsFromMapFunc(
enqueueKongPluginBindingForKongClusterPlugin(cl),
),
)
},
func(b *ctrl.Builder) *ctrl.Builder {
return b.Watches(
&configurationv1alpha1.KongService{},
Expand Down Expand Up @@ -307,39 +299,6 @@ func enqueueKongPluginBindingForKongPlugin(cl client.Client) func(
}
}

func enqueueKongPluginBindingForKongClusterPlugin(cl client.Client) func(
ctx context.Context, obj client.Object) []reconcile.Request {
return func(ctx context.Context, obj client.Object) []reconcile.Request {
plugin, ok := obj.(*configurationv1.KongClusterPlugin)
if !ok {
return nil
}

pluginBindingList := configurationv1alpha1.KongPluginBindingList{}
err := cl.List(ctx, &pluginBindingList,
client.MatchingFields{
IndexFieldKongPluginBindingKongClusterPluginReference: plugin.Name,
},
)
if err != nil {
ctrllog.FromContext(ctx).Error(err, "failed to list KongPluginBindings referencing KongClusterPlugin")
}

return lo.FilterMap(pluginBindingList.Items, func(pb configurationv1alpha1.KongPluginBinding, _ int) (reconcile.Request, bool) {
// Only put KongPluginBindings referencing to a Konnect control plane,
if pb.Spec.ControlPlaneRef == nil || pb.Spec.ControlPlaneRef.Type != configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef {
return reconcile.Request{}, false
}
return reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: pb.Namespace,
Name: pb.Name,
},
}, true
})
}
}

func enqueueKongPluginBindingForKongService(cl client.Client) func(
ctx context.Context, obj client.Object) []reconcile.Request {
return func(ctx context.Context, obj client.Object) []reconcile.Request {
Expand Down

0 comments on commit f1fd23a

Please sign in to comment.