@@ -69,7 +69,7 @@ func Test_CRDMigrator(t *testing.T) {
69
69
wantIsMigrated : false ,
70
70
},
71
71
{
72
- name : "No-op if new CRD supports same versions " ,
72
+ name : "No-op if new CRD uses the same storage version " ,
73
73
currentCRD : & apiextensionsv1.CustomResourceDefinition {
74
74
ObjectMeta : metav1.ObjectMeta {Name : "foo" },
75
75
Spec : apiextensionsv1.CustomResourceDefinitionSpec {
@@ -90,7 +90,7 @@ func Test_CRDMigrator(t *testing.T) {
90
90
wantIsMigrated : false ,
91
91
},
92
92
{
93
- name : "No-op if new CRD adds a new versions" ,
93
+ name : "No-op if new CRD adds a new versions and stored versions is only the old storage version " ,
94
94
currentCRD : & apiextensionsv1.CustomResourceDefinition {
95
95
ObjectMeta : metav1.ObjectMeta {Name : "foo" },
96
96
Spec : apiextensionsv1.CustomResourceDefinitionSpec {
@@ -104,30 +104,8 @@ func Test_CRDMigrator(t *testing.T) {
104
104
ObjectMeta : metav1.ObjectMeta {Name : "foo" },
105
105
Spec : apiextensionsv1.CustomResourceDefinitionSpec {
106
106
Versions : []apiextensionsv1.CustomResourceDefinitionVersion {
107
- {Name : "v1beta1" , Storage : true , Served : true }, // v1beta1 is being added
108
- {Name : "v1alpha1" , Served : true }, // v1alpha1 still exists
109
- },
110
- },
111
- },
112
- wantIsMigrated : false ,
113
- },
114
- {
115
- name : "No-op if new CRD adds a new versions and unserves the old" ,
116
- currentCRD : & apiextensionsv1.CustomResourceDefinition {
117
- ObjectMeta : metav1.ObjectMeta {Name : "foo" },
118
- Spec : apiextensionsv1.CustomResourceDefinitionSpec {
119
- Versions : []apiextensionsv1.CustomResourceDefinitionVersion {
120
- {Name : "v1alpha1" , Storage : true , Served : true },
121
- },
122
- },
123
- Status : apiextensionsv1.CustomResourceDefinitionStatus {StoredVersions : []string {"v1alpha1" }},
124
- },
125
- newCRD : & apiextensionsv1.CustomResourceDefinition {
126
- ObjectMeta : metav1.ObjectMeta {Name : "foo" },
127
- Spec : apiextensionsv1.CustomResourceDefinitionSpec {
128
- Versions : []apiextensionsv1.CustomResourceDefinitionVersion {
129
- {Name : "v1beta1" , Storage : true , Served : true }, // v1beta1 is being added
130
- {Name : "v1alpha1" , Served : false }, // v1alpha1 still exists but is not served anymore
107
+ {Name : "v1beta1" , Storage : true , Served : false }, // v1beta1 is being added
108
+ {Name : "v1alpha1" , Served : true }, // v1alpha1 still exists
131
109
},
132
110
},
133
111
},
@@ -155,7 +133,7 @@ func Test_CRDMigrator(t *testing.T) {
155
133
wantErr : true ,
156
134
},
157
135
{
158
- name : "Migrate CRs if their storage version is removed from the CRD " ,
136
+ name : "Migrate CRs if there are stored versions is not only the current storage version " ,
159
137
CRs : []unstructured.Unstructured {
160
138
{
161
139
Object : map [string ]interface {}{
@@ -215,67 +193,6 @@ func Test_CRDMigrator(t *testing.T) {
215
193
wantStoredVersions : []string {"v1beta1" }, // v1alpha1 should be dropped from current CRD's stored versions
216
194
wantIsMigrated : true ,
217
195
},
218
- {
219
- name : "Migrate the CR if their storage version is no longer served by the CRD" ,
220
- CRs : []unstructured.Unstructured {
221
- {
222
- Object : map [string ]interface {}{
223
- "apiVersion" : "foo/v1beta1" ,
224
- "kind" : "Foo" ,
225
- "metadata" : map [string ]interface {}{
226
- "name" : "cr1" ,
227
- "namespace" : metav1 .NamespaceDefault ,
228
- },
229
- },
230
- },
231
- {
232
- Object : map [string ]interface {}{
233
- "apiVersion" : "foo/v1beta1" ,
234
- "kind" : "Foo" ,
235
- "metadata" : map [string ]interface {}{
236
- "name" : "cr2" ,
237
- "namespace" : metav1 .NamespaceDefault ,
238
- },
239
- },
240
- },
241
- {
242
- Object : map [string ]interface {}{
243
- "apiVersion" : "foo/v1beta1" ,
244
- "kind" : "Foo" ,
245
- "metadata" : map [string ]interface {}{
246
- "name" : "cr3" ,
247
- "namespace" : metav1 .NamespaceDefault ,
248
- },
249
- },
250
- },
251
- },
252
- currentCRD : & apiextensionsv1.CustomResourceDefinition {
253
- ObjectMeta : metav1.ObjectMeta {Name : "foo" },
254
- Spec : apiextensionsv1.CustomResourceDefinitionSpec {
255
- Group : "foo" ,
256
- Names : apiextensionsv1.CustomResourceDefinitionNames {Kind : "Foo" , ListKind : "FooList" },
257
- Versions : []apiextensionsv1.CustomResourceDefinitionVersion {
258
- {Name : "v1beta1" , Storage : true , Served : true },
259
- {Name : "v1alpha1" , Served : true },
260
- },
261
- },
262
- Status : apiextensionsv1.CustomResourceDefinitionStatus {StoredVersions : []string {"v1beta1" , "v1alpha1" }},
263
- },
264
- newCRD : & apiextensionsv1.CustomResourceDefinition {
265
- ObjectMeta : metav1.ObjectMeta {Name : "foo" },
266
- Spec : apiextensionsv1.CustomResourceDefinitionSpec {
267
- Group : "foo" ,
268
- Names : apiextensionsv1.CustomResourceDefinitionNames {Kind : "Foo" , ListKind : "FooList" },
269
- Versions : []apiextensionsv1.CustomResourceDefinitionVersion {
270
- {Name : "v1" , Storage : true , Served : true }, // v1 is being added
271
- {Name : "v1beta1" , Served : true }, // v1beta1 still there (required for future migration)
272
- {Name : "v1alpha1" , Served : false }, // v1alpha1 is no longer being served
273
- },
274
- },
275
- },
276
- wantStoredVersions : []string {"v1beta1" }, // v1alpha1 should be dropped from current CRD's stored versions
277
- wantIsMigrated : true ,
278
- },
279
196
}
280
197
for _ , tt := range tests {
281
198
t .Run (tt .name , func (t * testing.T ) {
0 commit comments