Skip to content
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: make KIC v2 Gateway API v2 config generation deterministic #1302

Merged
merged 1 commit into from
May 27, 2024
Merged
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 kong2kic/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kong2kic
import (
"encoding/json"
"log"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -274,6 +275,36 @@ func addPluginsToRoute(
return nil
}

// HeadersByNameTypeAndValue is a type to sort headers by name, type and value.
// This is needed to ensure that the order of headers is consistent across runs.
type HeadersByNameTypeAndValue []k8sgwapiv1.HTTPHeaderMatch

func (a HeadersByNameTypeAndValue) Len() int { return len(a) }
func (a HeadersByNameTypeAndValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a HeadersByNameTypeAndValue) Less(i, j int) bool {
if a[i].Name < a[j].Name {
return true
}
if a[i].Name > a[j].Name {
return false
}

if a[i].Type != nil && a[j].Type == nil {
return true
}
if a[i].Type == nil && a[j].Type != nil {
return false
}

if *a[i].Type < *a[j].Type {
return true
}
if *a[i].Type > *a[j].Type {
return false
}
return a[i].Value < a[j].Value
}

// Convert route to HTTPRoute (Gateway API)
func populateKICIngressesWithGatewayAPI(content *file.Content, kicContent *KICContent) error {
for _, service := range content.Services {
Expand Down Expand Up @@ -397,6 +428,7 @@ func populateKICIngressesWithGatewayAPI(content *file.Content, kicContent *KICCo
})
}
}
sort.Sort(HeadersByNameTypeAndValue(httpHeaderMatch))
}

// If path is not nil, then for each path, for each method, add a httpRouteRule
Expand Down
Loading