From 1d80d8f7d6eef0a878f9e5648e085d01b86263a5 Mon Sep 17 00:00:00 2001 From: Ivan Matmati Date: Fri, 21 Oct 2022 16:13:35 +0200 Subject: [PATCH] MINOR: removal of unused ingresschan --- main.go | 5 +---- pkg/controller/builder.go | 7 ------- pkg/controller/controller.go | 1 - pkg/k8s/informers.go | 13 +++++-------- pkg/k8s/main.go | 10 +++++----- 5 files changed, 11 insertions(+), 25 deletions(-) diff --git a/main.go b/main.go index d51c70c5..85f9f3d3 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,6 @@ import ( "github.com/haproxytech/kubernetes-ingress/pkg/annotations" "github.com/haproxytech/kubernetes-ingress/pkg/controller" - "github.com/haproxytech/kubernetes-ingress/pkg/ingress" "github.com/haproxytech/kubernetes-ingress/pkg/k8s" "github.com/haproxytech/kubernetes-ingress/pkg/store" "github.com/haproxytech/kubernetes-ingress/pkg/utils" @@ -92,7 +91,6 @@ func main() { chanSize = osArgs.ChannelSize } eventChan := make(chan k8s.SyncDataEvent, chanSize) - ingressChan := make(chan ingress.Sync, chanSize) stop := make(chan struct{}) publishService := getNamespaceValue(osArgs.PublishService) @@ -107,14 +105,13 @@ func main() { c := controller.NewBuilder(). WithHaproxyCfgFile(haproxyConf). WithEventChan(eventChan). - WithIngressChan(ingressChan). WithStore(s). WithPublishService(publishService). WithUpdatePublishServiceFunc(k.UpdatePublishService). WithClientSet(k.GetClientset()). WithArgs(osArgs).Build() - go k.MonitorChanges(eventChan, ingressChan, stop) + go k.MonitorChanges(eventChan, stop) go c.Start() // Catch QUIT signals diff --git a/pkg/controller/builder.go b/pkg/controller/builder.go index 84717a0a..a15280ea 100644 --- a/pkg/controller/builder.go +++ b/pkg/controller/builder.go @@ -35,7 +35,6 @@ type Builder struct { store store.K8s publishService *utils.NamespaceValue eventChan chan k8s.SyncDataEvent - ingressChan chan ingress.Sync updatePublishServiceFunc func(ingresses []*ingress.Ingress, publishServiceAddresses []string) clientSet *kubernetes.Clientset } @@ -87,11 +86,6 @@ func (builder *Builder) WithEventChan(eventChan chan k8s.SyncDataEvent) *Builder return builder } -func (builder *Builder) WithIngressChan(ingressChan chan ingress.Sync) *Builder { - builder.ingressChan = ingressChan - return builder -} - func (builder *Builder) WithStore(store store.K8s) *Builder { builder.store = store return builder @@ -156,7 +150,6 @@ func (builder *Builder) Build() *HAProxyController { podPrefix: prefix, store: builder.store, eventChan: builder.eventChan, - ingressChan: builder.ingressChan, publishService: builder.publishService, annotations: builder.annotations, chShutdown: chShutdown, diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 9708d05d..df3641b9 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -41,7 +41,6 @@ type HAProxyController struct { publishService *utils.NamespaceValue auxCfgModTime int64 eventChan chan k8s.SyncDataEvent - ingressChan chan ingress.Sync ready bool reload bool restart bool diff --git a/pkg/k8s/informers.go b/pkg/k8s/informers.go index 72583f12..0e8761f1 100644 --- a/pkg/k8s/informers.go +++ b/pkg/k8s/informers.go @@ -15,7 +15,6 @@ import ( "github.com/haproxytech/client-native/v3/models" - "github.com/haproxytech/kubernetes-ingress/pkg/ingress" "github.com/haproxytech/kubernetes-ingress/pkg/store" "github.com/haproxytech/kubernetes-ingress/pkg/utils" ) @@ -109,7 +108,7 @@ func (k k8s) getNamespaceInfomer(eventChan chan SyncDataEvent, factory informers return informer } -func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, ingressChan chan ingress.Sync, factory informers.SharedInformerFactory, publishSvc *utils.NamespaceValue) cache.SharedIndexInformer { +func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, factory informers.SharedInformerFactory) cache.SharedIndexInformer { //nolint:ireturn informer := factory.Core().V1().Services().Informer() informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { @@ -146,7 +145,7 @@ func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, ingressChan chan i } logger.Tracef("%s %s: %s", SERVICE, item.Status, item.Name) eventChan <- SyncDataEvent{SyncType: SERVICE, Namespace: item.Namespace, Data: item} - if publishSvc != nil && publishSvc.Namespace == item.Namespace && publishSvc.Name == item.Name { + if k.publishSvc != nil && k.publishSvc.Namespace == item.Namespace && k.publishSvc.Name == item.Name { // item copy because of ADDED handler in events.go which must modify the STATUS based solely on addresses itemCopy := *item itemCopy.Addresses = getServiceAddresses(data) @@ -174,7 +173,7 @@ func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, ingressChan chan i } logger.Tracef("%s %s: %s", SERVICE, item.Status, item.Name) eventChan <- SyncDataEvent{SyncType: SERVICE, Namespace: item.Namespace, Data: item} - if publishSvc != nil && publishSvc.Namespace == item.Namespace && publishSvc.Name == item.Name { + if k.publishSvc != nil && k.publishSvc.Namespace == item.Namespace && k.publishSvc.Name == item.Name { item.Addresses = getServiceAddresses(data) eventChan <- SyncDataEvent{SyncType: PUBLISH_SERVICE, Namespace: data.Namespace, Data: item} } @@ -198,9 +197,7 @@ func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, ingressChan chan i logger.Tracef("forwarding to ExternalName Services for %v is disabled", data2) return } - if k.publishSvc != nil && k.publishSvc.Namespace == data2.Namespace && k.publishSvc.Name == data2.Name { - ingressChan <- ingress.Sync{Service: data2} - } + status := store.MODIFIED item1 := &store.Service{ Namespace: data1.GetNamespace(), @@ -243,7 +240,7 @@ func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, ingressChan chan i logger.Tracef("%s %s: %s", SERVICE, item2.Status, item2.Name) eventChan <- SyncDataEvent{SyncType: SERVICE, Namespace: item2.Namespace, Data: item2} - if publishSvc != nil && publishSvc.Namespace == item2.Namespace && publishSvc.Name == item2.Name { + if k.publishSvc != nil && k.publishSvc.Namespace == item2.Namespace && k.publishSvc.Name == item2.Name { item2.Addresses = getServiceAddresses(data2) eventChan <- SyncDataEvent{SyncType: PUBLISH_SERVICE, Namespace: item2.Namespace, Data: item2} } diff --git a/pkg/k8s/main.go b/pkg/k8s/main.go index 9f83f9a8..2d7c0282 100644 --- a/pkg/k8s/main.go +++ b/pkg/k8s/main.go @@ -46,7 +46,7 @@ var ErrIgnored = errors.New("ignored resource") type K8s interface { GetClientset() *k8sclientset.Clientset - MonitorChanges(eventChan chan SyncDataEvent, ingressChan chan ingress.Sync, stop chan struct{}) + MonitorChanges(eventChan chan SyncDataEvent, stop chan struct{}) UpdatePublishService(ingresses []*ingress.Ingress, publishServiceAddresses []string) } @@ -116,12 +116,12 @@ func (k k8s) UpdatePublishService(ingresses []*ingress.Ingress, publishServiceAd } } -func (k k8s) MonitorChanges(eventChan chan SyncDataEvent, ingressChan chan ingress.Sync, stop chan struct{}) { +func (k k8s) MonitorChanges(eventChan chan SyncDataEvent, stop chan struct{}) { informersSynced := &[]cache.InformerSynced{} k.runPodInformer(eventChan, stop, informersSynced) for _, namespace := range k.whiteListedNS { - k.runInformers(eventChan, ingressChan, stop, namespace, informersSynced) + k.runInformers(eventChan, stop, namespace, informersSynced) k.runCRInformers(eventChan, stop, namespace, informersSynced) } @@ -162,12 +162,12 @@ func (k k8s) runCRInformers(eventChan chan SyncDataEvent, stop chan struct{}, na } } -func (k k8s) runInformers(eventChan chan SyncDataEvent, ingressChan chan ingress.Sync, stop chan struct{}, namespace string, informersSynced *[]cache.InformerSynced) { +func (k k8s) runInformers(eventChan chan SyncDataEvent, stop chan struct{}, namespace string, informersSynced *[]cache.InformerSynced) { factory := k8sinformers.NewSharedInformerFactoryWithOptions(k.builtInClient, k.cacheResyncPeriod, k8sinformers.WithNamespace(namespace)) // Core.V1 Resources nsi := k.getNamespaceInfomer(eventChan, factory) go nsi.Run(stop) - svci := k.getServiceInformer(eventChan, ingressChan, factory, k.publishSvc) + svci := k.getServiceInformer(eventChan, factory) go svci.Run(stop) seci := k.getSecretInformer(eventChan, factory) go seci.Run(stop)