diff --git a/internal/k8s/controller.go b/internal/k8s/controller.go index 864a46e6e..830abce4e 100644 --- a/internal/k8s/controller.go +++ b/internal/k8s/controller.go @@ -1747,7 +1747,7 @@ func (lbc *LoadBalancerController) handleRegularSecretDeletion(resources []Resou } func (lbc *LoadBalancerController) handleSecretUpdate(secret *api_v1.Secret, resources []Resource) { - secretNsName := secret.Namespace + "/" + secret.Name + secretNsName := generateSecretNSName(secret) var warnings configs.Warnings var addOrUpdateErr error @@ -1764,7 +1764,7 @@ func (lbc *LoadBalancerController) handleSecretUpdate(secret *api_v1.Secret, res } func (lbc *LoadBalancerController) validationTLSSpecialSecret(secret *api_v1.Secret, secretName string, secretList *[]string) { - secretNsName := secret.Namespace + "/" + secret.Name + secretNsName := generateSecretNSName(secret) err := secrets.ValidateTLSSecret(secret) if err != nil { @@ -1777,7 +1777,7 @@ func (lbc *LoadBalancerController) validationTLSSpecialSecret(secret *api_v1.Sec func (lbc *LoadBalancerController) handleSpecialSecretUpdate(secret *api_v1.Secret) { var specialTLSSecretsToUpdate []string - secretNsName := secret.Namespace + "/" + secret.Name + secretNsName := generateSecretNSName(secret) if secretNsName == lbc.specialSecrets.defaultServerSecret { lbc.validationTLSSpecialSecret(secret, configs.DefaultServerSecretFileName, &specialTLSSecretsToUpdate) @@ -1795,6 +1795,10 @@ func (lbc *LoadBalancerController) handleSpecialSecretUpdate(secret *api_v1.Secr lbc.recorder.Eventf(secret, api_v1.EventTypeNormal, "Updated", "the special Secret %v was updated", secretNsName) } +func generateSecretNSName(secret *api_v1.Secret) string { + return secret.Namespace + "/" + secret.Name +} + func getStatusFromEventTitle(eventTitle string) string { switch eventTitle { case "AddedOrUpdatedWithError", "Rejected", "NoVirtualServersFound", "Missing Secret", "UpdatedWithError": diff --git a/internal/k8s/controller_test.go b/internal/k8s/controller_test.go index c7fb4bb7a..777a195b4 100644 --- a/internal/k8s/controller_test.go +++ b/internal/k8s/controller_test.go @@ -3505,3 +3505,32 @@ func TestNewTelemetryCollector(t *testing.T) { } } } + +func TestGenerateSecretNSName(t *testing.T) { + t.Parallel() + testCases := []struct { + name string + secret *api_v1.Secret + expected string + }{ + { + name: "Valid secret", + secret: &api_v1.Secret{ + ObjectMeta: meta_v1.ObjectMeta{ + Namespace: "testns", + Name: "test-secret", + }, + }, + expected: "testns/test-secret", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + result := generateSecretNSName(tc.secret) + if result != tc.expected { + t.Fatalf("Expected %v, but got %v", tc.expected, result) + } + }) + } +}