Skip to content

Commit

Permalink
refactor secret name for clarity (#6823)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexFenlon authored Nov 19, 2024
1 parent 1984678 commit 3ca3d6e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func processDefaultServerSecret(ctx context.Context, kubeClient *kubernetes.Clie
}

bytes := configs.GenerateCertAndKeyFileContent(secret)
nginxManager.CreateSecret(configs.DefaultServerSecretName, bytes, nginx.TLSSecretFileMode)
nginxManager.CreateSecret(configs.DefaultServerSecretFileName, bytes, nginx.TLSSecretFileMode)
} else {
_, err := os.Stat(configs.DefaultServerSecretPath)
if err != nil {
Expand All @@ -596,7 +596,7 @@ func processWildcardSecret(ctx context.Context, kubeClient *kubernetes.Clientset
}

bytes := configs.GenerateCertAndKeyFileContent(secret)
nginxManager.CreateSecret(configs.WildcardSecretName, bytes, nginx.TLSSecretFileMode)
nginxManager.CreateSecret(configs.WildcardSecretFileName, bytes, nginx.TLSSecretFileMode)
}
return *wildcardTLSSecret != ""
}
Expand Down
8 changes: 4 additions & 4 deletions internal/configs/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const DefaultServerSecretPath = "/etc/nginx/secrets/default" //nolint:gosec // G
// DefaultSecretPath is the full default path to where secrets are stored and accessed.
const DefaultSecretPath = "/etc/nginx/secrets" // #nosec G101

// DefaultServerSecretName is the filename of the Secret with a TLS cert and a key for the default server.
const DefaultServerSecretName = "default"
// DefaultServerSecretFileName is the filename of the Secret with a TLS cert and a key for the default server.
const DefaultServerSecretFileName = "default"

// WildcardSecretName is the filename of the Secret with a TLS cert and a key for the ingress resources with TLS termination enabled but not secret defined.
const WildcardSecretName = "wildcard"
// WildcardSecretFileName is the filename of the Secret with a TLS cert and a key for the ingress resources with TLS termination enabled but not secret defined.
const WildcardSecretFileName = "wildcard"

// JWTKeyKey is the key of the data field of a Secret where the JWK must be stored.
const JWTKeyKey = "jwk"
Expand Down
10 changes: 5 additions & 5 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1656,15 +1656,15 @@ func (lbc *LoadBalancerController) reportCustomResourceStatusEnabled() bool {
func (lbc *LoadBalancerController) syncSecret(task task) {
key := task.Key
var obj interface{}
var secrExists bool
var secretWatched bool
var err error

namespace, name, err := ParseNamespaceName(key)
if err != nil {
nl.Warnf(lbc.Logger, "Secret key %v is invalid: %v", key, err)
return
}
obj, secrExists, err = lbc.getNamespacedInformer(namespace).secretLister.GetByKey(key)
obj, secretWatched, err = lbc.getNamespacedInformer(namespace).secretLister.GetByKey(key)
if err != nil {
lbc.syncQueue.Requeue(task, err)
return
Expand All @@ -1683,7 +1683,7 @@ func (lbc *LoadBalancerController) syncSecret(task task) {

nl.Debugf(lbc.Logger, "Found %v Resources with Secret %v", len(resources), key)

if !secrExists {
if !secretWatched {
lbc.secretStore.DeleteSecret(key)

nl.Debugf(lbc.Logger, "Deleting Secret: %v", key)
Expand Down Expand Up @@ -1780,9 +1780,9 @@ func (lbc *LoadBalancerController) handleSpecialSecretUpdate(secret *api_v1.Secr
secretNsName := secret.Namespace + "/" + secret.Name
switch secretNsName {
case lbc.specialSecrets.defaultServerSecret:
lbc.validationTLSSpecialSecret(secret, configs.DefaultServerSecretName, &specialTLSSecretsToUpdate)
lbc.validationTLSSpecialSecret(secret, configs.DefaultServerSecretFileName, &specialTLSSecretsToUpdate)
case lbc.specialSecrets.wildcardTLSSecret:
lbc.validationTLSSpecialSecret(secret, configs.WildcardSecretName, &specialTLSSecretsToUpdate)
lbc.validationTLSSpecialSecret(secret, configs.WildcardSecretFileName, &specialTLSSecretsToUpdate)
default:
nl.Warnf(lbc.Logger, "special secret not found")
return
Expand Down

0 comments on commit 3ca3d6e

Please sign in to comment.