From eb888b4e2dfbfae8127b5a49773967fa9d378f25 Mon Sep 17 00:00:00 2001 From: Harry Bagdi Date: Fri, 31 Aug 2018 09:06:11 -0700 Subject: [PATCH] feat: add a method to list all KongPlugin resources with global label --- internal/ingress/controller/store/store.go | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/ingress/controller/store/store.go b/internal/ingress/controller/store/store.go index 749d74b9d4..88e0a12701 100644 --- a/internal/ingress/controller/store/store.go +++ b/internal/ingress/controller/store/store.go @@ -22,6 +22,9 @@ import ( "sync" "time" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/selection" + "github.com/eapache/channels" "github.com/golang/glog" @@ -92,6 +95,8 @@ type Storer interface { ListKongConsumers() []*consumerv1.KongConsumer ListKongCredentials() []*credentialv1.KongCredential + + ListGlobalKongPlugins() ([]*pluginv1.KongPlugin, error) } // EventType type of event associated with an informer @@ -657,3 +662,24 @@ func (s k8sStore) ListKongCredentials() []*credentialv1.KongCredential { return credentials } + +func (s k8sStore) ListGlobalKongPlugins() ([]*pluginv1.KongPlugin, error) { + + var plugins []*pluginv1.KongPlugin + // var globalPlugins []*pluginv1.KongPlugin + req, err := labels.NewRequirement("global", selection.Equals, []string{"true"}) + if err != nil { + return nil, err + } + err = cache.ListAll(s.listers.Kong.Plugin, + labels.NewSelector().Add(*req), + func(ob interface{}) { + if p, ok := ob.(*pluginv1.KongPlugin); ok { + plugins = append(plugins, p) + } + }) + if err != nil { + return nil, err + } + return plugins, nil +}