Skip to content

Commit

Permalink
fix:webhook route fail in argocd due to long route name
Browse files Browse the repository at this point in the history
Signed-off-by: Rizwana777 <rizwananaaz177@gmail.com>
  • Loading branch information
Rizwana777 committed Jan 2, 2024
1 parent d424ebd commit 8fb6644
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions controllers/argocd/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ func (r *ReconcileArgoCD) reconcileServerRoute(cr *argoproj.ArgoCD) error {
route.Spec.Host = cr.Spec.Server.Host // TODO: What additional role needed for this?
}

if len(route.Spec.Host) > 63 {
route.Spec.Host = route.Spec.Host[:63]
}

if cr.Spec.Server.Insecure {
// Disable TLS and rely on the cluster certificate.
route.Spec.Port = &routev1.RoutePort{
Expand Down Expand Up @@ -325,6 +329,10 @@ func (r *ReconcileArgoCD) reconcileApplicationSetControllerWebhookRoute(cr *argo
route.Spec.Host = cr.Spec.ApplicationSet.WebhookServer.Host
}

if len(route.Spec.Host) > 63 {
route.Spec.Host = route.Spec.Host[:63]
}

if cr.Spec.Server.Insecure {
// Disable TLS and rely on the cluster certificate.
route.Spec.Port = &routev1.RoutePort{
Expand Down
59 changes: 59 additions & 0 deletions controllers/argocd/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8fb6644

Please sign in to comment.