@@ -72,27 +72,34 @@ func Test_GetRemovedAPIsOn1_25From(t *testing.T) {
72
72
mock ["HorizontalPodAutoscaler" ] = []string {"memcached-operator-hpa" }
73
73
mock ["PodDisruptionBudget" ] = []string {"memcached-operator-policy-manager" }
74
74
75
+ warnMock := make (map [string ][]string )
76
+ warnMock ["cronjobs" ] = []string {"ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.ClusterPermissions[0].Rules[7]" }
77
+ warnMock ["events" ] = []string {"ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.Permissions[0].Rules[2]" }
78
+
75
79
type args struct {
76
80
bundleDir string
77
81
}
78
82
tests := []struct {
79
- name string
80
- args args
81
- want map [string ][]string
83
+ name string
84
+ args args
85
+ errWant map [string ][]string
86
+ warnWant map [string ][]string
82
87
}{
83
88
{
84
89
name : "should return an empty map when no deprecated apis are found" ,
85
90
args : args {
86
91
bundleDir : "./testdata/valid_bundle_v1" ,
87
92
},
88
- want : map [string ][]string {},
93
+ errWant : map [string ][]string {},
94
+ warnWant : map [string ][]string {},
89
95
},
90
96
{
91
97
name : "should fail return the removed APIs in 1.25" ,
92
98
args : args {
93
99
bundleDir : "./testdata/removed_api_1_25" ,
94
100
},
95
- want : mock ,
101
+ errWant : mock ,
102
+ warnWant : warnMock ,
96
103
},
97
104
}
98
105
for _ , tt := range tests {
@@ -102,8 +109,14 @@ func Test_GetRemovedAPIsOn1_25From(t *testing.T) {
102
109
bundle , err := manifests .GetBundleFromDir (tt .args .bundleDir )
103
110
require .NoError (t , err )
104
111
105
- if got := getRemovedAPIsOn1_25From (bundle ); ! reflect .DeepEqual (got , tt .want ) {
106
- t .Errorf ("getRemovedAPIsOn1_25From() = %v, want %v" , got , tt .want )
112
+ errGot , warnGot := getRemovedAPIsOn1_25From (bundle )
113
+
114
+ if ! reflect .DeepEqual (errGot , tt .errWant ) {
115
+ t .Errorf ("getRemovedAPIsOn1_25From() = %v, want %v" , errGot , tt .errWant )
116
+ }
117
+
118
+ if ! reflect .DeepEqual (warnGot , tt .warnWant ) {
119
+ t .Errorf ("getRemovedAPIsOn1_25From() = %v, want %v" , warnGot , tt .warnWant )
107
120
}
108
121
})
109
122
}
@@ -175,7 +188,11 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
175
188
warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.22. " +
176
189
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
177
190
"Migrate the API(s) for CRD: ([\" etcdbackups.etcd.database.coreos.com\" " +
178
- "\" etcdclusters.etcd.database.coreos.com\" \" etcdrestores.etcd.database.coreos.com\" ])" },
191
+ "\" etcdclusters.etcd.database.coreos.com\" \" etcdrestores.etcd.database.coreos.com\" ])" ,
192
+ "this bundle is using APIs which were deprecated and removed in v1.25. " +
193
+ "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
194
+ "Migrate the API(s) for events: " +
195
+ "([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.Permissions[0].Rules[1]\" ])" },
179
196
},
180
197
{
181
198
name : "should return an error when the k8sVersion is >= 1.22 and has the deprecated API" ,
@@ -189,6 +206,11 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
189
206
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
190
207
"Migrate the API(s) for CRD: ([\" etcdbackups.etcd.database.coreos.com\" " +
191
208
" \" etcdclusters.etcd.database.coreos.com\" \" etcdrestores.etcd.database.coreos.com\" ])" },
209
+ wantWarning : true ,
210
+ warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.25. " +
211
+ "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
212
+ "Migrate the API(s) for events: " +
213
+ "([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.Permissions[0].Rules[1]\" ])" },
192
214
},
193
215
{
194
216
name : "should return an error when the k8sVersion is >= 1.25 and found removed APIs on 1.25" ,
@@ -202,6 +224,12 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
202
224
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
203
225
"Migrate the API(s) for HorizontalPodAutoscaler: ([\" memcached-operator-hpa\" ])," +
204
226
"PodDisruptionBudget: ([\" memcached-operator-policy-manager\" ])," },
227
+ wantWarning : true ,
228
+ warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.25. " +
229
+ "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
230
+ "Migrate the API(s) for cronjobs: " +
231
+ "([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.ClusterPermissions[0].Rules[7]\" ])" +
232
+ ",events: ([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.Permissions[0].Rules[2]\" ])," },
205
233
},
206
234
{
207
235
name : "should return a warning if the k8sVersion is empty and found removed APIs on 1.25" ,
@@ -214,7 +242,12 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
214
242
warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.25. " +
215
243
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
216
244
"Migrate the API(s) for HorizontalPodAutoscaler: ([\" memcached-operator-hpa\" ])," +
217
- "PodDisruptionBudget: ([\" memcached-operator-policy-manager\" ])," },
245
+ "PodDisruptionBudget: ([\" memcached-operator-policy-manager\" ])," ,
246
+ "this bundle is using APIs which were deprecated and removed in v1.25. " +
247
+ "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
248
+ "Migrate the API(s) for cronjobs: " +
249
+ "([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.ClusterPermissions[0].Rules[7]\" ])" +
250
+ ",events: ([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.Permissions[0].Rules[2]\" ])," },
218
251
},
219
252
{
220
253
name : "should return an error when the k8sVersion is >= 1.26 and found removed APIs on 1.26" ,
@@ -227,6 +260,11 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
227
260
errStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.26. " +
228
261
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-26. " +
229
262
"Migrate the API(s) for HorizontalPodAutoscaler: ([\" memcached-operator-hpa\" ])" },
263
+ wantWarning : true ,
264
+ warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.25. " +
265
+ "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
266
+ "Migrate the API(s) for events: " +
267
+ "([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.Permissions[0].Rules[2]\" ])" },
230
268
},
231
269
{
232
270
name : "should return a warning when the k8sVersion is empty and found removed APIs on 1.26" ,
@@ -236,9 +274,13 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
236
274
directory : "./testdata/removed_api_1_26" ,
237
275
},
238
276
wantWarning : true ,
239
- warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.26. " +
240
- "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-26. " +
241
- "Migrate the API(s) for HorizontalPodAutoscaler: ([\" memcached-operator-hpa\" ])" },
277
+ warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.25. " +
278
+ "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
279
+ "Migrate the API(s) for events: " +
280
+ "([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.Permissions[0].Rules[2]\" ])" ,
281
+ "this bundle is using APIs which were deprecated and removed in v1.26. " +
282
+ "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-26. " +
283
+ "Migrate the API(s) for HorizontalPodAutoscaler: ([\" memcached-operator-hpa\" ])" },
242
284
},
243
285
{
244
286
name : "should return an error when the k8sVersion informed is invalid" ,
@@ -252,8 +294,12 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
252
294
wantWarning : true ,
253
295
warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.22. " +
254
296
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
255
- "Migrate the API(s) for CRD: ([\" etcdbackups.etcd.database.coreos.com\" " +
256
- " \" etcdclusters.etcd.database.coreos.com\" \" etcdrestores.etcd.database.coreos.com\" ])" },
297
+ "Migrate the API(s) for CRD: ([\" etcdbackups.etcd.database.coreos.com\" " +
298
+ "\" etcdclusters.etcd.database.coreos.com\" \" etcdrestores.etcd.database.coreos.com\" ])" ,
299
+ "this bundle is using APIs which were deprecated and removed in v1.25. " +
300
+ "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
301
+ "Migrate the API(s) for events: " +
302
+ "([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.Permissions[0].Rules[1]\" ])" },
257
303
},
258
304
{
259
305
name : "should return an error when the csv.spec.minKubeVersion informed is invalid" ,
@@ -268,7 +314,11 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
268
314
warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.22. " +
269
315
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
270
316
"Migrate the API(s) for CRD: ([\" etcdbackups.etcd.database.coreos.com\" " +
271
- "\" etcdclusters.etcd.database.coreos.com\" \" etcdrestores.etcd.database.coreos.com\" ])" },
317
+ "\" etcdclusters.etcd.database.coreos.com\" \" etcdrestores.etcd.database.coreos.com\" ])" ,
318
+ "this bundle is using APIs which were deprecated and removed in v1.25. " +
319
+ "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
320
+ "Migrate the API(s) for events: " +
321
+ "([\" ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.Permissions[0].Rules[1]\" ])" },
272
322
},
273
323
}
274
324
for _ , tt := range tests {
0 commit comments