Skip to content

Commit f2c4495

Browse files
committed
[feat gw-api] backfill E2E tests
ignore makefile address comments
1 parent e457112 commit f2c4495

File tree

8 files changed

+1071
-18
lines changed

8 files changed

+1071
-18
lines changed

pkg/gateway/model/model_build_listener.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"k8s.io/apimachinery/pkg/util/sets"
1515
elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1"
1616
"sigs.k8s.io/aws-load-balancer-controller/pkg/aws/services"
17-
certs "sigs.k8s.io/aws-load-balancer-controller/pkg/certs"
17+
"sigs.k8s.io/aws-load-balancer-controller/pkg/certs"
1818
"sigs.k8s.io/aws-load-balancer-controller/pkg/gateway/routeutils"
1919
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
2020
"sigs.k8s.io/aws-load-balancer-controller/pkg/model/core"
@@ -204,7 +204,7 @@ func (l listenerBuilderImpl) buildListenerRules(stack core.Stack, ls *elbv2model
204204
Weight: &weight,
205205
})
206206
}
207-
actions := buildL7ListenerActions(targetGroupTuples)
207+
actions := buildL7ListenerForwardActions(targetGroupTuples, nil)
208208

209209
// configure actions based on filters
210210
switch route.GetRouteKind() {
@@ -344,13 +344,24 @@ func buildL4ListenerDefaultActions(targetGroup *elbv2model.TargetGroup) []elbv2m
344344
}
345345
}
346346

347-
func buildL7ListenerActions(targetGroupTuple []elbv2model.TargetGroupTuple) []elbv2model.Action {
347+
func buildL7ListenerForwardActions(targetGroupTuple []elbv2model.TargetGroupTuple, duration *int32) []elbv2model.Action {
348+
349+
forwardConfig := &elbv2model.ForwardActionConfig{
350+
TargetGroups: targetGroupTuple,
351+
}
352+
353+
// Configure target group stickiness if a duration is specified
354+
if duration != nil {
355+
forwardConfig.TargetGroupStickinessConfig = &elbv2model.TargetGroupStickinessConfig{
356+
Enabled: awssdk.Bool(true),
357+
DurationSeconds: awssdk.Int32(*duration),
358+
}
359+
}
360+
348361
return []elbv2model.Action{
349362
{
350-
Type: elbv2model.ActionTypeForward,
351-
ForwardConfig: &elbv2model.ForwardActionConfig{
352-
TargetGroups: targetGroupTuple,
353-
},
363+
Type: elbv2model.ActionTypeForward,
364+
ForwardConfig: forwardConfig,
354365
},
355366
}
356367
}

pkg/gateway/routeutils/route_rule_condition.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ func buildHttpHeaderCondition(headers []gwv1.HTTPHeaderMatch) []elbv2model.RuleC
9898
Field: elbv2model.RuleConditionFieldHTTPHeader,
9999
HTTPHeaderConfig: &elbv2model.HTTPHeaderConditionConfig{
100100
HTTPHeaderName: string(header.Name),
101-
Values: []string{header.Value},
101+
// for a given HTTPHeaderName, ALB rule can accept a list of values. However, gateway route headers only accept one value per name, and name cannot duplicate.
102+
Values: []string{header.Value},
102103
},
103104
},
104105
}
@@ -146,15 +147,14 @@ func buildGrpcRouteRuleConditions(matches RouteRule) ([][]elbv2model.RuleConditi
146147
return conditions, nil
147148
}
148149

150+
// BuildHttpRuleActionsBasedOnFilter only request redirect is supported, header modification is limited due to ALB support level.
149151
func BuildHttpRuleActionsBasedOnFilter(filters []gwv1.HTTPRouteFilter) ([]elbv2model.Action, error) {
150152
for _, filter := range filters {
151153
switch filter.Type {
152-
case gwv1.HTTPRouteFilterRequestHeaderModifier:
153-
// TODO: decide behavior for request header modifier
154154
case gwv1.HTTPRouteFilterRequestRedirect:
155155
return buildHttpRedirectAction(filter.RequestRedirect)
156-
case gwv1.HTTPRouteFilterResponseHeaderModifier:
157-
// TODO: decide behavior for response header modifier
156+
default:
157+
return nil, errors.Errorf("Unsupported filter type: %v. Only request redirect is supported. To specify header modification, please configure it through LoadBalancerConfiguration.", filter.Type)
158158
}
159159
}
160160
return nil, nil

pkg/gateway/routeutils/route_rule_condition_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package routeutils
22

33
import (
4+
awssdk "github.com/aws/aws-sdk-go-v2/aws"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -391,3 +392,51 @@ func Test_buildHttpRedirectAction(t *testing.T) {
391392
})
392393
}
393394
}
395+
396+
func Test_BuildHttpRuleActionsBasedOnFilter(t *testing.T) {
397+
tests := []struct {
398+
name string
399+
filters []gwv1.HTTPRouteFilter
400+
wantErr bool
401+
errContains string
402+
}{
403+
{
404+
name: "request redirect filter",
405+
filters: []gwv1.HTTPRouteFilter{
406+
{
407+
Type: gwv1.HTTPRouteFilterRequestRedirect,
408+
RequestRedirect: &gwv1.HTTPRequestRedirectFilter{
409+
Port: (*gwv1.PortNumber)(awssdk.Int32(80)),
410+
},
411+
},
412+
},
413+
wantErr: false,
414+
},
415+
{
416+
name: "unsupported filter type",
417+
filters: []gwv1.HTTPRouteFilter{
418+
{
419+
Type: gwv1.HTTPRouteFilterRequestHeaderModifier,
420+
},
421+
},
422+
wantErr: true,
423+
errContains: "Unsupported filter type",
424+
},
425+
}
426+
427+
for _, tt := range tests {
428+
t.Run(tt.name, func(t *testing.T) {
429+
actions, err := BuildHttpRuleActionsBasedOnFilter(tt.filters)
430+
431+
if tt.wantErr {
432+
assert.Error(t, err)
433+
if tt.errContains != "" {
434+
assert.Contains(t, err.Error(), tt.errContains)
435+
}
436+
assert.Nil(t, actions)
437+
} else {
438+
assert.NoError(t, err)
439+
}
440+
})
441+
}
442+
}

0 commit comments

Comments
 (0)