Skip to content

Commit 6536a0b

Browse files
ivanmatmatioktalz
authored andcommitted
MINOR: prevent running informers from GW API when unnecessary
1 parent 07a53b6 commit 6536a0b

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func main() {
119119
WithRestClientSet(k.GetRestClientset()).
120120
WithArgs(osArgs).Build()
121121

122-
go k.MonitorChanges(eventChan, stop)
122+
go k.MonitorChanges(eventChan, stop, osArgs)
123123
go c.Start()
124124

125125
// Catch QUIT signals

pkg/k8s/main.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var ErrIgnored = errors.New("ignored resource")
5151
type K8s interface {
5252
GetRestClientset() client.Client
5353
GetClientset() *k8sclientset.Clientset
54-
MonitorChanges(eventChan chan SyncDataEvent, stop chan struct{})
54+
MonitorChanges(eventChan chan SyncDataEvent, stop chan struct{}, osArgs utils.OSArgs)
5555
UpdatePublishService(ingresses []*ingress.Ingress, publishServiceAddresses []string)
5656
}
5757

@@ -77,7 +77,6 @@ type k8s struct {
7777
syncPeriod time.Duration
7878
cacheResyncPeriod time.Duration
7979
disableSvcExternalName bool // CVE-2021-25740
80-
gatewayCRDInstalled bool
8180
}
8281

8382
func New(osArgs utils.OSArgs, whitelist map[string]struct{}, publishSvc *utils.NamespaceValue) K8s { //nolint:ireturn
@@ -146,14 +145,16 @@ func (k k8s) UpdatePublishService(ingresses []*ingress.Ingress, publishServiceAd
146145
}
147146
}
148147

149-
func (k k8s) MonitorChanges(eventChan chan SyncDataEvent, stop chan struct{}) {
148+
func (k k8s) MonitorChanges(eventChan chan SyncDataEvent, stop chan struct{}, osArgs utils.OSArgs) {
150149
informersSynced := &[]cache.InformerSynced{}
151-
k.gatewayCRDInstalled = k.isGatewayAPIInstalled()
150+
needGatewayAPIInformers := k.isGatewayAPIInstalled() && osArgs.GatewayControllerName != ""
152151
k.runPodInformer(eventChan, stop, informersSynced)
153152
for _, namespace := range k.whiteListedNS {
154153
k.runInformers(eventChan, stop, namespace, informersSynced)
155154
k.runCRInformers(eventChan, stop, namespace, informersSynced)
156-
k.runInformersGwAPI(eventChan, stop, namespace, informersSynced)
155+
if needGatewayAPIInformers {
156+
k.runInformersGwAPI(eventChan, stop, namespace, informersSynced)
157+
}
157158
}
158159

159160
if !cache.WaitForCacheSync(stop, *informersSynced...) {
@@ -234,9 +235,6 @@ func (k k8s) runInformers(eventChan chan SyncDataEvent, stop chan struct{}, name
234235
}
235236

236237
func (k k8s) runInformersGwAPI(eventChan chan SyncDataEvent, stop chan struct{}, namespace string, informersSynced *[]cache.InformerSynced) {
237-
if !k.gatewayCRDInstalled {
238-
return
239-
}
240238
factory := gatewaynetworking.NewSharedInformerFactoryWithOptions(k.gatewayClient, k.cacheResyncPeriod, gatewaynetworking.WithNamespace(namespace))
241239
gwclassInf := k.getGatewayClassesInformer(eventChan, factory)
242240
if gwclassInf != nil {

0 commit comments

Comments
 (0)