diff --git a/pkg/controllers/migration/controller.go b/pkg/controllers/migration/controller.go index e1a4838d4e..b0e85f2dea 100644 --- a/pkg/controllers/migration/controller.go +++ b/pkg/controllers/migration/controller.go @@ -79,7 +79,7 @@ func (c *Controller[T]) Reconcile(ctx context.Context) (reconcile.Result, error) } // should filter tighter than this crds := lo.Filter(crdList.Items, func(crd apiextensionsv1.CustomResourceDefinition, _ int) bool { - return strings.Contains(crd.ObjectMeta.Name, strings.ToLower(o.GetObjectKind().GroupVersionKind().Kind)) + return strings.Contains(crd.ObjectMeta.Name, strings.ToLower(object.GVK(o).Kind)) }) for _, crd := range crds { stored := crd.DeepCopy() diff --git a/pkg/controllers/migration/suite_test.go b/pkg/controllers/migration/suite_test.go index 3f7be6312a..5e64c8a698 100644 --- a/pkg/controllers/migration/suite_test.go +++ b/pkg/controllers/migration/suite_test.go @@ -18,6 +18,7 @@ package migration_test import ( "context" + "strings" "testing" operatorexpectations "github.com/awslabs/operatorpkg/test/expectations" @@ -30,7 +31,6 @@ import ( "sigs.k8s.io/karpenter/pkg/test" corev1 "k8s.io/api/core/v1" - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" . "sigs.k8s.io/karpenter/pkg/utils/testing" @@ -60,9 +60,11 @@ var _ = AfterSuite(func() { var _ = Describe("Migration", func() { var node *corev1.Node var nodeClaim *v1.NodeClaim + var nodeClass *v1alpha1.TestNodeClass BeforeEach(func() { nodeClaim, node = test.NodeClaimAndNode() + nodeClass = test.NodeClass() node.Labels[v1.NodePoolLabelKey] = test.NodePool().Name }) @@ -77,13 +79,15 @@ var _ = Describe("Migration", func() { nodeClaim = ExpectExists(ctx, env.Client, nodeClaim) Expect(nodeClaim.Annotations).To(HaveKeyWithValue("stored-version", "v1")) }) - It("should patch CRD status", func() { - ExpectApplied(ctx, env.Client, node, nodeClaim) + It("should patch CRD status stored versions", func() { + ExpectApplied(ctx, env.Client, node, nodeClaim, nodeClass) operatorexpectations.ExpectSingletonReconciled(ctx, migrationController) nodeClaim = ExpectExists(ctx, env.Client, nodeClaim) - crds := ExpectListExists(ctx, env.Client, &apiextensionsv1.CustomResourceDefinition{}) - for _, crd := range crds { - Expect(crd.Object["status"]).To(HaveKeyWithValue("storedVersions", []interface{}{"v1"})) + nodeClass = ExpectExists(ctx, env.Client, nodeClass) + for _, crd := range env.CRDs { + if strings.Contains(crd.Name, strings.ToLower(nodeClass.Name)) { + Expect(crd.Status.StoredVersions).To(HaveExactElements("v1")) + } } }) }) diff --git a/pkg/test/expectations/expectations.go b/pkg/test/expectations/expectations.go index 2617747037..9bb3d6958d 100644 --- a/pkg/test/expectations/expectations.go +++ b/pkg/test/expectations/expectations.go @@ -28,7 +28,6 @@ import ( "sigs.k8s.io/karpenter/pkg/test/v1alpha1" - "github.com/awslabs/operatorpkg/object" "github.com/awslabs/operatorpkg/singleton" "github.com/awslabs/operatorpkg/status" . "github.com/onsi/ginkgo/v2" //nolint:revive,stylecheck @@ -44,7 +43,6 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" @@ -96,14 +94,6 @@ func ExpectExists[T client.Object](ctx context.Context, c client.Client, obj T) return resp } -func ExpectListExists[T client.Object](ctx context.Context, c client.Client, obj T) []unstructured.Unstructured { - GinkgoHelper() - list := &unstructured.UnstructuredList{} - list.SetGroupVersionKind(object.GVK(obj)) - Expect(c.List(ctx, list)).To(Succeed()) - return list.Items -} - func ExpectPodExists(ctx context.Context, c client.Client, name string, namespace string) *corev1.Pod { GinkgoHelper() return ExpectExists(ctx, c, &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}})