Skip to content

Commit 9b8d111

Browse files
authored
Fixed bug where reconcile loop could occur when user provides an invalid (non-RFC1123) secret name (#186)
1 parent c3a2a05 commit 9b8d111

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/operator/controllers/poduserpassword/db_credentials_pod_reconciler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
"k8s.io/apimachinery/pkg/runtime"
2222
"k8s.io/apimachinery/pkg/types"
23+
"k8s.io/apimachinery/pkg/util/validation"
2324
"k8s.io/client-go/tools/record"
2425
ctrl "sigs.k8s.io/controller-runtime"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -125,6 +126,13 @@ func (e *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
125126

126127
secretName := pod.Annotations[metadata.UserAndPasswordSecretNameAnnotation]
127128
logrus.Debug("Ensuring user-password credentials secrets for pod")
129+
if secretNameErrors := validation.IsDNS1123Subdomain(secretName); len(secretNameErrors) > 0 {
130+
secretNameErrorsString := strings.Join(secretNameErrors, ", ")
131+
logrus.WithFields(logrus.Fields{"pod": pod.Name, "namespace": pod.Namespace, "secretName": secretName, "errors": secretNameErrors}).
132+
Warningf("Invalid secret name")
133+
e.recorder.Eventf(&pod, v1.EventTypeWarning, ReasonEnsuringPodUserAndPasswordFailed, "Invalid secret name %s: %s", secretName, secretNameErrorsString)
134+
return ctrl.Result{}, nil
135+
}
128136
result, created, password, err := e.ensurePodUserAndPasswordSecret(ctx, &pod, secretName, username)
129137
if err != nil {
130138
e.recorder.Eventf(&pod, v1.EventTypeWarning, ReasonEnsuringPodUserAndPasswordFailed, "Failed to ensure user-password credentials secret: %s", err.Error())

0 commit comments

Comments
 (0)