Skip to content

Commit

Permalink
refactor configmap.go for extensability (#6873)
Browse files Browse the repository at this point in the history
  • Loading branch information
j1m-ryan authored Nov 27, 2024
1 parent 7e7535d commit 8b8fc52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 18 additions & 10 deletions internal/k8s/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ func createConfigMapHandlers(lbc *LoadBalancerController, name string) cache.Res
}
}

// addConfigMapHandler adds the handler for config maps to the controller
func (lbc *LoadBalancerController) addConfigMapHandler(handlers cache.ResourceEventHandlerFuncs, namespace string) {
options := cache.InformerOptions{
func (lbc *LoadBalancerController) getConfigMapHandlerOptions(handlers cache.ResourceEventHandlerFuncs, namespace string) cache.InformerOptions {
return cache.InformerOptions{
ListerWatcher: cache.NewListWatchFromClient(
lbc.client.CoreV1().RESTClient(),
"configmaps",
Expand All @@ -62,6 +61,12 @@ func (lbc *LoadBalancerController) addConfigMapHandler(handlers cache.ResourceEv
ResyncPeriod: lbc.resync,
Handler: handlers,
}
}

// addConfigMapHandler adds the handler for config maps to the controller
func (lbc *LoadBalancerController) addConfigMapHandler(handlers cache.ResourceEventHandlerFuncs, namespace string) {
options := lbc.getConfigMapHandlerOptions(handlers, namespace)

lbc.configMapLister.Store, lbc.configMapController = cache.NewInformerWithOptions(options)
lbc.cacheSyncs = append(lbc.cacheSyncs, lbc.configMapController.HasSynced)
}
Expand All @@ -75,14 +80,17 @@ func (lbc *LoadBalancerController) syncConfigMap(task task) {
lbc.syncQueue.Requeue(task, err)
return
}
if configExists {
lbc.configMap = obj.(*v1.ConfigMap)
externalStatusAddress, exists := lbc.configMap.Data["external-status-address"]
if exists {
lbc.statusUpdater.SaveStatusFromExternalStatus(externalStatusAddress)
switch key {
case lbc.nginxConfigMapName:
if configExists {
lbc.configMap = obj.(*v1.ConfigMap)
externalStatusAddress, exists := lbc.configMap.Data["external-status-address"]
if exists {
lbc.statusUpdater.SaveStatusFromExternalStatus(externalStatusAddress)
}
} else {
lbc.configMap = nil
}
} else {
lbc.configMap = nil
}

if !lbc.isNginxReady {
Expand Down
2 changes: 2 additions & 0 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type LoadBalancerController struct {
telemetryCollector *telemetry.Collector
telemetryChan chan struct{}
weightChangesDynamicReload bool
nginxConfigMapName string
}

var keyFunc = cache.DeletionHandlingMetaNamespaceKeyFunc
Expand Down Expand Up @@ -263,6 +264,7 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc
isLatencyMetricsEnabled: input.IsLatencyMetricsEnabled,
isIPV6Disabled: input.IsIPV6Disabled,
weightChangesDynamicReload: input.DynamicWeightChangesReload,
nginxConfigMapName: input.ConfigMaps,
}

lbc.syncQueue = newTaskQueue(lbc.Logger, lbc.sync)
Expand Down

0 comments on commit 8b8fc52

Please sign in to comment.