Skip to content

Commit

Permalink
fix: use correct type for KongRoute headers (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo authored Jan 21, 2025
1 parent 6304cc5 commit 6c02f7d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
- Fix unexpected error logs caused by passing an odd number of arguments to the logger
in the `KongConsumer` reconciler.
[#983](https://github.com/Kong/gateway-operator/pull/983)
- Fix `KongRoute` Konnect entity with a non-empty `headers` field reconciliation. The
`headers` field is now properly mapped to the expected Konnect schema.
[#1044](https://github.com/Kong/gateway-operator/pull/1044)

### Added

Expand Down
12 changes: 11 additions & 1 deletion controller/konnect/ops/ops_kongroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func kongRouteToSDKRouteInput(
) sdkkonnectcomp.RouteInput {
r := sdkkonnectcomp.RouteInput{
Destinations: route.Spec.KongRouteAPISpec.Destinations,
Headers: route.Spec.KongRouteAPISpec.Headers,
Headers: kongRouteHeadersToSDK(route.Spec.Headers),
Hosts: route.Spec.KongRouteAPISpec.Hosts,
HTTPSRedirectStatusCode: route.Spec.KongRouteAPISpec.HTTPSRedirectStatusCode,
Methods: route.Spec.KongRouteAPISpec.Methods,
Expand Down Expand Up @@ -139,3 +139,13 @@ func getKongRouteForUID(

return getMatchingEntryFromListResponseData(sliceToEntityWithIDPtrSlice(resp.Object.Data), r)
}

// kongRouteHeadersToSDK converts KongRoute headers to Konnect SDK headers.
// It's a simple conversion from map[string]string to map[string][]string - the format expected by Konnect SDK.
// TODO: Support multiple header values in KongRoute CRD.
// https://github.com/Kong/kubernetes-configuration/issues/234
func kongRouteHeadersToSDK(headers map[string]string) map[string][]string {
return lo.MapEntries(headers, func(k, v string) (string, []string) {
return k, []string{v}
})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go 1.23.2
retract v1.2.2

require (
github.com/Kong/sdk-konnect-go v0.1.21
github.com/Kong/sdk-konnect-go v0.1.24
github.com/Masterminds/semver v1.5.0
github.com/cloudflare/cfssl v1.6.5
github.com/go-logr/logr v1.4.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg6
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/Kong/sdk-konnect-go v0.1.21 h1:p+As05Ixy0YDy4NDGA35jNioQ2rt7OAVUoUHC5f10xk=
github.com/Kong/sdk-konnect-go v0.1.21/go.mod h1:xsmTIkBbmVyUh1nRFjQMOhxYIPDl+sMfmRmPuZHtwLE=
github.com/Kong/sdk-konnect-go v0.1.24 h1:U1rOiy9TtYg/pXl7CXABaN96c1rFuHal19zVCuNpkiA=
github.com/Kong/sdk-konnect-go v0.1.24/go.mod h1:xsmTIkBbmVyUh1nRFjQMOhxYIPDl+sMfmRmPuZHtwLE=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
Expand Down
3 changes: 3 additions & 0 deletions test/integration/test_konnect_entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func TestKonnectEntities(t *testing.T) {
func(obj client.Object) {
kr := obj.(*configurationv1alpha1.KongRoute)
kr.Spec.KongRouteAPISpec.Paths = []string{"/kr-" + testID}
kr.Spec.Headers = map[string]string{
"KongTestHeader": "example.com",
}
},
)
t.Cleanup(deleteObjectAndWaitForDeletionFn(t, kr.DeepCopy()))
Expand Down

0 comments on commit 6c02f7d

Please sign in to comment.