@@ -21,7 +21,10 @@ import (
21
21
. "github.com/onsi/gomega"
22
22
v1 "github.com/operator-framework/api/pkg/operators/v1"
23
23
"github.com/operator-framework/api/pkg/operators/v1alpha1"
24
+ corev1 "k8s.io/api/core/v1"
25
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
26
"k8s.io/apimachinery/pkg/runtime"
27
+ "k8s.io/apimachinery/pkg/types"
25
28
"k8s.io/apimachinery/pkg/util/sets"
26
29
crclient "sigs.k8s.io/controller-runtime/pkg/client"
27
30
"sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -30,8 +33,167 @@ import (
30
33
)
31
34
32
35
var _ = Describe ("OperatorInstaller" , func () {
33
- Describe ("InstallOperator" , func () {
34
- // TODO: fill this in once run bundle is done
36
+ Describe ("NewOperatorInstaller" , func () {
37
+ It ("should create an OperatorInstaller" , func () {
38
+ cfg := & operator.Configuration {}
39
+ oi := NewOperatorInstaller (cfg )
40
+ Expect (oi ).ToNot (BeNil ())
41
+ })
42
+ })
43
+
44
+ Describe ("createSubscription" , func () {
45
+ var (
46
+ oi * OperatorInstaller
47
+ sch * runtime.Scheme
48
+ )
49
+ BeforeEach (func () {
50
+ // Setup and fake client
51
+ cfg := & operator.Configuration {}
52
+ sch = runtime .NewScheme ()
53
+ Expect (v1 .AddToScheme (sch )).To (Succeed ())
54
+ Expect (v1alpha1 .AddToScheme (sch )).To (Succeed ())
55
+ cfg .Client = fake .NewFakeClientWithScheme (sch )
56
+
57
+ oi = NewOperatorInstaller (cfg )
58
+ oi .StartingCSV = "fakeName"
59
+ oi .cfg .Namespace = "fakeNS"
60
+ })
61
+
62
+ It ("should create the subscription with the fake client" , func () {
63
+ sub , err := oi .createSubscription (context .TODO (), "huzzah" )
64
+ Expect (err ).ToNot (HaveOccurred ())
65
+
66
+ retSub := & v1alpha1.Subscription {}
67
+ subKey := types.NamespacedName {
68
+ Namespace : sub .GetNamespace (),
69
+ Name : sub .GetName (),
70
+ }
71
+ err = oi .cfg .Client .Get (context .TODO (), subKey , retSub )
72
+ Expect (err ).ToNot (HaveOccurred ())
73
+ Expect (retSub .GetName ()).To (Equal (sub .GetName ()))
74
+ Expect (retSub .GetNamespace ()).To (Equal (sub .GetNamespace ()))
75
+ })
76
+
77
+ It ("should pass through any client errors (duplicate)" , func () {
78
+
79
+ sub := newSubscription (oi .StartingCSV , oi .cfg .Namespace , withCatalogSource ("duplicate" , oi .cfg .Namespace ))
80
+ oi .cfg .Client = fake .NewFakeClientWithScheme (sch , sub )
81
+
82
+ _ , err := oi .createSubscription (context .TODO (), "duplicate" )
83
+ Expect (err ).To (HaveOccurred ())
84
+ Expect (err .Error ()).Should (ContainSubstring ("error creating subscription" ))
85
+ })
86
+ })
87
+
88
+ Describe ("approveInstallPlan" , func () {
89
+ var (
90
+ oi * OperatorInstaller
91
+ sch * runtime.Scheme
92
+ )
93
+ BeforeEach (func () {
94
+ cfg := & operator.Configuration {}
95
+ sch = runtime .NewScheme ()
96
+ Expect (v1alpha1 .AddToScheme (sch )).To (Succeed ())
97
+ oi = NewOperatorInstaller (cfg )
98
+ })
99
+
100
+ It ("should update the install plan" , func () {
101
+ oi .cfg .Client = fake .NewFakeClientWithScheme (sch ,
102
+ & v1alpha1.InstallPlan {
103
+ ObjectMeta : metav1.ObjectMeta {
104
+ Name : "fakeName" ,
105
+ Namespace : "fakeNS" ,
106
+ },
107
+ },
108
+ )
109
+
110
+ ip := & v1alpha1.InstallPlan {}
111
+ ipKey := types.NamespacedName {
112
+ Namespace : "fakeNS" ,
113
+ Name : "fakeName" ,
114
+ }
115
+
116
+ err := oi .cfg .Client .Get (context .TODO (), ipKey , ip )
117
+ Expect (err ).ToNot (HaveOccurred ())
118
+ Expect (ip .Name ).To (Equal ("fakeName" ))
119
+ Expect (ip .Namespace ).To (Equal ("fakeNS" ))
120
+
121
+ // Test
122
+ sub := & v1alpha1.Subscription {
123
+ Status : v1alpha1.SubscriptionStatus {
124
+ InstallPlanRef : & corev1.ObjectReference {
125
+ Name : "fakeName" ,
126
+ Namespace : "fakeNS" ,
127
+ },
128
+ },
129
+ }
130
+ err = oi .approveInstallPlan (context .TODO (), sub )
131
+ Expect (err ).ToNot (HaveOccurred ())
132
+ err = oi .cfg .Client .Get (context .TODO (), ipKey , ip )
133
+ Expect (err ).ToNot (HaveOccurred ())
134
+ Expect (ip .Name ).To (Equal ("fakeName" ))
135
+ Expect (ip .Namespace ).To (Equal ("fakeNS" ))
136
+ Expect (ip .Spec .Approved ).To (Equal (true ))
137
+ })
138
+ It ("should return an error if the install plan does not exist." , func () {
139
+ oi .cfg .Client = fake .NewFakeClientWithScheme (sch )
140
+ sub := & v1alpha1.Subscription {
141
+ Status : v1alpha1.SubscriptionStatus {
142
+ InstallPlanRef : & corev1.ObjectReference {
143
+ Name : "fakeName" ,
144
+ Namespace : "fakeNS" ,
145
+ },
146
+ },
147
+ }
148
+ err := oi .approveInstallPlan (context .TODO (), sub )
149
+ Expect (err ).To (HaveOccurred ())
150
+ Expect (err .Error ()).Should (ContainSubstring ("error getting install plan" ))
151
+ })
152
+ })
153
+
154
+ Describe ("waitForInstallPlan" , func () {
155
+ var (
156
+ oi * OperatorInstaller
157
+ sch * runtime.Scheme
158
+ )
159
+ BeforeEach (func () {
160
+ // Setup and fake client
161
+ cfg := & operator.Configuration {}
162
+ sch = runtime .NewScheme ()
163
+ Expect (v1alpha1 .AddToScheme (sch )).To (Succeed ())
164
+ cfg .Client = fake .NewFakeClientWithScheme (sch )
165
+
166
+ oi = NewOperatorInstaller (cfg )
167
+ oi .StartingCSV = "fakeName"
168
+ oi .cfg .Namespace = "fakeNS"
169
+ })
170
+ It ("should return an error if the subscription does not exist." , func () {
171
+ sub := newSubscription (oi .StartingCSV , oi .cfg .Namespace , withCatalogSource ("duplicate" , oi .cfg .Namespace ))
172
+
173
+ err := oi .waitForInstallPlan (context .TODO (), sub )
174
+ Expect (err ).To (HaveOccurred ())
175
+ Expect (err .Error ()).Should (ContainSubstring ("install plan is not available for the subscription" ))
176
+
177
+ })
178
+ It ("should return if subscription has an install plan." , func () {
179
+ sub := & v1alpha1.Subscription {
180
+ ObjectMeta : metav1.ObjectMeta {
181
+ Name : "fakeName" ,
182
+ Namespace : "fakeNS" ,
183
+ },
184
+ Status : v1alpha1.SubscriptionStatus {
185
+ InstallPlanRef : & corev1.ObjectReference {
186
+ Name : "fakeName" ,
187
+ Namespace : "fakeNS" ,
188
+ },
189
+ },
190
+ }
191
+ err := oi .cfg .Client .Create (context .TODO (), sub )
192
+ Expect (err ).ToNot (HaveOccurred ())
193
+
194
+ err = oi .waitForInstallPlan (context .TODO (), sub )
195
+ Expect (err ).ToNot (HaveOccurred ())
196
+ })
35
197
})
36
198
37
199
Describe ("ensureOperatorGroup" , func () {
@@ -212,7 +374,6 @@ var _ = Describe("OperatorInstaller", func() {
212
374
})
213
375
})
214
376
})
215
-
216
377
Describe ("createOperatorGroup" , func () {
217
378
var (
218
379
oi OperatorInstaller
@@ -335,10 +496,6 @@ var _ = Describe("OperatorInstaller", func() {
335
496
})
336
497
})
337
498
338
- Describe ("createSubscription" , func () {
339
- // TODO: add them as part of a different story
340
- })
341
-
342
499
Describe ("getTargetNamespaces" , func () {
343
500
var (
344
501
oi OperatorInstaller
0 commit comments