@@ -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