@@ -28,6 +28,7 @@ import (
2828 "github.com/stretchr/testify/assert"
2929 "github.com/stretchr/testify/require"
3030 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+ "k8s.io/utils/ptr"
3132
3233 flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
3334 v1 "github.com/fluxcd/flagger/pkg/apis/gatewayapi/v1"
@@ -603,3 +604,106 @@ func TestGatewayAPIRouter_makeFilters_CORS(t *testing.T) {
603604 // Assert MaxAge (24h = 86400 seconds)
604605 assert .Equal (t , int32 (86400 ), corsFilter .CORS .MaxAge )
605606}
607+
608+ func TestGatewayAPIRouter_GetRoutes (t * testing.T ) {
609+ canary := newTestGatewayAPICanary ()
610+ mocks := newFixture (canary )
611+ router := & GatewayAPIRouter {
612+ gatewayAPIClient : mocks .meshClient ,
613+ kubeClient : mocks .kubeClient ,
614+ logger : mocks .logger ,
615+ }
616+
617+ httpRoute := & v1.HTTPRoute {
618+ ObjectMeta : metav1.ObjectMeta {
619+ Name : "podinfo" ,
620+ Generation : 1 ,
621+ },
622+ Spec : v1.HTTPRouteSpec {
623+ Rules : []v1.HTTPRouteRule {
624+ {
625+ BackendRefs : []v1.HTTPBackendRef {
626+ {
627+ BackendRef : v1.BackendRef {
628+ BackendObjectReference : v1.BackendObjectReference {
629+ Name : "podinfo-canary" ,
630+ },
631+ Weight : ptr .To (int32 (10 )),
632+ },
633+ },
634+ {
635+ BackendRef : v1.BackendRef {
636+ BackendObjectReference : v1.BackendObjectReference {
637+ Name : "podinfo-primary" ,
638+ },
639+ Weight : ptr .To (int32 (90 )),
640+ },
641+ },
642+ },
643+ },
644+ },
645+ CommonRouteSpec : v1.CommonRouteSpec {
646+ ParentRefs : []v1.ParentReference {
647+ {
648+ Name : "podinfo" ,
649+ },
650+ },
651+ },
652+ },
653+ }
654+ httpRoute , err := router .gatewayAPIClient .GatewayapiV1 ().HTTPRoutes ("default" ).Create (context .TODO (), httpRoute , metav1.CreateOptions {})
655+ require .NoError (t , err )
656+
657+ t .Run ("httproute generation" , func (t * testing.T ) {
658+ httpRoute .ObjectMeta .Generation = 5
659+ httpRoute .Status .Parents = []v1.RouteParentStatus {
660+ {
661+ ParentRef : v1.ParentReference {
662+ Name : "podinfo" ,
663+ SectionName : ptr .To (v1 .SectionName ("https" )),
664+ },
665+ Conditions : []metav1.Condition {
666+ {
667+ Type : string (v1 .RouteConditionAccepted ),
668+ Status : metav1 .ConditionTrue ,
669+ ObservedGeneration : 1 ,
670+ },
671+ },
672+ },
673+ {
674+ ParentRef : v1.ParentReference {
675+ Name : "podinfo" ,
676+ },
677+ Conditions : []metav1.Condition {
678+ {
679+ Type : string (v1 .RouteConditionAccepted ),
680+ Status : metav1 .ConditionFalse ,
681+ ObservedGeneration : 4 ,
682+ },
683+ },
684+ },
685+ }
686+ httpRoute , err := router .gatewayAPIClient .GatewayapiV1 ().HTTPRoutes ("default" ).Update (context .TODO (), httpRoute , metav1.UpdateOptions {})
687+ require .NoError (t , err )
688+
689+ _ , _ , _ , err = router .GetRoutes (canary )
690+ require .Error (t , err )
691+
692+ httpRoute .Status .Parents [1 ].Conditions [0 ].ObservedGeneration = 5
693+ _ , err = router .gatewayAPIClient .GatewayapiV1 ().HTTPRoutes ("default" ).Update (context .TODO (), httpRoute , metav1.UpdateOptions {})
694+ require .NoError (t , err )
695+
696+ _ , _ , _ , err = router .GetRoutes (canary )
697+ require .Error (t , err )
698+
699+ httpRoute .Status .Parents [1 ].Conditions [0 ].Status = metav1 .ConditionTrue
700+ _ , err = router .gatewayAPIClient .GatewayapiV1 ().HTTPRoutes ("default" ).Update (context .TODO (), httpRoute , metav1.UpdateOptions {})
701+ require .NoError (t , err )
702+
703+ primaryWeight , canaryWeight , mirrored , err := router .GetRoutes (canary )
704+ require .NoError (t , err )
705+ assert .Equal (t , 90 , primaryWeight )
706+ assert .Equal (t , 10 , canaryWeight )
707+ assert .False (t , mirrored )
708+ })
709+ }
0 commit comments