Skip to content

Commit 726fe44

Browse files
Jim Ryanpdabelf5
andauthored
refactor lbc to add metadata struct (#6885)
refactor lbc namespace Co-authored-by: Paul Abel <[email protected]>
1 parent 579a790 commit 726fe44

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

cmd/nginx-ingress/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ func main() {
260260
ExternalServiceName: *externalService,
261261
IngressLink: *ingressLink,
262262
ControllerNamespace: controllerNamespace,
263+
Pod: pod,
263264
ReportIngressStatus: *reportIngressStatus,
264265
IsLeaderElectionEnabled: *leaderElectionEnabled,
265266
LeaderElectionLockName: *leaderElectionLockName,

internal/k8s/controller.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const (
7979
typeKeyword = "type"
8080
helmReleaseType = "helm.sh/release.v1"
8181
splitClientAmountWhenWeightChangesDynamicReload = 101
82+
secretDeletedReason = "SecretDeleted"
8283
)
8384

8485
var (
@@ -106,6 +107,11 @@ type specialSecrets struct {
106107
wildcardTLSSecret string
107108
}
108109

110+
type controllerMetadata struct {
111+
namespace string
112+
pod *api_v1.Pod
113+
}
114+
109115
// LoadBalancerController watches Kubernetes API and
110116
// reconfigures NGINX via NginxController when needed
111117
type LoadBalancerController struct {
@@ -144,7 +150,7 @@ type LoadBalancerController struct {
144150
resync time.Duration
145151
namespaceList []string
146152
secretNamespaceList []string
147-
controllerNamespace string
153+
metadata controllerMetadata
148154
areCustomResourcesEnabled bool
149155
enableOIDC bool
150156
metricsCollector collectors.ControllerCollector
@@ -197,6 +203,7 @@ type NewLoadBalancerControllerInput struct {
197203
ExternalServiceName string
198204
IngressLink string
199205
ControllerNamespace string
206+
Pod *api_v1.Pod
200207
ReportIngressStatus bool
201208
IsLeaderElectionEnabled bool
202209
LeaderElectionLockName string
@@ -253,7 +260,7 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc
253260
resync: input.ResyncPeriod,
254261
namespaceList: input.Namespace,
255262
secretNamespaceList: input.SecretNamespace,
256-
controllerNamespace: input.ControllerNamespace,
263+
metadata: controllerMetadata{namespace: input.ControllerNamespace, pod: input.Pod},
257264
areCustomResourcesEnabled: input.AreCustomResourcesEnabled,
258265
enableOIDC: input.EnableOIDC,
259266
metricsCollector: input.MetricsCollector,
@@ -1694,7 +1701,8 @@ func (lbc *LoadBalancerController) syncSecret(task task) {
16941701
lbc.handleRegularSecretDeletion(resources)
16951702
}
16961703
if lbc.isSpecialSecret(key) {
1697-
nl.Warnf(lbc.Logger, "A special TLS Secret %v was removed. Retaining the Secret.", key)
1704+
lbc.recorder.Eventf(lbc.metadata.pod, conf_v1.StateWarning, secretDeletedReason, "A special secret [%s] was deleted. Retaining the secret on this pod but this will affect new pods.", key)
1705+
nl.Warnf(lbc.Logger, "A special Secret %v was removed. Retaining the Secret.", key)
16981706
}
16991707
return
17001708
}

internal/k8s/ingress_link.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (lbc *LoadBalancerController) addIngressLinkHandler(handlers cache.Resource
5656
options.FieldSelector = fields.Set{"metadata.name": name}.String()
5757
}
5858

59-
informer := dynamicinformer.NewFilteredDynamicInformer(lbc.dynClient, ingressLinkGVR, lbc.controllerNamespace, lbc.resync,
59+
informer := dynamicinformer.NewFilteredDynamicInformer(lbc.dynClient, ingressLinkGVR, lbc.metadata.namespace, lbc.resync,
6060
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, optionsModifier)
6161

6262
informer.Informer().AddEventHandlerWithResyncPeriod(handlers, lbc.resync) //nolint:errcheck,gosec

internal/k8s/leader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func createLeaderHandler(lbc *LoadBalancerController) leaderelection.LeaderCallb
109109
// addLeaderHandler adds the handler for leader election to the controller
110110
func (lbc *LoadBalancerController) addLeaderHandler(leaderHandler leaderelection.LeaderCallbacks) {
111111
var err error
112-
lbc.leaderElector, err = newLeaderElector(lbc.client, leaderHandler, lbc.controllerNamespace, lbc.leaderElectionLockName)
112+
lbc.leaderElector, err = newLeaderElector(lbc.client, leaderHandler, lbc.metadata.namespace, lbc.leaderElectionLockName)
113113
if err != nil {
114114
nl.Debugf(lbc.Logger, "Error starting LeaderElection: %v", err)
115115
}

0 commit comments

Comments
 (0)