-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checks for k8s 1.25 deprecated APIs #151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package external | ||
|
||
import ( | ||
"github.com/operator-framework/api/pkg/manifests" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
func GetRemovedAPIsOn1_25From(bundle *manifests.Bundle) map[string][]string { | ||
deprecatedAPIs := make(map[string][]string) | ||
for _, obj := range bundle.Objects { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check has not been called in any validator so it will not be useful. we also need to address improvements for these scenario checks such as make clear what are the k8s versions supported by the checks and some cleanups. |
||
switch usage := obj.GetObjectKind().(type) { | ||
case *unstructured.Unstructured: | ||
switch usage.GetAPIVersion() { | ||
case "batch/v1beta1": | ||
if usage.GetKind() == "CronJob" { | ||
addDepUsage(deprecatedAPIs, usage) | ||
} | ||
case "discovery.k8s.io/v1beta1": | ||
if usage.GetKind() == "EndpointSlice" { | ||
addDepUsage(deprecatedAPIs, usage) | ||
} | ||
case "events.k8s.io/v1beta1": | ||
if usage.GetKind() == "Event" { | ||
addDepUsage(deprecatedAPIs, usage) | ||
} | ||
case "policy/v1beta1": | ||
if usage.GetKind() == "PodDisruptionBudget" || usage.GetKind() == "PodSecurityPolicy" { | ||
addDepUsage(deprecatedAPIs, usage) | ||
} | ||
case "node.k8s.io/v1beta1": | ||
if usage.GetKind() == "RuntimeClass" { | ||
addDepUsage(deprecatedAPIs, usage) | ||
} | ||
} | ||
} | ||
} | ||
return deprecatedAPIs | ||
} | ||
|
||
func addDepUsage(deprecatedAPIs map[string][]string, u *unstructured.Unstructured) map[string][]string { | ||
deprecatedAPIs[u.GetKind()] = append(deprecatedAPIs[u.GetKind()], u.GetName()) | ||
return deprecatedAPIs | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you getting the name of the resource where the api was found? See that it is used in more places so, why not address the cleanup across the project? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package external | ||
|
||
import ( | ||
"github.com/operator-framework/api/pkg/manifests" | ||
"github.com/stretchr/testify/require" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_getDeprecated1_25APIs(t *testing.T) { | ||
|
||
// Mock the expected result for ../internal/testdata/valid_bundle_v1beta1 | ||
crdMock := make(map[string][]string) | ||
crdMock["CRD"] = []string{"etcdbackups.etcd.database.coreos.com", "etcdclusters.etcd.database.coreos.com", "etcdrestores.etcd.database.coreos.com"} | ||
|
||
// Mock the expected result | ||
otherKindsMock := make(map[string][]string) | ||
otherKindsMock["PodDisruptionBudget"] = []string{"busybox-pdb"} | ||
|
||
bundleDirPrefix := "../internal/testdata/" // let's reuse the testdata, so we can avoid creating more | ||
|
||
type args struct { | ||
bundleDir string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string][]string | ||
}{ | ||
{ | ||
name: "should return an empty map when no deprecated apis are found", | ||
args: args{ | ||
bundleDir: bundleDirPrefix + "valid_bundle_v1", | ||
}, | ||
want: map[string][]string{}, | ||
}, | ||
{ | ||
name: "should return map with others kinds which are deprecated", | ||
args: args{ | ||
bundleDir: bundleDirPrefix + "bundle_with_deprecated_resources", | ||
}, | ||
want: otherKindsMock, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
// Validate the bundle object | ||
bundle, err := manifests.GetBundleFromDir(tt.args.bundleDir) | ||
require.NoError(t, err) | ||
|
||
if got := GetRemovedAPIsOn1_25From(bundle); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("getRemovedAPIsOn1_25From() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add this implementation with https://github.com/operator-framework/api/blob/master/pkg/validation/internal/removed_apis.go?