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