diff --git a/controllers/argocd/route.go b/controllers/argocd/route.go index d4c75da1d..5af71cd9c 100644 --- a/controllers/argocd/route.go +++ b/controllers/argocd/route.go @@ -393,6 +393,11 @@ func shortenHostname(hostname string) (string, error) { // Check and truncate the FIRST label if longer than 63 characters if len(labels[0]) > 63 { labels[0] = labels[0][:63] + + // Check if the FIRST label is < 20 after truncating and return an error if true + if len(labels[0]) < 20 { + return "", fmt.Errorf("first label length is less than 20 characters") + } } // Check other labels and return an error if any is longer than 63 characters diff --git a/controllers/argocd/route_test.go b/controllers/argocd/route_test.go index 412c8ed7c..4e365beb0 100644 --- a/controllers/argocd/route_test.go +++ b/controllers/argocd/route_test.go @@ -240,6 +240,7 @@ func TestReconcileRouteForShorteningHostname(t *testing.T) { sch := makeTestReconcilerScheme(argoproj.AddToScheme, configv1.Install, routev1.Install) cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs) r := makeTestReconciler(cl, sch) + assert.NoError(t, createNamespace(r, argoCD.Namespace, "")) req := reconcile.Request{