Skip to content

Commit

Permalink
Merge pull request #1228 from spencerhance/hostname-parentref
Browse files Browse the repository at this point in the history
Adds new tiny type for HTTPRoute Listeners in conformance tests
  • Loading branch information
k8s-ci-robot authored Jun 28, 2022
2 parents cea484e + ddb1f08 commit 751ccfc
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 28 deletions.
2 changes: 1 addition & 1 deletion conformance/tests/httproute-cross-namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var HTTPRouteCrossNamespace = suite.ConformanceTest{
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
routeNN := types.NamespacedName{Name: "cross-namespace", Namespace: "gateway-conformance-web-backend"}
gwNN := types.NamespacedName{Name: "backend-namespaces", Namespace: "gateway-conformance-infra"}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, gwNN, routeNN)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

t.Run("Simple HTTP request should reach web-backend", func(t *testing.T) {
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, http.ExpectedResponse{
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/httproute-exact-path-matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var HTTPExactPathMatching = suite.ConformanceTest{
ns := "gateway-conformance-infra"
routeNN := types.NamespacedName{Name: "exact-matching", Namespace: ns}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, gwNN, routeNN)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

testCases := []http.ExpectedResponse{
{
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/httproute-header-matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var HTTPRouteHeaderMatching = suite.ConformanceTest{
ns := "gateway-conformance-infra"
routeNN := types.NamespacedName{Name: "header-matching", Namespace: ns}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, gwNN, routeNN)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

testCases := []http.ExpectedResponse{{
Request: http.ExpectedRequest{Path: "/", Headers: map[string]string{"Version": "one"}},
Expand Down
4 changes: 2 additions & 2 deletions conformance/tests/httproute-hostname-intersection.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var HTTPRouteHostnameIntersection = suite.ConformanceTest{
{Namespace: ns, Name: "wildcard-host-matches-listener-specific-host"},
{Namespace: ns, Name: "wildcard-host-matches-listener-wildcard-host"},
}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, gwNN, routes...)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routes...)

var testCases []http.ExpectedResponse

Expand Down Expand Up @@ -189,7 +189,7 @@ var HTTPRouteHostnameIntersection = suite.ConformanceTest{
})

t.Run("HTTPRoutes that do not intersect with listener hostnames", func(t *testing.T) {
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, gwNN)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, kubernetes.NewGatewayRef(gwNN))

routeName := types.NamespacedName{Namespace: ns, Name: "no-intersecting-hosts"}
parents := []v1alpha2.RouteParentStatus{{
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/httproute-invalid-reference-grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var HTTPRouteInvalidReferenceGrant = suite.ConformanceTest{
// to add check for Accepted condition once
// https://github.com/kubernetes-sigs/gateway-api/issues/1112
// has been resolved
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, s.Client, s.ControllerName, gwNN)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, s.Client, s.ControllerName, kubernetes.NewGatewayRef(gwNN))

// TODO(mikemorris): Add check for HTTP requests successfully reaching
// app-backend-v1 at path "/" if it is determined that a Route with at
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/httproute-listener-hostname-matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var HTTPRouteListenerHostnameMatching = suite.ConformanceTest{
{Namespace: ns, Name: "backend-v2"},
{Namespace: ns, Name: "backend-v3"},
}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, gwNN, routes...)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routes...)

testCases := []http.ExpectedResponse{{
Request: http.ExpectedRequest{Host: "bar.com", Path: "/"},
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/httproute-matching-across-routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var HTTPRouteMatchingAcrossRoutes = suite.ConformanceTest{
routeNN1 := types.NamespacedName{Name: "matching-part1", Namespace: ns}
routeNN2 := types.NamespacedName{Name: "matching-part2", Namespace: ns}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, gwNN, routeNN1, routeNN2)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN1, routeNN2)

testCases := []http.ExpectedResponse{{
Request: http.ExpectedRequest{
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/httproute-matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var HTTPRouteMatching = suite.ConformanceTest{
ns := "gateway-conformance-infra"
routeNN := types.NamespacedName{Name: "matching", Namespace: ns}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, gwNN, routeNN)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

testCases := []http.ExpectedResponse{{
Request: http.ExpectedRequest{Path: "/"},
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/httproute-reference-grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var HTTPRouteReferenceGrant = suite.ConformanceTest{
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
routeNN := types.NamespacedName{Name: "reference-grant", Namespace: "gateway-conformance-infra"}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: "gateway-conformance-infra"}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, s.Client, s.ControllerName, gwNN, routeNN)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, s.Client, s.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

t.Run("Simple HTTP request should reach web-backend", func(t *testing.T) {
http.MakeRequestAndExpectEventuallyConsistentResponse(t, s.RoundTripper, gwAddr, http.ExpectedResponse{
Expand Down
2 changes: 1 addition & 1 deletion conformance/tests/httproute-simple-same-namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var HTTPRouteSimpleSameNamespace = suite.ConformanceTest{
ns := v1alpha2.Namespace("gateway-conformance-infra")
routeNN := types.NamespacedName{Name: "gateway-conformance-infra-test", Namespace: string(ns)}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: string(ns)}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, gwNN, routeNN)
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeReady(t, suite.Client, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

t.Run("Simple HTTP request should reach infra-backend", func(t *testing.T) {
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, gwAddr, http.ExpectedResponse{
Expand Down
66 changes: 49 additions & 17 deletions conformance/utils/kubernetes/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ import (
"sigs.k8s.io/gateway-api/apis/v1alpha2"
)

// GatewayRef is a tiny type for specifying an HTTP Route ParentRef without
// relying on a specific api version.
type GatewayRef struct {
types.NamespacedName
listenerNames []*v1alpha2.SectionName
}

// NewGatewayRef creates a GatewayRef resource. ListenerNames are optional.
func NewGatewayRef(nn types.NamespacedName, listenerNames ...string) GatewayRef {
var listeners []*v1alpha2.SectionName

if len(listenerNames) == 0 {
listenerNames = append(listenerNames, "")
}

for _, listener := range listenerNames {
sectionName := v1alpha2.SectionName(listener)
listeners = append(listeners, &sectionName)
}
return GatewayRef{
NamespacedName: nn,
listenerNames: listeners,
}
}

// GWCMustBeAccepted waits until the specified GatewayClass has an Accepted
// condition set to true. It also returns the ControllerName for the
// GatewayClass. This will cause the test to halt if the specified timeout is
Expand Down Expand Up @@ -110,33 +135,40 @@ func NamespacesMustBeReady(t *testing.T, c client.Client, namespaces []string, s
// address assigned to it and the Route has a ParentRef referring to the
// Gateway. The test will fail if these conditions are not met before the
// timeouts.
func GatewayAndHTTPRoutesMustBeReady(t *testing.T, c client.Client, controllerName string, gwNN types.NamespacedName, routeNNs ...types.NamespacedName) string {
func GatewayAndHTTPRoutesMustBeReady(t *testing.T, c client.Client, controllerName string, gw GatewayRef, routeNNs ...types.NamespacedName) string {
t.Helper()

gwAddr, err := WaitForGatewayAddress(t, c, gwNN, 180)
gwAddr, err := WaitForGatewayAddress(t, c, gw.NamespacedName, 180)
require.NoErrorf(t, err, "timed out waiting for Gateway address to be assigned")

ns := v1alpha2.Namespace(gwNN.Namespace)
ns := v1alpha2.Namespace(gw.Namespace)
kind := v1alpha2.Kind("Gateway")

for _, routeNN := range routeNNs {
namespaceRequired := true
if routeNN.Namespace == gwNN.Namespace {
if routeNN.Namespace == gw.Namespace {
namespaceRequired = false
}
parents := []v1alpha2.RouteParentStatus{{
ParentRef: v1alpha2.ParentReference{
Group: (*v1alpha2.Group)(&v1alpha2.GroupVersion.Group),
Kind: &kind,
Name: v1alpha2.ObjectName(gwNN.Name),
Namespace: &ns,
},
ControllerName: v1alpha2.GatewayController(controllerName),
Conditions: []metav1.Condition{{
Type: string(v1alpha2.RouteConditionAccepted),
Status: metav1.ConditionTrue,
}},
}}

var parents []v1alpha2.RouteParentStatus
for _, listener := range gw.listenerNames {
parents = append(parents, v1alpha2.RouteParentStatus{
ParentRef: v1alpha2.ParentReference{
Group: (*v1alpha2.Group)(&v1alpha2.GroupVersion.Group),
Kind: &kind,
Name: v1alpha2.ObjectName(gw.Name),
Namespace: &ns,
SectionName: listener,
},
ControllerName: v1alpha2.GatewayController(controllerName),
Conditions: []metav1.Condition{
{
Type: string(v1alpha2.RouteConditionAccepted),
Status: metav1.ConditionTrue,
},
},
})
}
HTTPRouteMustHaveParents(t, c, routeNN, parents, namespaceRequired, 60)
}

Expand Down

0 comments on commit 751ccfc

Please sign in to comment.