@@ -22,6 +22,8 @@ import (
22
22
appsv1 "k8s.io/api/apps/v1"
23
23
corev1 "k8s.io/api/core/v1"
24
24
rbacv1 "k8s.io/api/rbac/v1"
25
+ apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
26
+ apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
25
27
26
28
"github.com/operator-framework/operator-sdk/internal/generate/collector"
27
29
)
@@ -93,6 +95,141 @@ var _ = Describe("apply functions", func() {
93
95
})
94
96
})
95
97
98
+ var _ = Describe ("applyCustomResourceDefinitions" , func () {
99
+ var c * collector.Manifests
100
+
101
+ csv := operatorsv1alpha1.ClusterServiceVersion {
102
+ Spec : operatorsv1alpha1.ClusterServiceVersionSpec {
103
+ CustomResourceDefinitions : operatorsv1alpha1.CustomResourceDefinitions {
104
+ Owned : []operatorsv1alpha1.CRDDescription {
105
+ {
106
+ Name : "test1" ,
107
+ Version : "v1" ,
108
+ Kind : "Memcached" ,
109
+ },
110
+ {
111
+ Name : "test1" ,
112
+ Version : "v1beta1" ,
113
+ Kind : "Memcached" ,
114
+ },
115
+ },
116
+ },
117
+ },
118
+ }
119
+
120
+ It ("should add all CRDs present in collector and specified in CSV" , func () {
121
+ c = & collector.Manifests {}
122
+ crd1 := apiextv1.CustomResourceDefinition {
123
+ Spec : apiextv1.CustomResourceDefinitionSpec {
124
+ Group : "Test" ,
125
+ Names : apiextv1.CustomResourceDefinitionNames {
126
+ Kind : "Memcached" ,
127
+ },
128
+ Versions : []apiextv1.CustomResourceDefinitionVersion {
129
+ {
130
+ Name : "v1" ,
131
+ Served : true ,
132
+ },
133
+ {
134
+ Name : "v1beta1" ,
135
+ Served : true ,
136
+ },
137
+ },
138
+ }}
139
+ crd1 .SetName ("test1" )
140
+
141
+ c .V1CustomResourceDefinitions = []apiextv1.CustomResourceDefinition {crd1 }
142
+
143
+ applyCustomResourceDefinitions (c , & csv )
144
+
145
+ By ("test if csv has the required owned crds applied" )
146
+ ownedDes := csv .Spec .CustomResourceDefinitions .Owned
147
+ Expect (len (ownedDes )).To (BeEquivalentTo (2 ))
148
+ Expect (ownedDes ).To (ContainElements (operatorsv1alpha1.CRDDescription {
149
+ Name : "test1" ,
150
+ Version : "v1" ,
151
+ Kind : "Memcached" ,
152
+ }, operatorsv1alpha1.CRDDescription {
153
+ Name : "test1" ,
154
+ Version : "v1beta1" ,
155
+ Kind : "Memcached" ,
156
+ }))
157
+ })
158
+
159
+ It ("should not add unserved v1CRDs" , func () {
160
+ c = & collector.Manifests {}
161
+ crd1 := apiextv1.CustomResourceDefinition {
162
+ Spec : apiextv1.CustomResourceDefinitionSpec {
163
+ Group : "Test" ,
164
+ Names : apiextv1.CustomResourceDefinitionNames {
165
+ Kind : "Memcached" ,
166
+ },
167
+ Versions : []apiextv1.CustomResourceDefinitionVersion {
168
+ {
169
+ Name : "v1" ,
170
+ Served : true ,
171
+ },
172
+ {
173
+ Name : "v1beta1" ,
174
+ Served : false ,
175
+ },
176
+ },
177
+ }}
178
+ crd1 .SetName ("test1" )
179
+
180
+ c .V1CustomResourceDefinitions = []apiextv1.CustomResourceDefinition {crd1 }
181
+
182
+ applyCustomResourceDefinitions (c , & csv )
183
+
184
+ By ("test if deprecated crds are not added" )
185
+ ownedDes := csv .Spec .CustomResourceDefinitions .Owned
186
+ Expect (len (ownedDes )).To (BeEquivalentTo (1 ))
187
+ Expect (ownedDes ).To (ContainElement (operatorsv1alpha1.CRDDescription {
188
+ Name : "test1" ,
189
+ Version : "v1" ,
190
+ Kind : "Memcached" ,
191
+ }))
192
+ })
193
+
194
+ It ("should not add unserved v1beta1CRDs" , func () {
195
+ c = & collector.Manifests {}
196
+
197
+ crd1 := apiextv1beta1.CustomResourceDefinition {
198
+ Spec : apiextv1beta1.CustomResourceDefinitionSpec {
199
+ Group : "Test" ,
200
+ Names : apiextv1beta1.CustomResourceDefinitionNames {
201
+ Kind : "Memcached" ,
202
+ },
203
+ Versions : []apiextv1beta1.CustomResourceDefinitionVersion {
204
+ {
205
+ Name : "v2" ,
206
+ Served : true ,
207
+ },
208
+ {
209
+ Name : "v1beta1" ,
210
+ Served : false ,
211
+ },
212
+ },
213
+ },
214
+ }
215
+
216
+ crd1 .SetName ("test1" )
217
+
218
+ c .V1beta1CustomResourceDefinitions = []apiextv1beta1.CustomResourceDefinition {crd1 }
219
+
220
+ applyCustomResourceDefinitions (c , & csv )
221
+
222
+ By ("test if deprecated crds are not added" )
223
+ ownedDes := csv .Spec .CustomResourceDefinitions .Owned
224
+ Expect (len (ownedDes )).To (BeEquivalentTo (1 ))
225
+ Expect (ownedDes ).To (ContainElement (operatorsv1alpha1.CRDDescription {
226
+ Name : "test1" ,
227
+ Version : "v2" ,
228
+ Kind : "Memcached" ,
229
+ }))
230
+ })
231
+ })
232
+
96
233
var _ = Describe ("findMatchingDeploymentAndServiceForWebhook" , func () {
97
234
98
235
var (
0 commit comments