44 "context"
55 "crypto/tls"
66 "fmt"
7- "strings"
8- "time"
9-
107 awssdk "github.com/aws/aws-sdk-go-v2/aws"
118 elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
129 "github.com/gavv/httpexpect/v2"
@@ -24,6 +21,8 @@ import (
2421 "sigs.k8s.io/aws-load-balancer-controller/test/framework/utils"
2522 "sigs.k8s.io/aws-load-balancer-controller/test/framework/verifier"
2623 gwv1 "sigs.k8s.io/gateway-api/apis/v1"
24+ "strings"
25+ "time"
2726)
2827
2928var _ = Describe ("test k8s alb gateway using ip targets reconciled by the aws load balancer controller" , func () {
@@ -195,7 +194,6 @@ var _ = Describe("test k8s alb gateway using ip targets reconciled by the aws lo
195194 })
196195 })
197196 })
198-
199197 Context ("with ALB ip target configuration with HTTPRoute specified matches" , func () {
200198 BeforeEach (func () {})
201199 It ("should provision internet-facing load balancer resources" , func () {
@@ -666,7 +664,139 @@ var _ = Describe("test k8s alb gateway using ip targets reconciled by the aws lo
666664 })
667665 })
668666 })
667+ Context ("with ALB ip target configuration with path and url transforms" , func () {
668+ BeforeEach (func () {})
669+ It ("should provision internet-facing load balancer resources" , func () {
670+ interf := elbv2gw .LoadBalancerSchemeInternetFacing
671+ lbcSpec := elbv2gw.LoadBalancerConfigurationSpec {
672+ Scheme : & interf ,
673+ }
674+ ipTargetType := elbv2gw .TargetTypeIP
675+ tgSpec := elbv2gw.TargetGroupConfigurationSpec {
676+ DefaultConfiguration : elbv2gw.TargetGroupProps {
677+ TargetType : & ipTargetType ,
678+ },
679+ }
680+ gwListeners := []gwv1.Listener {
681+ {
682+ Name : "test-listener" ,
683+ Port : 80 ,
684+ Protocol : gwv1 .HTTPProtocolType ,
685+ },
686+ }
687+
688+ lrcSpec := elbv2gw.ListenerRuleConfigurationSpec {}
689+ httpr := buildHTTPRoute ([]string {}, []gwv1.HTTPRouteRule {}, & gwListeners [0 ].Name )
690+ httpr .Spec .Rules [0 ].Filters = []gwv1.HTTPRouteFilter {
691+ {
692+ Type : gwv1 .HTTPRouteFilterURLRewrite ,
693+ URLRewrite : & gwv1.HTTPURLRewriteFilter {
694+ Hostname : (* gwv1 .PreciseHostname )(awssdk .String ("foo.com" )),
695+ Path : & gwv1.HTTPPathModifier {
696+ Type : gwv1 .FullPathHTTPPathModifier ,
697+ ReplaceFullPath : awssdk .String ("/my/cool/path" ),
698+ },
699+ },
700+ },
701+ }
702+
703+ By ("deploying stack" , func () {
704+ err := stack .DeployHTTP (ctx , nil , tf , gwListeners , []* gwv1.HTTPRoute {httpr }, lbcSpec , tgSpec , lrcSpec , nil , true )
705+ Expect (err ).NotTo (HaveOccurred ())
706+ })
707+
708+ By ("checking gateway status for lb dns name" , func () {
709+ dnsName = stack .GetLoadBalancerIngressHostName ()
710+ Expect (dnsName ).ToNot (BeEmpty ())
711+ })
712+
713+ By ("querying AWS loadbalancer from the dns name" , func () {
714+ var err error
715+ lbARN , err = tf .LBManager .FindLoadBalancerByDNSName (ctx , dnsName )
716+ Expect (err ).NotTo (HaveOccurred ())
717+ Expect (lbARN ).ToNot (BeEmpty ())
718+ })
669719
720+ By ("verifying AWS loadbalancer resources" , func () {
721+ expectedTargetGroups := []verifier.ExpectedTargetGroup {
722+ {
723+ Protocol : "HTTP" ,
724+ Port : 80 ,
725+ NumTargets : int (* stack .albResourceStack .commonStack .dps [0 ].Spec .Replicas ),
726+ TargetType : "ip" ,
727+ TargetGroupHC : DEFAULT_ALB_TARGET_GROUP_HC ,
728+ },
729+ }
730+ err := verifier .VerifyAWSLoadBalancerResources (ctx , tf , lbARN , verifier.LoadBalancerExpectation {
731+ Type : "application" ,
732+ Scheme : "internet-facing" ,
733+ Listeners : stack .albResourceStack .getListenersPortMap (),
734+ TargetGroups : expectedTargetGroups ,
735+ })
736+ Expect (err ).NotTo (HaveOccurred ())
737+ })
738+
739+ By ("verifying HTTP load balancer listener" , func () {
740+ err := verifier .VerifyLoadBalancerListener (ctx , tf , lbARN , int32 (gwListeners [0 ].Port ), & verifier.ListenerExpectation {
741+ ProtocolPort : "HTTP:80" ,
742+ })
743+ Expect (err ).NotTo (HaveOccurred ())
744+ })
745+ By ("verifying listener rules" , func () {
746+ err := verifier .VerifyLoadBalancerListenerRules (ctx , tf , lbARN , int32 (gwListeners [0 ].Port ), []verifier.ListenerRuleExpectation {
747+ {
748+ Conditions : []elbv2types.RuleCondition {
749+ {
750+ Field : awssdk .String (string (elbv2model .RuleConditionFieldPathPattern )),
751+ PathPatternConfig : & elbv2types.PathPatternConditionConfig {
752+ Values : []string {"/*" },
753+ },
754+ },
755+ },
756+ Actions : []elbv2types.Action {
757+ {
758+ Type : elbv2types .ActionTypeEnum (elbv2model .ActionTypeForward ),
759+ ForwardConfig : & elbv2types.ForwardActionConfig {
760+ TargetGroups : []elbv2types.TargetGroupTuple {
761+ {
762+ TargetGroupArn : awssdk .String (testTargetGroupArn ),
763+ Weight : awssdk .Int32 (1 ),
764+ },
765+ },
766+ },
767+ },
768+ },
769+ Transforms : []elbv2types.RuleTransform {
770+ {
771+ Type : elbv2types .TransformTypeEnumHostHeaderRewrite ,
772+ HostHeaderRewriteConfig : & elbv2types.HostHeaderRewriteConfig {
773+ Rewrites : []elbv2types.RewriteConfig {
774+ {
775+ Replace : awssdk .String ("foo.com" ),
776+ Regex : awssdk .String (".*" ),
777+ },
778+ },
779+ },
780+ },
781+ {
782+ Type : elbv2types .TransformTypeEnumUrlRewrite ,
783+ UrlRewriteConfig : & elbv2types.UrlRewriteConfig {
784+ Rewrites : []elbv2types.RewriteConfig {
785+ {
786+ Replace : awssdk .String ("/my/cool/path" ),
787+ Regex : awssdk .String ("^([^?]*)" ),
788+ },
789+ },
790+ },
791+ },
792+ },
793+ Priority : 1 ,
794+ },
795+ })
796+ Expect (err ).NotTo (HaveOccurred ())
797+ })
798+ })
799+ })
670800 Context ("with ALB ip target configuration with secure HTTPRoute" , func () {
671801 BeforeEach (func () {})
672802 It ("should provision internet-facing load balancer resources" , func () {
0 commit comments