Skip to content

Commit

Permalink
conformance: initial UDPRoute test (#2661)
Browse files Browse the repository at this point in the history
* conformance: initial UDPRoute test

Signed-off-by: Karol Szwaj <[email protected]>

* go.mod

Signed-off-by: Karol Szwaj <[email protected]>

* reuse function for route checking

Signed-off-by: Karol Szwaj <[email protected]>

* fix path

Signed-off-by: Karol Szwaj <[email protected]>

* add features

Signed-off-by: Karol Szwaj <[email protected]>

* add type for routeHandlerFunc

Signed-off-by: Karol Szwaj <[email protected]>

* fix goimports

Signed-off-by: Karol Szwaj <[email protected]>

* rebase: use funcs from grpcroute tests

Signed-off-by: Karol Szwaj <[email protected]>

---------

Signed-off-by: Karol Szwaj <[email protected]>
  • Loading branch information
cnvergence authored Mar 22, 2024
1 parent 50091d0 commit 729d38f
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 0 deletions.
78 changes: 78 additions & 0 deletions conformance/base/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -654,3 +654,81 @@ spec:
resources:
requests:
cpu: 10m
---
apiVersion: v1
kind: Service
metadata:
name: coredns
namespace: gateway-conformance-infra
labels:
app: udp
spec:
ports:
- name: udp-dns
port: 53
protocol: UDP
targetPort: 53
selector:
app: udp
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: coredns
namespace: gateway-conformance-infra
labels:
app: udp
spec:
selector:
matchLabels:
app: udp
template:
metadata:
labels:
app: udp
spec:
containers:
- args:
- -conf
- /root/Corefile
image: coredns/coredns
name: coredns
volumeMounts:
- mountPath: /root
name: conf
volumes:
- configMap:
defaultMode: 420
name: coredns
name: conf
---
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: gateway-conformance-infra
data:
Corefile: |
.:53 {
forward . 8.8.8.8 9.9.9.9
log
errors
}
foo.bar.com:53 {
whoami
}
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: udp-gateway
namespace: gateway-conformance-infra
spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
listeners:
- name: coredns
protocol: UDP
port: 5300
allowedRoutes:
kinds:
- kind: UDPRoute
69 changes: 69 additions & 0 deletions conformance/tests/udproute-simple.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tests

import (
"context"
"testing"
"time"

"github.com/miekg/dns"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"

"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, UDPRouteTest)
}

var UDPRouteTest = suite.ConformanceTest{
ShortName: "UDPRoute",
Description: "Make sure UDPRoute is working",
Manifests: []string{"tests/udproute-simple.yaml"},
Features: []suite.SupportedFeature{
suite.SupportGateway,
suite.SupportUDPRoute,
},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
t.Run("Simple UDP request matching UDPRoute should reach coredns backend", func(t *testing.T) {
namespace := "gateway-conformance-infra"
domain := "foo.bar.com."
routeNN := types.NamespacedName{Name: "udp-coredns", Namespace: namespace}
gwNN := types.NamespacedName{Name: "udp-gateway", Namespace: namespace}
gwAddr := kubernetes.GatewayAndUDPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

msg := new(dns.Msg)
msg.SetQuestion(domain, dns.TypeA)

if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, true,
func(_ context.Context) (done bool, err error) {
t.Logf("performing DNS query %s on %s", domain, gwAddr)
_, err = dns.Exchange(msg, gwAddr)
if err != nil {
t.Logf("failed to perform a UDP query: %v", err)
return false, nil
}
return true, nil
}); err != nil {
t.Errorf("failed to perform DNS query: %v", err)
}
})
},
}
13 changes: 13 additions & 0 deletions conformance/tests/udproute-simple.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: UDPRoute
metadata:
name: udp-coredns
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: udp-gateway
sectionName: coredns
rules:
- backendRefs:
- name: coredns
port: 53
15 changes: 15 additions & 0 deletions conformance/utils/kubernetes/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,14 @@ func GatewayAndHTTPRoutesMustBeAccepted(t *testing.T, c client.Client, timeoutCo
return GatewayAndRoutesMustBeAccepted(t, c, timeoutConfig, controllerName, gw, &gatewayv1.HTTPRoute{}, routeNNs...)
}

// GatewayAndUDPRoutesMustBeAccepted waits until the specified Gateway has an IP
// address assigned to it and the UDPRoute has a ParentRef referring to the
// Gateway. The test will fail if these conditions are not met before the
// timeouts.
func GatewayAndUDPRoutesMustBeAccepted(t *testing.T, c client.Client, timeoutConfig config.TimeoutConfig, controllerName string, gw GatewayRef, routeNNs ...types.NamespacedName) string {
return GatewayAndRoutesMustBeAccepted(t, c, timeoutConfig, controllerName, gw, &v1alpha2.UDPRoute{}, routeNNs...)
}

// WaitForGatewayAddress waits until at least one IP Address has been set in the
// status of the specified Gateway.
func WaitForGatewayAddress(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, gwName types.NamespacedName) (string, error) {
Expand Down Expand Up @@ -599,6 +607,13 @@ func HTTPRouteMustHaveParents(t *testing.T, client client.Client, timeoutConfig
RouteMustHaveParents(t, client, timeoutConfig, routeName, parents, namespaceRequired, &gatewayv1.HTTPRoute{})
}

// UDPRouteMustHaveParents waits for the specified UDPRoute to have parents
// in status that match the expected parents. This will cause the test to halt
// if the specified timeout is exceeded.
func UDPRouteMustHaveParents(t *testing.T, client client.Client, timeoutConfig config.TimeoutConfig, routeName types.NamespacedName, parents []gatewayv1.RouteParentStatus, namespaceRequired bool) {
RouteMustHaveParents(t, client, timeoutConfig, routeName, parents, namespaceRequired, &v1alpha2.UDPRoute{})
}

// TLSRouteMustHaveParents waits for the specified TLSRoute to have parents
// in status that match the expected parents, and also returns the TLSRoute.
// This will cause the test to halt if the specified timeout is exceeded.
Expand Down
15 changes: 15 additions & 0 deletions conformance/utils/suite/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ var TLSRouteCoreFeatures = sets.New(
SupportTLSRoute,
)

// -----------------------------------------------------------------------------
// Features - UDPRoute Conformance (Core)
// -----------------------------------------------------------------------------

const (
// This option indicates support for UDPRoute
SupportUDPRoute SupportedFeature = "UDPRoute"
)

// UDPRouteCoreFeatures includes all SupportedFeatures needed to be conformant with
// the UDPRoute resource.
var UDPRouteFeatures = sets.New(
SupportUDPRoute,
)

// -----------------------------------------------------------------------------
// Features - Mesh Conformance (Core)
// -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/ahmetb/gen-crd-api-reference-docs v0.3.0
github.com/miekg/dns v1.1.57
github.com/stretchr/testify v1.9.0
golang.org/x/net v0.20.0
google.golang.org/grpc v1.61.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM=
github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down

0 comments on commit 729d38f

Please sign in to comment.