Skip to content

Commit

Permalink
MINOR: removal of unused ingresschan
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmatmati authored and oktalz committed Oct 31, 2022
1 parent dd6c493 commit 1d80d8f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 25 deletions.
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions pkg/controller/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions pkg/k8s/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{}) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}
}
Expand All @@ -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(),
Expand Down Expand Up @@ -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}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1d80d8f

Please sign in to comment.