-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ingress rules order is preserved #97
Conversation
@mlavacca I think we want to make sure we dont produce different rule orders other than making the tests pass with different order. |
yep, I agree that we should preserve the rule orders. I dug a bit into the issue, and the problem is caused by the fact that in the common package we aggregate the ingress rules into a map, and then we iterate that map to create HTTPRoute rules. Since map order is not guaranteed, this can cause flakes. This problem has been surfaced by the new kong test as there were no tests with ingresses having multiple rules previously. We may need to add some logic to fix it. I'll do it in this PR. |
9b640b5
to
c49da87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this one @mlavacca!
The ingress rules order is kept during Ingress to Gateway conversion. Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
c49da87
to
c643b6b
Compare
c643b6b
to
4fd1ff2
Compare
Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
4fd1ff2
to
ba636b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an idea.
Is this helping also achieving what we want?
type orderedPathsByMatchGroup struct {
keys []pathMatchKey
data map[pathMatchKey][]ingressPath
}
func (rg *ingressRuleGroup) toHTTPRoute() (gatewayv1beta1.HTTPRoute, field.ErrorList) {
// pathsByMatchGroup := map[pathMatchKey][]ingressPath{}
pathsByMatchGroup := &orderedPathsByMatchGroup{
keys: []pathMatchKey{},
data: make(map[pathMatchKey][]ingressPath),
}
var errors field.ErrorList
for i, ir := range rg.rules {
for j, path := range ir.rule.HTTP.Paths {
ip := ingressPath{ruleIdx: i, pathIdx: j, ruleType: "http", path: path}
pmKey := getPathMatchKey(ip)
if _, ok := pathsByMatchGroup.data[pmKey]; !ok {
pathsByMatchGroup.keys = append(pathsByMatchGroup.keys, pmKey)
}
pathsByMatchGroup.data[pmKey] = append(pathsByMatchGroup.data[pmKey], ip)
}
}
later in the range:
for _, pmKey := range pathsByMatchGroup.keys {
paths := pathsByMatchGroup.data[pmKey]
path := paths[0]
By keeping only the keys in a slice, we can also retain the order in which the elements were added.
I have not ran this but it feels like it could work
Co-authored-by: Lior Lieberman <liorlieberman@google.com> Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
It makes sense, your proposal is more efficient. I've made this change and changed the tests accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Mattia!
Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: LiorLieberman, mlavacca 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 |
Co-authored-by: Lior Lieberman <liorlib7+riskified@gmail.com>
Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
b5d677e
to
f03f896
Compare
Thanks Mattia! |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Ingress Rules order needs to be preserved when converting into
HTTPRoute
rules.Which issue(s) this PR fixes:
Fixes #91
Does this PR introduce a user-facing change?: