@@ -253,7 +253,7 @@ func TestReconcileRouteApplicationSetHost(t *testing.T) {
253253 assert .NoError (t , err )
254254
255255 loaded := & routev1.Route {}
256- err = r .Client .Get (ctx , types.NamespacedName {Name : fmt .Sprintf ("%s-%s-%s " , testArgoCDName , common .ApplicationSetServiceNameSuffix , "webhook" ), Namespace : testNamespace }, loaded )
256+ err = r .Client .Get (ctx , types.NamespacedName {Name : fmt .Sprintf ("%s-%s" , testArgoCDName , common .ApplicationSetControllerWebhookSuffix ), Namespace : testNamespace }, loaded )
257257 fatalIfError (t , err , "failed to load route %q: %s" , testArgoCDName + "-server" , err )
258258
259259 wantTLSConfig := & routev1.TLSConfig {
@@ -309,7 +309,7 @@ func TestReconcileRouteApplicationSetTlsTermination(t *testing.T) {
309309 assert .NoError (t , err )
310310
311311 loaded := & routev1.Route {}
312- err = r .Client .Get (ctx , types.NamespacedName {Name : fmt .Sprintf ("%s-%s-%s " , testArgoCDName , common .ApplicationSetServiceNameSuffix , "webhook" ), Namespace : testNamespace }, loaded )
312+ err = r .Client .Get (ctx , types.NamespacedName {Name : fmt .Sprintf ("%s-%s" , testArgoCDName , common .ApplicationSetControllerWebhookSuffix ), Namespace : testNamespace }, loaded )
313313 fatalIfError (t , err , "failed to load route %q: %s" , testArgoCDName + "-server" , err )
314314
315315 wantTLSConfig := & routev1.TLSConfig {
@@ -351,7 +351,17 @@ func TestReconcileRouteApplicationSetTls(t *testing.T) {
351351 }
352352 })
353353
354- resObjs := []client.Object {argoCD }
354+ // Create the Ingress configuration
355+ ingressConfig := & configv1.Ingress {
356+ ObjectMeta : metav1.ObjectMeta {
357+ Name : "cluster" ,
358+ },
359+ Spec : configv1.IngressSpec {
360+ Domain : "apps.example.com" ,
361+ },
362+ }
363+
364+ resObjs := []client.Object {argoCD , ingressConfig }
355365 subresObjs := []client.Object {argoCD }
356366 runtimeObjs := []runtime.Object {}
357367 sch := makeTestReconcilerScheme (argoproj .AddToScheme , configv1 .Install , routev1 .Install )
@@ -370,10 +380,17 @@ func TestReconcileRouteApplicationSetTls(t *testing.T) {
370380 _ , err := r .Reconcile (context .TODO (), req )
371381 assert .NoError (t , err )
372382
383+ // The route name should be based on the ArgoCD instance name
384+ expectedRouteName := fmt .Sprintf ("%s-%s" , testArgoCDName , common .ApplicationSetControllerWebhookSuffix )
385+ if len (expectedRouteName ) > 63 {
386+ expectedRouteName = expectedRouteName [:63 ]
387+ }
388+
373389 loaded := & routev1.Route {}
374- err = r .Client .Get (ctx , types.NamespacedName {Name : fmt . Sprintf ( "%s-%s-%s" , testArgoCDName , common . ApplicationSetServiceNameSuffix , "webhook" ) , Namespace : testNamespace }, loaded )
375- fatalIfError (t , err , "failed to load route %q: %s" , testArgoCDName + "-server" , err )
390+ err = r .Client .Get (ctx , types.NamespacedName {Name : expectedRouteName , Namespace : testNamespace }, loaded )
391+ fatalIfError (t , err , "failed to load route %q: %s" , expectedRouteName , err )
376392
393+ // Verify TLS configuration
377394 wantTLSConfig := & routev1.TLSConfig {
378395 Termination : routev1 .TLSTerminationEdge ,
379396 Certificate : "test-certificate" ,
@@ -383,28 +400,36 @@ func TestReconcileRouteApplicationSetTls(t *testing.T) {
383400 InsecureEdgeTerminationPolicy : routev1 .InsecureEdgeTerminationPolicyRedirect ,
384401 }
385402 if diff := cmp .Diff (wantTLSConfig , loaded .Spec .TLS ); diff != "" {
386- t .Fatalf ("failed to reconcile route:\n %s" , diff )
403+ t .Fatalf ("failed to reconcile route TLS config :\n %s" , diff )
387404 }
388405
389- assert .Empty (t , loaded .Spec .Host )
406+ // Verify hostname
407+ expectedHost := fmt .Sprintf ("%s-%s-%s.apps.example.com" , testArgoCDName , common .ApplicationSetControllerWebhookSuffix , testNamespace )
408+ if diff := cmp .Diff (expectedHost , loaded .Spec .Host ); diff != "" {
409+ t .Fatalf ("failed to reconcile route hostname:\n %s" , diff )
410+ }
390411
412+ // Verify port configuration
391413 wantPort := & routev1.RoutePort {
392414 TargetPort : intstr .FromString ("webhook" ),
393415 }
394416 if diff := cmp .Diff (wantPort , loaded .Spec .Port ); diff != "" {
395- t .Fatalf ("failed to reconcile route:\n %s" , diff )
417+ t .Fatalf ("failed to reconcile route port :\n %s" , diff )
396418 }
397419
420+ // Verify annotations
398421 if diff := cmp .Diff ("my-annotation-value" , loaded .Annotations ["my-annotation-key" ]); diff != "" {
399- t .Fatalf ("failed to reconcile route:\n %s" , diff )
422+ t .Fatalf ("failed to reconcile route annotations :\n %s" , diff )
400423 }
401424
425+ // Verify labels
402426 if diff := cmp .Diff ("my-label-value" , loaded .Labels ["my-label-key" ]); diff != "" {
403- t .Fatalf ("failed to reconcile route:\n %s" , diff )
427+ t .Fatalf ("failed to reconcile route labels :\n %s" , diff )
404428 }
405429
430+ // Verify wildcard policy
406431 if diff := cmp .Diff (wildcardPolicy , loaded .Spec .WildcardPolicy ); diff != "" {
407- t .Fatalf ("failed to reconcile route:\n %s" , diff )
432+ t .Fatalf ("failed to reconcile route wildcard policy :\n %s" , diff )
408433 }
409434}
410435
@@ -492,6 +517,65 @@ func TestReconcileRouteForShorteningHostname(t *testing.T) {
492517 }
493518}
494519
520+ func TestReconcileRouteForShorteningRoutename (t * testing.T ) {
521+ routeAPIFound = true
522+ ctx := context .Background ()
523+ logf .SetLogger (ZapLogger (true ))
524+
525+ // Use a long ArgoCD instance name to force truncation
526+ longName := "this-is-a-very-long-argocd-instance-name-that-will-break-the-route-name-limit"
527+ argoCD := makeArgoCD (func (a * argoproj.ArgoCD ) {
528+ a .Name = longName
529+ a .Spec .ApplicationSet = & argoproj.ArgoCDApplicationSet {
530+ WebhookServer : argoproj.WebhookServerSpec {
531+ Route : argoproj.ArgoCDRouteSpec {
532+ Enabled : true ,
533+ },
534+ },
535+ }
536+ })
537+
538+ // Add a fake Ingress resource to satisfy the domain lookup
539+ ingressConfig := & configv1.Ingress {
540+ ObjectMeta : metav1.ObjectMeta {
541+ Name : "cluster" ,
542+ },
543+ Spec : configv1.IngressSpec {
544+ Domain : "apps.example.com" ,
545+ },
546+ }
547+
548+ resObjs := []client.Object {argoCD , ingressConfig }
549+ subresObjs := []client.Object {argoCD }
550+ runtimeObjs := []runtime.Object {}
551+ sch := makeTestReconcilerScheme (argoproj .AddToScheme , configv1 .Install , routev1 .Install )
552+ cl := makeTestReconcilerClient (sch , resObjs , subresObjs , runtimeObjs )
553+ r := makeTestReconciler (cl , sch )
554+
555+ assert .NoError (t , createNamespace (r , argoCD .Namespace , "" ))
556+
557+ req := reconcile.Request {
558+ NamespacedName : types.NamespacedName {
559+ Name : longName ,
560+ Namespace : testNamespace ,
561+ },
562+ }
563+
564+ _ , err := r .Reconcile (context .TODO (), req )
565+ assert .NoError (t , err )
566+
567+ // The route name should be truncated to 63 chars
568+ expectedRouteName := longName + "-" + common .ApplicationSetControllerWebhookSuffix
569+ if len (expectedRouteName ) > 63 {
570+ expectedRouteName = expectedRouteName [:63 ]
571+ }
572+
573+ loaded := & routev1.Route {}
574+ err = r .Client .Get (ctx , types.NamespacedName {Name : expectedRouteName , Namespace : testNamespace }, loaded )
575+ assert .NoError (t , err )
576+ assert .LessOrEqual (t , len (loaded .Name ), 63 )
577+ }
578+
495579func TestReconcileRouteTLSConfig (t * testing.T ) {
496580 routeAPIFound = true
497581 ctx := context .Background ()
0 commit comments