diff --git a/controllers/argocd/route.go b/controllers/argocd/route.go index bbf07d47c..9d73e4870 100644 --- a/controllers/argocd/route.go +++ b/controllers/argocd/route.go @@ -302,6 +302,10 @@ func (r *ReconcileArgoCD) reconcileApplicationSetControllerWebhookRoute(cr *argo } } + if len(route.Spec.Host) > 63 { + route.Spec.Host = route.Spec.Host[:63] + } + if cr.Spec.ApplicationSet == nil || !cr.Spec.ApplicationSet.WebhookServer.Route.Enabled { return nil // Route not enabled, move along... } diff --git a/controllers/argocd/route_test.go b/controllers/argocd/route_test.go index 626520e55..8bad48708 100644 --- a/controllers/argocd/route_test.go +++ b/controllers/argocd/route_test.go @@ -213,6 +213,65 @@ func TestReconcileRouteUnsetsInsecure(t *testing.T) { } } +func TestReconcileRoute(t *testing.T) { + routeAPIFound = true + ctx := context.Background() + logf.SetLogger(ZapLogger(true)) + argoCD := makeArgoCD(func(a *argoproj.ArgoCD) { + a.Spec.Server.Route.Enabled = true + a.Spec.ApplicationSet = &argoproj.ArgoCDApplicationSet{ + WebhookServer: argoproj.WebhookServerSpec{ + Route: argoproj.ArgoCDRouteSpec{ + Enabled: true, + }, + }, + } + }) + + resObjs := []client.Object{argoCD} + subresObjs := []client.Object{argoCD} + runtimeObjs := []runtime.Object{} + sch := makeTestReconcilerScheme(argoproj.AddToScheme, configv1.Install, routev1.Install) + cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs) + r := makeTestReconciler(cl, sch) + name := "argocd-applicationset-controller-webhook" + route := &routev1.Route{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: testNamespace, + }, + Spec: routev1.RouteSpec{ + Host: name + "-openshift-gitops.apps-crc.testing", + }, + } + err := r.Client.Create(context.TODO(), route) + assert.NoError(t, err) + assert.NoError(t, createNamespace(r, argoCD.Namespace, "")) + + req := reconcile.Request{ + NamespacedName: types.NamespacedName{ + Name: testArgoCDName, + Namespace: testNamespace, + }, + } + + _, err = r.Reconcile(context.TODO(), req) + assert.NoError(t, err) + + loaded := &routev1.Route{} + err = r.Client.Get(ctx, types.NamespacedName{Name: name, Namespace: testNamespace}, loaded) + fatalIfError(t, err, "failed to load route %q: %s", name, err) + + wantRoute := &routev1.RouteSpec{ + Host: "argocd-applicationset-controller-webhook-openshift-gitops.apps-", + } + + if diff := cmp.Diff(wantRoute.Host, loaded.Spec.Host); diff != "" { + t.Fatalf("failed to reconcile route:\n%s", diff) + } + +} + func makeReconciler(t *testing.T, acd *argoproj.ArgoCD, objs ...runtime.Object) *ReconcileArgoCD { t.Helper() s := scheme.Scheme