Skip to content

Commit 57ed030

Browse files
everettravenperdasilva
authored andcommitted
(bugfix): make k8s 1.25 validation logic check api group before issuing a warning (openshift#274)
* fix a bug in k8s 1.25 validation logic to now check the apiGroup/resource to determine if an api is deprecated. Signed-off-by: Bryce Palmer <[email protected]> * update warning and error checks to use a map Signed-off-by: Bryce Palmer <[email protected]> Signed-off-by: Bryce Palmer <[email protected]> Upstream-repository: api Upstream-commit: f1b729684854a053f229464eb327527222188fd1
1 parent b2892cc commit 57ed030

File tree

10 files changed

+464
-315
lines changed

10 files changed

+464
-315
lines changed

pkg/manifests/csv.yaml

-175
This file was deleted.

staging/api/pkg/validation/internal/removed_apis.go

+32-45
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
interfaces "github.com/operator-framework/api/pkg/validation/interfaces"
1313
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1414
"k8s.io/apimachinery/pkg/runtime"
15+
"k8s.io/apimachinery/pkg/runtime/schema"
1516
)
1617

1718
// 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
306307
deprecatedAPIs := make(map[string][]string)
307308
warnDeprecatedAPIs := make(map[string][]string)
308309

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+
309320
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())
335323
}
336324
}
337325

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)
354339
}
355340
}
356341

@@ -403,11 +388,13 @@ func getRemovedAPIsOn1_25From(bundle *manifests.Bundle) (map[string][]string, ma
403388
permCheck := func(permField string, perms []v1alpha1.StrategyDeploymentPermissions) {
404389
for i, perm := range perms {
405390
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))
409397
}
410-
warnIfDeprecated(res, fmt.Sprintf("ClusterServiceVersion.Spec.InstallStrategy.StrategySpec.%s[%d].Rules[%d]", permField, i, j))
411398
}
412399
}
413400
}

0 commit comments

Comments
 (0)