Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor configmap.go for extensability #6873

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}
}

// 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{

Check warning on line 54 in internal/k8s/configmap.go

View check run for this annotation

Codecov / codecov/patch

internal/k8s/configmap.go#L53-L54

Added lines #L53 - L54 were not covered by tests
ListerWatcher: cache.NewListWatchFromClient(
lbc.client.CoreV1().RESTClient(),
"configmaps",
Expand All @@ -62,6 +61,12 @@
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)

Check warning on line 69 in internal/k8s/configmap.go

View check run for this annotation

Codecov / codecov/patch

internal/k8s/configmap.go#L67-L69

Added lines #L67 - L69 were not covered by tests
lbc.configMapLister.Store, lbc.configMapController = cache.NewInformerWithOptions(options)
lbc.cacheSyncs = append(lbc.cacheSyncs, lbc.configMapController.HasSynced)
}
Expand All @@ -75,14 +80,17 @@
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

Check warning on line 92 in internal/k8s/configmap.go

View check run for this annotation

Codecov / codecov/patch

internal/k8s/configmap.go#L83-L92

Added lines #L83 - L92 were not covered by tests
}
} 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
Loading