diff --git a/cmd/nginx-ingress/main.go b/cmd/nginx-ingress/main.go index 13917ec05b..7476d99388 100644 --- a/cmd/nginx-ingress/main.go +++ b/cmd/nginx-ingress/main.go @@ -260,6 +260,7 @@ func main() { ExternalServiceName: *externalService, IngressLink: *ingressLink, ControllerNamespace: controllerNamespace, + Pod: pod, ReportIngressStatus: *reportIngressStatus, IsLeaderElectionEnabled: *leaderElectionEnabled, LeaderElectionLockName: *leaderElectionLockName, diff --git a/internal/k8s/controller.go b/internal/k8s/controller.go index 1cfe976024..606c1431ad 100644 --- a/internal/k8s/controller.go +++ b/internal/k8s/controller.go @@ -79,6 +79,7 @@ const ( typeKeyword = "type" helmReleaseType = "helm.sh/release.v1" splitClientAmountWhenWeightChangesDynamicReload = 101 + secretDeletedReason = "SecretDeleted" ) var ( @@ -106,6 +107,11 @@ type specialSecrets struct { wildcardTLSSecret string } +type controllerMetadata struct { + namespace string + pod *api_v1.Pod +} + // LoadBalancerController watches Kubernetes API and // reconfigures NGINX via NginxController when needed type LoadBalancerController struct { @@ -144,7 +150,7 @@ type LoadBalancerController struct { resync time.Duration namespaceList []string secretNamespaceList []string - controllerNamespace string + metadata controllerMetadata areCustomResourcesEnabled bool enableOIDC bool metricsCollector collectors.ControllerCollector @@ -197,6 +203,7 @@ type NewLoadBalancerControllerInput struct { ExternalServiceName string IngressLink string ControllerNamespace string + Pod *api_v1.Pod ReportIngressStatus bool IsLeaderElectionEnabled bool LeaderElectionLockName string @@ -253,7 +260,7 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc resync: input.ResyncPeriod, namespaceList: input.Namespace, secretNamespaceList: input.SecretNamespace, - controllerNamespace: input.ControllerNamespace, + metadata: controllerMetadata{namespace: input.ControllerNamespace, pod: input.Pod}, areCustomResourcesEnabled: input.AreCustomResourcesEnabled, enableOIDC: input.EnableOIDC, metricsCollector: input.MetricsCollector, @@ -1694,7 +1701,8 @@ func (lbc *LoadBalancerController) syncSecret(task task) { lbc.handleRegularSecretDeletion(resources) } if lbc.isSpecialSecret(key) { - nl.Warnf(lbc.Logger, "A special TLS Secret %v was removed. Retaining the Secret.", key) + 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) + nl.Warnf(lbc.Logger, "A special Secret %v was removed. Retaining the Secret.", key) } return } diff --git a/internal/k8s/ingress_link.go b/internal/k8s/ingress_link.go index fed8e84666..fbfe3df76b 100644 --- a/internal/k8s/ingress_link.go +++ b/internal/k8s/ingress_link.go @@ -56,7 +56,7 @@ func (lbc *LoadBalancerController) addIngressLinkHandler(handlers cache.Resource options.FieldSelector = fields.Set{"metadata.name": name}.String() } - informer := dynamicinformer.NewFilteredDynamicInformer(lbc.dynClient, ingressLinkGVR, lbc.controllerNamespace, lbc.resync, + informer := dynamicinformer.NewFilteredDynamicInformer(lbc.dynClient, ingressLinkGVR, lbc.metadata.namespace, lbc.resync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, optionsModifier) informer.Informer().AddEventHandlerWithResyncPeriod(handlers, lbc.resync) //nolint:errcheck,gosec diff --git a/internal/k8s/leader.go b/internal/k8s/leader.go index 47b9b7d30d..81f5faae8b 100644 --- a/internal/k8s/leader.go +++ b/internal/k8s/leader.go @@ -109,7 +109,7 @@ func createLeaderHandler(lbc *LoadBalancerController) leaderelection.LeaderCallb // addLeaderHandler adds the handler for leader election to the controller func (lbc *LoadBalancerController) addLeaderHandler(leaderHandler leaderelection.LeaderCallbacks) { var err error - lbc.leaderElector, err = newLeaderElector(lbc.client, leaderHandler, lbc.controllerNamespace, lbc.leaderElectionLockName) + lbc.leaderElector, err = newLeaderElector(lbc.client, leaderHandler, lbc.metadata.namespace, lbc.leaderElectionLockName) if err != nil { nl.Debugf(lbc.Logger, "Error starting LeaderElection: %v", err) }