@@ -5,12 +5,18 @@ import (
5
5
"strings"
6
6
7
7
. "github.com/onsi/ginkgo"
8
+ "k8s.io/apimachinery/pkg/runtime"
8
9
"k8s.io/client-go/dynamic"
10
+ kscheme "k8s.io/client-go/kubernetes/scheme"
9
11
"k8s.io/client-go/rest"
10
12
13
+ operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
14
+ operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
15
+ operatorsv2alpha1 "github.com/operator-framework/api/pkg/operators/v2alpha1"
11
16
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
12
17
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
13
18
pversioned "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/versioned"
19
+ controllerclient "sigs.k8s.io/controller-runtime/pkg/client"
14
20
)
15
21
16
22
var ctx TestContext
@@ -23,6 +29,11 @@ type TestContext struct {
23
29
operatorClient versioned.Interface
24
30
dynamicClient dynamic.Interface
25
31
packageClient pversioned.Interface
32
+
33
+ scheme * runtime.Scheme
34
+
35
+ // client is the controller-runtime client -- we should use this from now on
36
+ client controllerclient.Client
26
37
}
27
38
28
39
// Ctx returns a pointer to the global test context. During parallel
@@ -40,6 +51,10 @@ func (ctx TestContext) Logf(f string, v ...interface{}) {
40
51
fmt .Fprintf (GinkgoWriter , f , v ... )
41
52
}
42
53
54
+ func (ctx TestContext ) Scheme () * runtime.Scheme {
55
+ return ctx .scheme
56
+ }
57
+
43
58
func (ctx TestContext ) RESTConfig () * rest.Config {
44
59
return ctx .restConfig
45
60
}
@@ -60,6 +75,10 @@ func (ctx TestContext) PackageClient() pversioned.Interface {
60
75
return ctx .packageClient
61
76
}
62
77
78
+ func (ctx TestContext ) Client () controllerclient.Client {
79
+ return ctx .client
80
+ }
81
+
63
82
func setDerivedFields (ctx * TestContext ) error {
64
83
if ctx == nil {
65
84
return fmt .Errorf ("nil test context" )
@@ -93,5 +112,24 @@ func setDerivedFields(ctx *TestContext) error {
93
112
}
94
113
ctx .packageClient = packageClient
95
114
115
+ ctx .scheme = runtime .NewScheme ()
116
+ localSchemeBuilder := runtime .NewSchemeBuilder (
117
+ kscheme .AddToScheme ,
118
+ operatorsv1alpha1 .AddToScheme ,
119
+ operatorsv1 .AddToScheme ,
120
+ operatorsv2alpha1 .AddToScheme ,
121
+ )
122
+ if err := localSchemeBuilder .AddToScheme (ctx .scheme ); err != nil {
123
+ return err
124
+ }
125
+
126
+ client , err := controllerclient .New (ctx .restConfig , controllerclient.Options {
127
+ Scheme : ctx .scheme ,
128
+ })
129
+ if err != nil {
130
+ return err
131
+ }
132
+ ctx .client = client
133
+
96
134
return nil
97
135
}
0 commit comments