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(gatewayapi): update gateway-api and fix failing RouteKind tests #5175

Merged
merged 6 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace sigs.k8s.io/gateway-api => github.com/kumahq/gateway-api v0.0.0-20220822185518-e8a3f0be778b
replace sigs.k8s.io/gateway-api => github.com/kumahq/gateway-api v0.0.0-20221019125100-747a4fedfd7a
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/ktrysmt/go-bitbucket v0.6.4/go.mod h1:9u0v3hsd2rqCHRIpbir1oP7F58uo5dq19sBYvuMoyQ4=
github.com/kumahq/gateway-api v0.0.0-20220822185518-e8a3f0be778b h1:bOI+l61dTIF2vXrB/SUlRKCzJhFgGlBTVDKxKSCGrv8=
github.com/kumahq/gateway-api v0.0.0-20220822185518-e8a3f0be778b/go.mod h1:x0AP6gugkFV8fC/oTlnOMU0pnmuzIR8LfIPRVUjxSqA=
github.com/kumahq/gateway-api v0.0.0-20221019125100-747a4fedfd7a h1:szFGMVdySxtKAjCxO3JUncfr1JGWOIlQaqWnrTUJsBc=
github.com/kumahq/gateway-api v0.0.0-20221019125100-747a4fedfd7a/go.mod h1:x0AP6gugkFV8fC/oTlnOMU0pnmuzIR8LfIPRVUjxSqA=
github.com/kumahq/kuma-net v0.7.2 h1:892BxDUkSQjQZR2DUaAub/2DNN6VEQd/CaGrQIlFtR0=
github.com/kumahq/kuma-net v0.7.2/go.mod h1:aqhBHsY3LQCTvBOr7oU1r2hwjTn9vhXUKDJXJokkSCM=
github.com/kumahq/protoc-gen-kumadoc v0.3.1 h1:tY2dGQJTYVGkhxAHN154fddcWDRy55Pl4+oLT+FhsHo=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package gatewayapi
import (
"context"
"fmt"
"strings"

kube_core "k8s.io/api/core/v1"
kube_apierrs "k8s.io/apimachinery/pkg/api/errors"
kube_apimeta "k8s.io/apimachinery/pkg/api/meta"
kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
kube_types "k8s.io/apimachinery/pkg/types"
kube_client "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -191,20 +193,23 @@ func (r *GatewayReconciler) gapiToKumaGateway(
continue
}

var unsupportedRouteGroupKinds []string
for _, gk := range l.AllowedRoutes.Kinds {
if gk.Kind != common.HTTPRouteKind || *gk.Group != gatewayapi.GroupName {
metaGK := kube_meta.GroupKind{Group: string(*gk.Group), Kind: string(gk.Kind)}
listenerConditions[l.Name] = append(listenerConditions[l.Name],
kube_meta.Condition{
Type: string(gatewayapi.ListenerConditionResolvedRefs),
Status: kube_meta.ConditionFalse,
Reason: string(gatewayapi.ListenerReasonInvalidRouteKinds),
Message: fmt.Sprintf("unexpected RouteGroupKind %q", metaGK.String()),
},
)
continue
unsupportedRouteGroupKinds = append(unsupportedRouteGroupKinds, metaGK.String())
}
}
if len(unsupportedRouteGroupKinds) > 0 {
listenerConditions[l.Name] = append(listenerConditions[l.Name],
kube_meta.Condition{
Type: string(gatewayapi.ListenerConditionResolvedRefs),
Status: kube_meta.ConditionFalse,
Reason: string(gatewayapi.ListenerReasonInvalidRouteKinds),
Message: fmt.Sprintf("unexpected RouteGroupKind %q", strings.Join(unsupportedRouteGroupKinds, ", ")),
},
)
}

