@@ -12,6 +12,7 @@ import (
12
12
interfaces "github.com/operator-framework/api/pkg/validation/interfaces"
13
13
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14
14
"k8s.io/apimachinery/pkg/runtime"
15
+ "k8s.io/apimachinery/pkg/runtime/schema"
15
16
)
16
17
17
18
// k8sVersionKey defines the key which can be used by its consumers
@@ -306,51 +307,35 @@ func getRemovedAPIsOn1_25From(bundle *manifests.Bundle) (map[string][]string, ma
306
307
deprecatedAPIs := make (map [string ][]string )
307
308
warnDeprecatedAPIs := make (map [string ][]string )
308
309
310
+ deprecatedGvk := map [schema.GroupVersionKind ]struct {}{
311
+ {Group : "batch" , Version : "v1beta1" , Kind : "CronJob" }: {},
312
+ {Group : "discovery.k8s.io" , Version : "v1beta1" , Kind : "EndpointSlice" }: {},
313
+ {Group : "events.k8s.io" , Version : "v1beta1" , Kind : "Event" }: {},
314
+ {Group : "autoscaling" , Version : "v2beta1" , Kind : "HorizontalPodAutoscaler" }: {},
315
+ {Group : "policy" , Version : "v1beta1" , Kind : "PodDisruptionBudget" }: {},
316
+ {Group : "policy" , Version : "v1beta1" , Kind : "PodSecurityPolicy" }: {},
317
+ {Group : "node.k8s.io" , Version : "v1beta1" , Kind : "RuntimeClass" }: {},
318
+ }
319
+
309
320
addIfDeprecated := func (u * unstructured.Unstructured ) {
310
- switch u .GetAPIVersion () {
311
- case "batch/v1beta1" :
312
- if u .GetKind () == "CronJob" {
313
- deprecatedAPIs [u .GetKind ()] = append (deprecatedAPIs [u .GetKind ()], u .GetName ())
314
- }
315
- case "discovery.k8s.io/v1beta1" :
316
- if u .GetKind () == "EndpointSlice" {
317
- deprecatedAPIs [u .GetKind ()] = append (deprecatedAPIs [u .GetKind ()], u .GetName ())
318
- }
319
- case "events.k8s.io/v1beta1" :
320
- if u .GetKind () == "Event" {
321
- deprecatedAPIs [u .GetKind ()] = append (deprecatedAPIs [u .GetKind ()], u .GetName ())
322
- }
323
- case "autoscaling/v2beta1" :
324
- if u .GetKind () == "HorizontalPodAutoscaler" {
325
- deprecatedAPIs [u .GetKind ()] = append (deprecatedAPIs [u .GetKind ()], u .GetName ())
326
- }
327
- case "policy/v1beta1" :
328
- if u .GetKind () == "PodDisruptionBudget" || u .GetKind () == "PodSecurityPolicy" {
329
- deprecatedAPIs [u .GetKind ()] = append (deprecatedAPIs [u .GetKind ()], u .GetName ())
330
- }
331
- case "node.k8s.io/v1beta1" :
332
- if u .GetKind () == "RuntimeClass" {
333
- deprecatedAPIs [u .GetKind ()] = append (deprecatedAPIs [u .GetKind ()], u .GetName ())
334
- }
321
+ if _ , ok := deprecatedGvk [u .GetObjectKind ().GroupVersionKind ()]; ok {
322
+ deprecatedAPIs [u .GetKind ()] = append (deprecatedAPIs [u .GetKind ()], u .GetName ())
335
323
}
336
324
}
337
325
338
- warnIfDeprecated := func (res string , msg string ) {
339
- switch res {
340
- case "cronjobs" :
341
- warnDeprecatedAPIs [res ] = append (warnDeprecatedAPIs [res ], msg )
342
- case "endpointslices" :
343
- warnDeprecatedAPIs [res ] = append (warnDeprecatedAPIs [res ], msg )
344
- case "events" :
345
- warnDeprecatedAPIs [res ] = append (warnDeprecatedAPIs [res ], msg )
346
- case "horizontalpodautoscalers" :
347
- warnDeprecatedAPIs [res ] = append (warnDeprecatedAPIs [res ], msg )
348
- case "poddisruptionbudgets" :
349
- warnDeprecatedAPIs [res ] = append (warnDeprecatedAPIs [res ], msg )
350
- case "podsecuritypolicies" :
351
- warnDeprecatedAPIs [res ] = append (warnDeprecatedAPIs [res ], msg )
352
- case "runtimeclasses" :
353
- warnDeprecatedAPIs [res ] = append (warnDeprecatedAPIs [res ], msg )
326
+ deprecatedGroupResource := map [schema.GroupResource ]struct {}{
327
+ {Group : "batch" , Resource : "cronjobs" }: {},
328
+ {Group : "discovery.k8s.io" , Resource : "endpointslices" }: {},
329
+ {Group : "events.k8s.io" , Resource : "events" }: {},
330
+ {Group : "autoscaling" , Resource : "horizontalpodautoscalers" }: {},
331
+ {Group : "policy" , Resource : "poddisruptionbudgets" }: {},
332
+ {Group : "policy" , Resource : "podsecuritypolicies" }: {},
333
+ {Group : "node.k8s.io" , Resource : "runtimeclasses" }: {},
334
+ }
335
+
336
+ warnIfDeprecated := func (gr schema.GroupResource , msg string ) {
337
+ if _ , ok := deprecatedGroupResource [gr ]; ok {
338
+ warnDeprecatedAPIs [gr .Resource ] = append (warnDeprecatedAPIs [gr .Resource ], msg )
354
339
}
355
340
}
356
341
@@ -403,11 +388,13 @@ func getRemovedAPIsOn1_25From(bundle *manifests.Bundle) (map[string][]string, ma
403
388
permCheck := func (permField string , perms []v1alpha1.StrategyDeploymentPermissions ) {
404
389
for i , perm := range perms {
405
390
for j , rule := range perm .Rules {
406
- for _ , res := range rule .Resources {
407
- if _ , ok := resInCsvCrds [res ]; ok {
408
- continue
391
+ for _ , apiGroup := range rule .APIGroups {
392
+ for _ , res := range rule .Resources {
393
+ if _ , ok := resInCsvCrds [res ]; ok {
394
+ continue
395
+ }
396
+ warnIfDeprecated (schema.GroupResource {Group : apiGroup , Resource : res }, fmt .Sprintf ("ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.%s[%d].Rules[%d]" , permField , i , j ))
409
397
}
410
- warnIfDeprecated (res , fmt .Sprintf ("ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.%s[%d].Rules[%d]" , permField , i , j ))
411
398
}
412
399
}
413
400
}
0 commit comments