@@ -72,27 +72,34 @@ func Test_GetRemovedAPIsOn1_25From(t *testing.T) {
7272 mock ["HorizontalPodAutoscaler" ] = []string {"memcached-operator-hpa" }
7373 mock ["PodDisruptionBudget" ] = []string {"memcached-operator-policy-manager" }
7474
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+
7579 type args struct {
7680 bundleDir string
7781 }
7882 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
8287 }{
8388 {
8489 name : "should return an empty map when no deprecated apis are found" ,
8590 args : args {
8691 bundleDir : "./testdata/valid_bundle_v1" ,
8792 },
88- want : map [string ][]string {},
93+ errWant : map [string ][]string {},
94+ warnWant : map [string ][]string {},
8995 },
9096 {
9197 name : "should fail return the removed APIs in 1.25" ,
9298 args : args {
9399 bundleDir : "./testdata/removed_api_1_25" ,
94100 },
95- want : mock ,
101+ errWant : mock ,
102+ warnWant : warnMock ,
96103 },
97104 }
98105 for _ , tt := range tests {
@@ -102,8 +109,14 @@ func Test_GetRemovedAPIsOn1_25From(t *testing.T) {
102109 bundle , err := manifests .GetBundleFromDir (tt .args .bundleDir )
103110 require .NoError (t , err )
104111
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 )
107120 }
108121 })
109122 }
@@ -175,7 +188,11 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
175188 warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.22. " +
176189 "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
177190 "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]\" ])" },
179196 },
180197 {
181198 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) {
189206 "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
190207 "Migrate the API(s) for CRD: ([\" etcdbackups.etcd.database.coreos.com\" " +
191208 " \" 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]\" ])" },
192214 },
193215 {
194216 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) {
202224 "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
203225 "Migrate the API(s) for HorizontalPodAutoscaler: ([\" memcached-operator-hpa\" ])," +
204226 "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]\" ])," },
205233 },
206234 {
207235 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) {
214242 warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.25. " +
215243 "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25. " +
216244 "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]\" ])," },
218251 },
219252 {
220253 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) {
227260 errStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.26. " +
228261 "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-26. " +
229262 "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]\" ])" },
230268 },
231269 {
232270 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) {
236274 directory : "./testdata/removed_api_1_26" ,
237275 },
238276 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\" ])" },
242284 },
243285 {
244286 name : "should return an error when the k8sVersion informed is invalid" ,
@@ -252,8 +294,12 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
252294 wantWarning : true ,
253295 warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.22. " +
254296 "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]\" ])" },
257303 },
258304 {
259305 name : "should return an error when the csv.spec.minKubeVersion informed is invalid" ,
@@ -268,7 +314,11 @@ func TestValidateDeprecatedAPIS(t *testing.T) {
268314 warnStrings : []string {"this bundle is using APIs which were deprecated and removed in v1.22. " +
269315 "More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22. " +
270316 "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]\" ])" },
272322 },
273323 }
274324 for _ , tt := range tests {
0 commit comments