Skip to content

Conversation

shuqz
Copy link
Collaborator

@shuqz shuqz commented Jun 23, 2025

Description

  • added httproute matching logic
  • added precedence order logic to assign priority
  • added weighted target group support
  • sourceIp is not cover in this PR -> this will be covered in lbConfig, another PR
  • i am giving pathType priority as exact > regex > pathPrefix, but this can be changed

Checklist

  • Added tests that cover your change (if possible)
  • run gateway E2E and it passed
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
a comprohensive test example, provided two YAML (both prefers to same parentRef):
----------------------------------------------------------
metadata:
  name: http-app-5
  namespace: sample-gateway-alb
spec:
  parentRefs:
    - name: sample-gw-alb
      port: 80
  hostnames:
    - "test.a.example.com"
    - "test.example.com"
  rules: 
    - backendRefs:
        - name: echoserver
          port: 80
          weight: 70
        - name: echoserver2
          port: 80
          weight: 30
      matches:
        - path:
            type: PathPrefix
            value: /PathPrefixShouldSecondPriority
        - path:
            type: Exact
            value: /exactHighPriority
        - path:
            type: PathPrefix
            value: /PathPrefixLowPriority
----------------------------------------------------------
metadata:
  name: http-app-6
  namespace: sample-gateway-alb
spec:
  parentRefs:
    - name: sample-gw-alb
      port: 80
  hostnames:
    - "test.a.example.com"
    - "*.example.com"
    - "*.com"
  rules: # no matches specified
    - backendRefs:
        - name: echoserver
          port: 80
          weight: 50
        - name: echoserver2
          port: 80
          weight: 0
      matches:
        - path:
            type: Exact
            value: /exactPath
        - headers:
            - name: "firstMatch"
              value: "someValue"
        - path: # Regex path match
            type: RegularExpression
            value: "/v+?/users"
    - backendRefs:
        - name: echoserver2
          port: 80
      matches:
        - path: # not specify type, should be treated as pathPrefix
            value: "/pathPrefixMatch"
          headers:
            - name: "version"
              type: RegularExpression
              value: "*[0-9]a-Z*"

result:

Screenshot 2025-06-24 at 11 04 55 AM
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 23, 2025
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 23, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @shuqz. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jun 23, 2025
return tgErr
}
actions := buildL4ListenerDefaultActions(targetGroup) // TODO: update this and weighted target group support
albRules = append(albRules, ingress.Rule{
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be best to not mingle the ingress and gateway packages. Would it be possible to take some time to refactor what we need out of the ingress package into a common package.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i will take a look

})
}

type RulePrecedence struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: consider putting this into it's own file, as to not bloat the general utilities file.

for _, route := range routes {
routeNamespacedName := route.GetRouteNamespacedName().String()
routeCreateTimestamp := getRouteCreateTimestamp(route)
highestPrecedenceHostname := getHighestPrecedenceHostname(route.GetHostnames())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is interesting. Were you following a specific specification here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess I need some clarification, because I only see these specific rules under the GRPC route.
https://gateway-api.sigs.k8s.io/reference/spec/#grpcroutespec

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

synced offline regarding this, added the missing piece in new commit

@shuqz shuqz force-pushed the shuqz-httproute branch from 353d19f to 16a5588 Compare June 24, 2025 17:59
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 24, 2025
@shuqz shuqz changed the title [feat gw-api]implement httproute matching [feat gw-api]implement httproute matching and weighted target group Jun 24, 2025
if pathType == gwv1.PathMatchPathPrefix {
// the paths `/abc`, `/abc/`, and `/abc/def` would all match the prefix `/abc`, but the path `/abcd` would not.
if pathValue == "/" {
pathValue = "/*"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain why this is needed? I was checking against the Ingress implementation and we translate / -> / without adding the wildcard.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i was thinking, when pathType and value is not specified, it will be automatically assigned as prefix and /. and in this case, we should pass /* to ALB to present that this allows all path.

	// +optional
	// +kubebuilder:default={type: "PathPrefix", value: "/"}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this what you're referring to?

	// If no matches are specified, the default is a prefix
	// path match on "/", which has the effect of matching every
	// HTTP request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

synced offline

})
}

func getHostnameListPrecedenceOrder(hostnameOne, hostnameTwo []string) int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: adding a comment stating that the behavior is to NOT tiebreak when lists are not equal length but have the same elements, e.g

routeA: 
hostname: 
- "test.example.com" -> highest
- "test.a.com"
- "*.a.com"

routeB: 
hostname: 
- "test.example.com"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah i have a comment regarding this before return 0 at the end, but i can add a general comment for this function

Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT : func getHostnameListPrecedenceOrder(hostnameListOne, hostnameListTwo []string)

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 24, 2025
@zac-nixon
Copy link
Collaborator

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 24, 2025

for _, route := range routes {
routeNamespacedName := route.GetRouteNamespacedName().String()
routeCreateTimestamp := getRouteCreateTimestamp(route)
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT : Add this getRouteCreateTimestamp as part of routeMetadataDescriptor interface as its part of metadata of the routes.

type routeMetadataDescriptor interface {
    GetRouteNamespacedName() types.NamespacedName
    GetRouteKind() RouteKind
    GetHostnames() []gwv1.Hostname
    GetParentRefs() []gwv1.ParentReference
    GetRawRoute() interface{}
    GetBackendRefs() []gwv1.BackendRef
    GetRouteGeneration() int64
    GetRouteCreateTimestamp() time.Time  // Add this method
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea

// this is only for L7 ALB
func (l listenerBuilderImpl) buildListenerRules(stack core.Stack, ls *elbv2model.Listener, lb *elbv2model.LoadBalancer, securityGroups securityGroupOutput, gw *gwv1.Gateway, port int32, lbCfg elbv2gw.LoadBalancerConfiguration, routes map[int32][]routeutils.RouteDescriptor) error {
// sort all rules based on precedence
routesWithPrecedenceOrder := routeutils.SortAllRulesByPrecedence(routes[port])
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: renameroutesWithPrecedenceOrder to rulesWithPrecedenceOrder

rule := ruleWithPrecedence.Rule
var hostnamesStringList []string
// add hostname to condition
if hostnames := route.GetHostnames(); len(hostnames) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have this info already in ruleWithPrecedence. No need to create hostnamesStringList again from route.
Replace this with hostnamesStringList :=ruleWithPrecedence.Hostnames

@shuqz
Copy link
Collaborator Author

shuqz commented Jun 26, 2025

synced with shraddhabang we will defer validation check to API directly, resolving all validation related comments.

add weighted target group support and factor previous commit

address feedbacks and fix bug in prefix path build
@shuqz shuqz force-pushed the shuqz-httproute branch from 16a5588 to 9bb29d4 Compare June 27, 2025 00:26
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 27, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: shuqz, zac-nixon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@zac-nixon
Copy link
Collaborator

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 27, 2025
@k8s-ci-robot k8s-ci-robot merged commit bc93298 into kubernetes-sigs:main Jun 27, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants