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
32 changes: 32 additions & 0 deletions docs/guides/advanced-configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@ However, the controller utilizes [IMDS](https://docs.aws.amazon.com/AWSEC2/lates

- **If your cluster cannot access to IMDS.** ensure to specify the[configuration variables](environment.md) when installing the controller.

### Rule Priority Configuration

You can manually assign priorities to rules using the custom annotation `application-networking.k8s.aws/rule-{index}-priority`. This annotation allows you to explicitly set the priority for specific rules in your route configurations.

For example, to set priorities for multiple rules in an HTTPRoute:

```yaml
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: example-route
annotations:
application-networking.k8s.aws/rule-0-priority: "200" # First rule gets higher priority
application-networking.k8s.aws/rule-1-priority: "100" # Second rule gets lower priority
spec:
rules:
- matches: # This is rule[0]
- path:
type: PathPrefix
value: /api/v2
- matches: # This is rule[1]
- path:
type: PathPrefix
value: /api
```

The `{index}` in the annotation corresponds to the zero-based index of the rule in the rules array. In this example:
- `rule-0-priority: "200"` applies to the first rule matching `/api/v2`
- `rule-1-priority: "100"` applies to the second rule matching `/api`

Higher priority values indicate higher precedence, so requests to `/api/v2` will be matched by the first rule (priority 200) before the second rule (priority 100) is considered.

### IPv6 support

IPv6 address type is automatically used for your services and pods if
Expand Down
55 changes: 52 additions & 3 deletions pkg/gateway/model_build_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"context"
"errors"
"fmt"
"strconv"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"

anv1alpha1 "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
"github.com/aws/aws-application-networking-k8s/pkg/model/core"
"github.com/aws/aws-application-networking-k8s/pkg/utils"

"github.com/aws/aws-sdk-go/aws"

Expand All @@ -32,10 +34,59 @@ func (t *latticeServiceModelBuildTask) buildRules(ctx context.Context, stackList
// note we only build rules for non-deleted routes
t.log.Debugf(ctx, "Processing %d rules", len(t.route.Spec().Rules()))

// Track rules with and without priority
rulesWithoutPriority := make([]core.RouteRule, 0)
priorityQueue := make(utils.PriorityQueue, 0)

// First pass: build all rules and add them to priority queue
for i, rule := range t.route.Spec().Rules() {
// Default priority is index + 1
priority := int64(i + 1)

// Check for priority annotation in format: application-networking.k8s.aws/rule-{index}-priority
if priorityStr, ok := t.route.K8sObject().GetAnnotations()[fmt.Sprintf("application-networking.k8s.aws/rule-%d-priority", i)]; ok {
if p, err := strconv.ParseInt(priorityStr, 10, 64); err == nil {
priority = p
t.log.Debugf(ctx, "Using priority %d from annotation for rule %d", priority, i)
} else {
t.log.Warnf(ctx, "Invalid priority value in annotation for rule %d: %s", i, priorityStr)
}

priorityQueue.Push(&utils.Item{
Value: rule,
Priority: int32(priority),
})

} else {
rulesWithoutPriority = append(rulesWithoutPriority, rule)
}
}

// Assign rules without a manually assigned priority a priority in sequential order following the greatest
// manually assigned priority
for _, ruleSpec := range rulesWithoutPriority {
// No manually assigned priorities
topItem, err := priorityQueue.Peek()
if err == nil {
t.log.Debugf(ctx, "Setting default rule priority set to: %d", topItem.Priority+1)
priorityQueue.Push(&utils.Item{
Value: ruleSpec,
Priority: topItem.Priority + 1,
})
} else {
t.log.Debugf(ctx, "Setting default rule priority set to: %d", 1)
priorityQueue.Push(&utils.Item{
Value: ruleSpec,
Priority: 1,
})
}
}

for _, item := range priorityQueue {
rule := item.Value.(core.RouteRule)
ruleSpec := model.RuleSpec{
StackListenerId: stackListenerId,
Priority: int64(i + 1),
Priority: int64(item.Priority),
}

if len(rule.Matches()) > 1 {
Expand All @@ -62,14 +113,12 @@ func (t *latticeServiceModelBuildTask) buildRules(ctx context.Context, stackList
return err
}
} else {

// Match every traffic on no matches
ruleSpec.PathMatchValue = "/"
ruleSpec.PathMatchPrefix = true
if _, ok := rule.(*core.GRPCRouteRule); ok {
ruleSpec.Method = string(gwv1.HTTPMethodPost)
}

}

ruleTgList, err := t.getTargetGroupsForRuleAction(ctx, rule)
Expand Down
Loading
Loading