Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions pkg/gateway/model/model_build_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
elbv2gw "sigs.k8s.io/aws-load-balancer-controller/apis/gateway/v1beta1"
"sigs.k8s.io/aws-load-balancer-controller/pkg/aws/services"
certs "sigs.k8s.io/aws-load-balancer-controller/pkg/certs"
"sigs.k8s.io/aws-load-balancer-controller/pkg/certs"
"sigs.k8s.io/aws-load-balancer-controller/pkg/gateway/routeutils"
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
"sigs.k8s.io/aws-load-balancer-controller/pkg/model/core"
Expand Down Expand Up @@ -204,7 +204,7 @@ func (l listenerBuilderImpl) buildListenerRules(stack core.Stack, ls *elbv2model
Weight: &weight,
})
}
actions := buildL7ListenerActions(targetGroupTuples)
actions := buildL7ListenerForwardActions(targetGroupTuples, nil)

// configure actions based on filters
switch route.GetRouteKind() {
Expand Down Expand Up @@ -344,13 +344,24 @@ func buildL4ListenerDefaultActions(targetGroup *elbv2model.TargetGroup) []elbv2m
}
}

func buildL7ListenerActions(targetGroupTuple []elbv2model.TargetGroupTuple) []elbv2model.Action {
func buildL7ListenerForwardActions(targetGroupTuple []elbv2model.TargetGroupTuple, duration *int32) []elbv2model.Action {

forwardConfig := &elbv2model.ForwardActionConfig{
TargetGroups: targetGroupTuple,
}

// Configure target group stickiness if a duration is specified
if duration != nil {
forwardConfig.TargetGroupStickinessConfig = &elbv2model.TargetGroupStickinessConfig{
Enabled: awssdk.Bool(true),
DurationSeconds: awssdk.Int32(*duration),
}
}

return []elbv2model.Action{
{
Type: elbv2model.ActionTypeForward,
ForwardConfig: &elbv2model.ForwardActionConfig{
TargetGroups: targetGroupTuple,
},
Type: elbv2model.ActionTypeForward,
ForwardConfig: forwardConfig,
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/gateway/routeutils/route_rule_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func buildHttpHeaderCondition(headers []gwv1.HTTPHeaderMatch) []elbv2model.RuleC
Field: elbv2model.RuleConditionFieldHTTPHeader,
HTTPHeaderConfig: &elbv2model.HTTPHeaderConditionConfig{
HTTPHeaderName: string(header.Name),
Values: []string{header.Value},
// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Are we going to use the rule CRD to enhance this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, that's not discussed yet. i am ok to add it later when customer needs it.

Copy link
Collaborator Author

@shuqz shuqz Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if you want me to add it in rule-CRD, let's discuss it tomorrow

Values: []string{header.Value},
},
},
}
Expand Down Expand Up @@ -146,15 +147,14 @@ func buildGrpcRouteRuleConditions(matches RouteRule) ([][]elbv2model.RuleConditi
return conditions, nil
}

// BuildHttpRuleActionsBasedOnFilter only request redirect is supported, header modification is limited due to ALB support level.
func BuildHttpRuleActionsBasedOnFilter(filters []gwv1.HTTPRouteFilter) ([]elbv2model.Action, error) {
for _, filter := range filters {
switch filter.Type {
case gwv1.HTTPRouteFilterRequestHeaderModifier:
// TODO: decide behavior for request header modifier
case gwv1.HTTPRouteFilterRequestRedirect:
return buildHttpRedirectAction(filter.RequestRedirect)
case gwv1.HTTPRouteFilterResponseHeaderModifier:
// TODO: decide behavior for response header modifier
default:
return nil, errors.Errorf("Unsupported filter type: %v. Only request redirect is supported. To specify header modification, please configure it through LoadBalancerConfiguration.", filter.Type)
}
}
return nil, nil
Expand Down
49 changes: 49 additions & 0 deletions pkg/gateway/routeutils/route_rule_condition_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package routeutils

import (
awssdk "github.com/aws/aws-sdk-go-v2/aws"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -391,3 +392,51 @@ func Test_buildHttpRedirectAction(t *testing.T) {
})
}
}

func Test_BuildHttpRuleActionsBasedOnFilter(t *testing.T) {
tests := []struct {
name string
filters []gwv1.HTTPRouteFilter
wantErr bool
errContains string
}{
{
name: "request redirect filter",
filters: []gwv1.HTTPRouteFilter{
{
Type: gwv1.HTTPRouteFilterRequestRedirect,
RequestRedirect: &gwv1.HTTPRequestRedirectFilter{
Port: (*gwv1.PortNumber)(awssdk.Int32(80)),
},
},
},
wantErr: false,
},
{
name: "unsupported filter type",
filters: []gwv1.HTTPRouteFilter{
{
Type: gwv1.HTTPRouteFilterRequestHeaderModifier,
},
},
wantErr: true,
errContains: "Unsupported filter type",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actions, err := BuildHttpRuleActionsBasedOnFilter(tt.filters)

if tt.wantErr {
assert.Error(t, err)
if tt.errContains != "" {
assert.Contains(t, err.Error(), tt.errContains)
}
assert.Nil(t, actions)
} else {
assert.NoError(t, err)
}
})
}
}
Loading
Loading