listener.Hostname = "*"
if l.Hostname != nil {
Expand Down Expand Up @@ -322,34 +327,41 @@ func handleConditions(conditions []kube_meta.Condition, unresolvableCertRef *cer

var resolvedRefConditions []kube_meta.Condition

if unresolvableCertRef == nil {
resolvedRefConditions = []kube_meta.Condition{
{
if unresolvableCertRef != nil && !kube_apimeta.IsStatusConditionFalse(conditions, string(gatewayapi.ListenerConditionResolvedRefs)) {
kube_apimeta.SetStatusCondition(&conditions,
kube_meta.Condition{
Type: string(gatewayapi.ListenerConditionResolvedRefs),
Status: kube_meta.ConditionFalse,
Reason: unresolvableCertRef.reason,
Message: unresolvableCertRef.message,
},
)
}

if !kube_apimeta.IsStatusConditionFalse(conditions, string(gatewayapi.ListenerConditionResolvedRefs)) {
kube_apimeta.SetStatusCondition(&conditions,
kube_meta.Condition{
Type: string(gatewayapi.ListenerConditionResolvedRefs),
Status: kube_meta.ConditionTrue,
Reason: string(gatewayapi.ListenerReasonResolvedRefs),
},
{
)
kube_apimeta.SetStatusCondition(&conditions,
kube_meta.Condition{
Type: string(gatewayapi.ListenerConditionReady),
Status: kube_meta.ConditionTrue,
Reason: string(gatewayapi.ListenerConditionReady),
Reason: string(gatewayapi.ListenerReasonReady),
},
}
)
} else {
resolvedRefConditions = []kube_meta.Condition{
{
Type: string(gatewayapi.ListenerConditionResolvedRefs),
Status: kube_meta.ConditionFalse,
Reason: unresolvableCertRef.reason,
Message: unresolvableCertRef.message,
},
{
kube_apimeta.SetStatusCondition(&conditions,
kube_meta.Condition{
Type: string(gatewayapi.ListenerConditionReady),
Status: kube_meta.ConditionFalse,
Reason: string(gatewayapi.ListenerReasonInvalid),
Message: "unable to resolve refs",
},
}
)
}

return append(conditions, resolvedRefConditions...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"
kube_client "sigs.k8s.io/controller-runtime/pkg/client"
gatewayapi "sigs.k8s.io/gateway-api/apis/v1beta1"
gatewayapi_util "sigs.k8s.io/gateway-api/apis/v1beta1/util/translator"

mesh_k8s "github.com/kumahq/kuma/pkg/plugins/resources/k8s/native/api/v1alpha1"
"github.com/kumahq/kuma/pkg/plugins/runtime/k8s/controllers/gatewayapi/common"
Expand Down Expand Up @@ -145,18 +146,36 @@ func mergeGatewayListenerStatuses(
// for each new parentstatus, either add it to the list or update the
// existing one
for name, conditions := range conditions {
var listener gatewayapi.Listener
for _, l := range gateway.Spec.Listeners {
if l.Name == name {
listener = l
}
}

supportedKinds := []gatewayapi.RouteGroupKind{}
if len(listener.AllowedRoutes.Kinds) == 0 {
supportedKinds = append(supportedKinds,
gatewayapi.RouteGroupKind{Group: gatewayapi_util.GroupPtr(gatewayapi.GroupVersion.Group), Kind: common.HTTPRouteKind},
)
}
for _, rgk := range listener.AllowedRoutes.Kinds {
if string(*rgk.Group) == gatewayapi.GroupVersion.Group && rgk.Kind == common.HTTPRouteKind {
supportedKinds = append(supportedKinds, rgk)
}
}

previousStatus := gatewayapi.ListenerStatus{
Name: name,
AttachedRoutes: 0,
// TODO this should be Listener.AllowedRoutes with invalid kinds
// removed, i.e. it may be empty
SupportedKinds: []gatewayapi.RouteGroupKind{{Kind: common.HTTPRouteKind}},
}

if prev, ok := previousStatuses[name]; ok {
previousStatus = prev
}

previousStatus.SupportedKinds = supportedKinds

for _, condition := range conditions {
condition.ObservedGeneration = gateway.GetGeneration()
kube_apimeta.SetStatusCondition(&previousStatus.Conditions, condition)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/gateway/gatewayapi/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestConformance(t *testing.T) {
ValidUniqueListenerPorts: validUniqueListenerPorts,
SupportedFeatures: []suite.SupportedFeature{
suite.SupportHTTPRouteQueryParamMatching,
suite.SupportReferenceGrant,
suite.SupportHTTPRouteMethodMatching,
},
})

Expand Down