1
1
package cel
2
2
3
3
import (
4
+ "testing"
5
+
4
6
"k8s.io/apimachinery/pkg/runtime"
5
7
controllerruntime "sigs.k8s.io/controller-runtime"
6
8
"sigs.k8s.io/controller-runtime/pkg/client"
7
9
8
10
ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
11
+ ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha2"
12
+ )
13
+
14
+ const (
15
+ GatewayKind = "Gateway"
16
+ HTTPRouteKind = "HTTPRoute"
17
+ GRPCRouteKind = "GRPCRoute"
18
+ TCPRouteKind = "TCPRoute"
19
+ InvalidKind = "InvalidKind"
20
+ )
21
+
22
+ const (
23
+ GatewayGroup = "gateway.networking.k8s.io"
24
+ InvalidGroup = "invalid.networking.k8s.io"
25
+ DiscoveryGroup = "discovery.k8s.io/v1"
26
+ )
27
+
28
+ const (
29
+ ExpectedTargetRefKindError = `TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute`
30
+ ExpectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io.`
31
+ )
32
+
33
+ const (
34
+ PolicyName = "test-policy"
35
+ TargetRef = "targetRef-name"
9
36
)
10
37
11
38
// GetKubernetesClient returns a client connected to a real Kubernetes cluster.
12
- func GetKubernetesClient () (k8sClient client.Client , err error ) {
39
+ func GetKubernetesClient (t * testing.T ) (k8sClient client.Client , err error ) {
40
+ t .Helper ()
13
41
// Use controller-runtime to get cluster connection
14
42
k8sConfig , err := controllerruntime .GetConfig ()
15
43
if err != nil {
@@ -21,6 +49,9 @@ func GetKubernetesClient() (k8sClient client.Client, err error) {
21
49
if err = ngfAPIv1alpha1 .AddToScheme (scheme ); err != nil {
22
50
return nil , err
23
51
}
52
+ if err = ngfAPIv1alpha2 .AddToScheme (scheme ); err != nil {
53
+ return nil , err
54
+ }
24
55
// Create a new client with the scheme and return it
25
56
return client .New (k8sConfig , client.Options {Scheme : scheme })
26
57
}
0 commit comments