@@ -27,6 +27,36 @@ import (
27
27
var _ = Describe ("CRD Generation" , func () {
28
28
Describe ("Utilities" , func () {
29
29
Describe ("MergeIdenticalVersionInfo" , func () {
30
+ It ("should replace per-version schemata with a top-level schema if only one version" , func () {
31
+ spec := & apiext.CustomResourceDefinition {
32
+ Spec : apiext.CustomResourceDefinitionSpec {
33
+ Versions : []apiext.CustomResourceDefinitionVersion {
34
+ {
35
+ Name : "v1" ,
36
+ Storage : true ,
37
+ Schema : & apiext.CustomResourceValidation {
38
+ OpenAPIV3Schema : & apiext.JSONSchemaProps {
39
+ Required : []string {"foo" },
40
+ Type : "object" ,
41
+ Properties : map [string ]apiext.JSONSchemaProps {"foo" : apiext.JSONSchemaProps {Type : "string" }},
42
+ },
43
+ },
44
+ },
45
+ },
46
+ },
47
+ }
48
+ crd .MergeIdenticalVersionInfo (spec )
49
+ Expect (spec .Spec .Validation ).To (Equal (& apiext.CustomResourceValidation {
50
+ OpenAPIV3Schema : & apiext.JSONSchemaProps {
51
+ Required : []string {"foo" },
52
+ Type : "object" ,
53
+ Properties : map [string ]apiext.JSONSchemaProps {"foo" : apiext.JSONSchemaProps {Type : "string" }},
54
+ },
55
+ }))
56
+ Expect (spec .Spec .Versions ).To (Equal ([]apiext.CustomResourceDefinitionVersion {
57
+ {Name : "v1" , Storage : true },
58
+ }))
59
+ })
30
60
It ("should replace per-version schemata with a top-level schema if all are identical" , func () {
31
61
spec := & apiext.CustomResourceDefinition {
32
62
Spec : apiext.CustomResourceDefinitionSpec {
@@ -100,6 +130,30 @@ var _ = Describe("CRD Generation", func() {
100
130
Expect (spec ).To (Equal (orig ))
101
131
})
102
132
133
+ It ("should replace per-version subresources with top-level subresources if only one version" , func () {
134
+ spec := & apiext.CustomResourceDefinition {
135
+ Spec : apiext.CustomResourceDefinitionSpec {
136
+ Versions : []apiext.CustomResourceDefinitionVersion {
137
+ {
138
+ Name : "v1" ,
139
+ Storage : true ,
140
+ Subresources : & apiext.CustomResourceSubresources {
141
+ Status : & apiext.CustomResourceSubresourceStatus {},
142
+ },
143
+ },
144
+ },
145
+ },
146
+ }
147
+
148
+ crd .MergeIdenticalVersionInfo (spec )
149
+ Expect (spec .Spec .Subresources ).To (Equal (& apiext.CustomResourceSubresources {
150
+ Status : & apiext.CustomResourceSubresourceStatus {},
151
+ }))
152
+ Expect (spec .Spec .Versions ).To (Equal ([]apiext.CustomResourceDefinitionVersion {
153
+ {Name : "v1" , Storage : true },
154
+ }))
155
+ })
156
+
103
157
It ("should replace per-version subresources with top-level subresources if all are identical" , func () {
104
158
spec := & apiext.CustomResourceDefinition {
105
159
Spec : apiext.CustomResourceDefinitionSpec {
@@ -152,6 +206,32 @@ var _ = Describe("CRD Generation", func() {
152
206
Expect (spec ).To (Equal (orig ))
153
207
})
154
208
209
+ It ("should replace per-version printer columns with top-level printer columns if only one version" , func () {
210
+ spec := & apiext.CustomResourceDefinition {
211
+ Spec : apiext.CustomResourceDefinitionSpec {
212
+ Versions : []apiext.CustomResourceDefinitionVersion {
213
+ {
214
+ Name : "v1" ,
215
+ Storage : true ,
216
+ AdditionalPrinterColumns : []apiext.CustomResourceColumnDefinition {
217
+ {Name : "Cheddar" , JSONPath : ".spec.cheddar" },
218
+ {Name : "Parmesan" , JSONPath : ".status.parmesan" },
219
+ },
220
+ },
221
+ },
222
+ },
223
+ }
224
+
225
+ crd .MergeIdenticalVersionInfo (spec )
226
+ Expect (spec .Spec .AdditionalPrinterColumns ).To (Equal ([]apiext.CustomResourceColumnDefinition {
227
+ {Name : "Cheddar" , JSONPath : ".spec.cheddar" },
228
+ {Name : "Parmesan" , JSONPath : ".status.parmesan" },
229
+ }))
230
+ Expect (spec .Spec .Versions ).To (Equal ([]apiext.CustomResourceDefinitionVersion {
231
+ {Name : "v1" , Storage : true },
232
+ }))
233
+ })
234
+
155
235
It ("should replace per-version printer columns with top-level printer columns if all are identical" , func () {
156
236
spec := & apiext.CustomResourceDefinition {
157
237
Spec : apiext.CustomResourceDefinitionSpec {
0 commit comments