Skip to content

Commit

Permalink
watch custom resources to provide better user experience (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
suchen-sci authored Nov 22, 2023
1 parent 54350cb commit 2cbbb25
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/object/gatewaycontroller/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic/dynamicinformer"
corev1 "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/informers/internalinterfaces"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -250,9 +251,9 @@ func (c *k8sClient) watch(namespaces []string) (chan struct{}, error) {
}

/*
labelSelectorOptions := func(options *metav1.ListOptions) {
options.LabelSelector = c.labelSelector
}
labelSelectorOptions := func(options *metav1.ListOptions) {
options.LabelSelector = c.labelSelector
}
*/

c.kFactory = kinformers.NewSharedInformerFactory(c.kcs, resyncPeriod)
Expand All @@ -267,6 +268,7 @@ func (c *k8sClient) watch(namespaces []string) (chan struct{}, error) {
return nil, err
}

dFactories := []dynamicinformer.DynamicSharedInformerFactory{}
for _, ns := range namespaces {
gwinformerapis.New(c.gwFactory, ns, nil).Gateways().Informer().AddEventHandler(c)
gwinformerapis.New(c.gwFactory, ns, nil).HTTPRoutes().Informer().AddEventHandler(c)
Expand All @@ -275,10 +277,17 @@ func (c *k8sClient) watch(namespaces []string) (chan struct{}, error) {
corev1.New(c.kFactory, ns, nil).Services().Informer().AddEventHandler(c)
corev1.New(c.kFactory, ns, nil).Endpoints().Informer().AddEventHandler(c)
corev1.New(c.kFactory, ns, internalinterfaces.TweakListOptionsFunc(notHelm)).Secrets().Informer().AddEventHandler(c)

dFactory := dynamicinformer.NewFilteredDynamicSharedInformerFactory(c.dc, resyncPeriod, ns, nil)
dFactory.ForResource(FilterSpecGVR).Informer().AddEventHandler(c)
dFactories = append(dFactories, dFactory)
}

c.kFactory.Start(stopCh)
c.gwFactory.Start(stopCh)
for _, f := range dFactories {
f.Start(stopCh)
}

for typ, ok := range c.kFactory.WaitForCacheSync(stopCh) {
if !ok {
Expand Down

0 comments on commit 2cbbb25

Please sign in to comment.