From 222fac2bd90ba23e6d9bc21627ea11014693652a Mon Sep 17 00:00:00 2001 From: Andrej Krejcir Date: Wed, 6 Dec 2023 14:26:29 +0100 Subject: [PATCH] fix: Import correct apiextensions version The previous imported version was incorrect. Signed-off-by: Andrej Krejcir --- internal/common/scheme.go | 9 +++---- internal/crd-watch/crd-watch.go | 6 ++--- internal/crd-watch/crd-watch_test.go | 18 ++++++------- .../common-instancetypes/reconcile_test.go | 26 +++++++++---------- .../tekton-pipelines/reconcile_test.go | 18 +++++++------ .../operands/tekton-tasks/reconcile_test.go | 16 +++++++----- 6 files changed, 48 insertions(+), 45 deletions(-) diff --git a/internal/common/scheme.go b/internal/common/scheme.go index e8f1bbcd5..2472681dc 100644 --- a/internal/common/scheme.go +++ b/internal/common/scheme.go @@ -2,7 +2,6 @@ package common import ( osconfv1 "github.com/openshift/api/config/v1" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" internalmeta "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -36,8 +35,8 @@ func init() { // This function is useful in operand unit tests only func AddConversionFunctions(s *runtime.Scheme) error { - err := s.AddConversionFunc((*apiextensions.CustomResourceDefinition)(nil), (*metav1.PartialObjectMetadata)(nil), func(a, b interface{}, scope conversion.Scope) error { - crd := a.(*apiextensions.CustomResourceDefinition) + err := s.AddConversionFunc((*extv1.CustomResourceDefinition)(nil), (*metav1.PartialObjectMetadata)(nil), func(a, b interface{}, scope conversion.Scope) error { + crd := a.(*extv1.CustomResourceDefinition) partialMeta := b.(*metav1.PartialObjectMetadata) partialMeta.TypeMeta = crd.TypeMeta @@ -48,8 +47,8 @@ func AddConversionFunctions(s *runtime.Scheme) error { return err } - return s.AddConversionFunc((*apiextensions.CustomResourceDefinitionList)(nil), (*metav1.PartialObjectMetadataList)(nil), func(a, b interface{}, scope conversion.Scope) error { - crdList := a.(*apiextensions.CustomResourceDefinitionList) + return s.AddConversionFunc((*extv1.CustomResourceDefinitionList)(nil), (*metav1.PartialObjectMetadataList)(nil), func(a, b interface{}, scope conversion.Scope) error { + crdList := a.(*extv1.CustomResourceDefinitionList) partialMetaList := b.(*metav1.PartialObjectMetadataList) partialMetaList.TypeMeta = crdList.TypeMeta diff --git a/internal/crd-watch/crd-watch.go b/internal/crd-watch/crd-watch.go index 3fc88ab82..5311cdd4d 100644 --- a/internal/crd-watch/crd-watch.go +++ b/internal/crd-watch/crd-watch.go @@ -5,7 +5,7 @@ import ( "fmt" "sync" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" + extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/cache" ctrlcache "sigs.k8s.io/controller-runtime/pkg/cache" @@ -95,7 +95,7 @@ func (c *CrdWatch) Start(ctx context.Context) error { informer, err := c.cache.GetInformer(ctx, &metav1.PartialObjectMetadata{ TypeMeta: metav1.TypeMeta{ - APIVersion: apiextensions.GroupName + "/v1", + APIVersion: extv1.SchemeGroupVersion.String(), Kind: "CustomResourceDefinition", }, }) @@ -131,7 +131,7 @@ func (c *CrdWatch) Start(ctx context.Context) error { func (c *CrdWatch) sync(ctx context.Context, reader client.Reader) error { crdMetaList := &metav1.PartialObjectMetadataList{ TypeMeta: metav1.TypeMeta{ - APIVersion: apiextensions.SchemeGroupVersion.String(), + APIVersion: extv1.SchemeGroupVersion.String(), Kind: "CustomResourceDefinitionList", }, } diff --git a/internal/crd-watch/crd-watch_test.go b/internal/crd-watch/crd-watch_test.go index 1e1b2d91d..e2bc3bc3b 100644 --- a/internal/crd-watch/crd-watch_test.go +++ b/internal/crd-watch/crd-watch_test.go @@ -9,7 +9,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" + extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" internalmeta "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/conversion" @@ -35,14 +35,14 @@ var _ = Describe("CRD watch", func() { BeforeEach(func() { Expect(internalmeta.AddToScheme(scheme.Scheme)).To(Succeed()) - Expect(apiextensions.AddToScheme(scheme.Scheme)).To(Succeed()) + Expect(extv1.AddToScheme(scheme.Scheme)).To(Succeed()) // For unit tests, we to manually add conversion functions from CRD to PartialObjectMetadata Expect(addConversionFunctions(scheme.Scheme)).To(Succeed()) - crdObj := &apiextensions.CustomResourceDefinition{ + crdObj := &extv1.CustomResourceDefinition{ TypeMeta: metav1.TypeMeta{ - APIVersion: apiextensions.SchemeGroupVersion.String(), + APIVersion: extv1.SchemeGroupVersion.String(), Kind: "CustomResourceDefinition", }, ObjectMeta: metav1.ObjectMeta{ @@ -161,8 +161,8 @@ var _ = Describe("CRD watch", func() { }) func addConversionFunctions(s *runtime.Scheme) error { - err := s.AddConversionFunc((*apiextensions.CustomResourceDefinition)(nil), (*metav1.PartialObjectMetadata)(nil), func(a, b interface{}, scope conversion.Scope) error { - crd := a.(*apiextensions.CustomResourceDefinition) + err := s.AddConversionFunc((*extv1.CustomResourceDefinition)(nil), (*metav1.PartialObjectMetadata)(nil), func(a, b interface{}, scope conversion.Scope) error { + crd := a.(*extv1.CustomResourceDefinition) partialMeta := b.(*metav1.PartialObjectMetadata) partialMeta.TypeMeta = crd.TypeMeta @@ -173,8 +173,8 @@ func addConversionFunctions(s *runtime.Scheme) error { return err } - return s.AddConversionFunc((*apiextensions.CustomResourceDefinitionList)(nil), (*metav1.PartialObjectMetadataList)(nil), func(a, b interface{}, scope conversion.Scope) error { - crdList := a.(*apiextensions.CustomResourceDefinitionList) + return s.AddConversionFunc((*extv1.CustomResourceDefinitionList)(nil), (*metav1.PartialObjectMetadataList)(nil), func(a, b interface{}, scope conversion.Scope) error { + crdList := a.(*extv1.CustomResourceDefinitionList) partialMetaList := b.(*metav1.PartialObjectMetadataList) partialMetaList.TypeMeta = crdList.TypeMeta @@ -205,7 +205,7 @@ func removeCrdFromFakeInformers(crdName string, fakeInformers *informertest.Fake func crdPartialMetadata(crdName string) *metav1.PartialObjectMetadata { return &metav1.PartialObjectMetadata{ TypeMeta: metav1.TypeMeta{ - APIVersion: apiextensions.SchemeGroupVersion.String(), + APIVersion: extv1.SchemeGroupVersion.String(), Kind: "CustomResourceDefinition", }, ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/operands/common-instancetypes/reconcile_test.go b/internal/operands/common-instancetypes/reconcile_test.go index ea0ff302a..1bebc4a09 100644 --- a/internal/operands/common-instancetypes/reconcile_test.go +++ b/internal/operands/common-instancetypes/reconcile_test.go @@ -9,7 +9,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" + extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" internalmeta "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/conversion" @@ -48,8 +48,8 @@ var _ = Describe("Common-Instancetypes operand", func() { err error operand *CommonInstancetypes request common.Request - virtualMachineClusterInstancetypeCrdObj *apiextensions.CustomResourceDefinition - virtualMachineClusterPreferenceCrdObj *apiextensions.CustomResourceDefinition + virtualMachineClusterInstancetypeCrdObj *extv1.CustomResourceDefinition + virtualMachineClusterPreferenceCrdObj *extv1.CustomResourceDefinition ) const ( @@ -82,15 +82,15 @@ var _ = Describe("Common-Instancetypes operand", func() { Expect(err).ToNot(HaveOccurred()) Expect(internalmeta.AddToScheme(scheme.Scheme)).To(Succeed()) - Expect(apiextensions.AddToScheme(scheme.Scheme)).To(Succeed()) + Expect(extv1.AddToScheme(scheme.Scheme)).To(Succeed()) Expect(addConversionFunctions(scheme.Scheme)).To(Succeed()) Expect(instancetypev1beta1.AddToScheme(scheme.Scheme)).To(Succeed()) client := fake.NewClientBuilder().Build() - virtualMachineClusterInstancetypeCrdObj = &apiextensions.CustomResourceDefinition{ + virtualMachineClusterInstancetypeCrdObj = &extv1.CustomResourceDefinition{ TypeMeta: metav1.TypeMeta{ - APIVersion: apiextensions.SchemeGroupVersion.String(), + APIVersion: extv1.SchemeGroupVersion.String(), Kind: "CustomResourceDefinition", }, ObjectMeta: metav1.ObjectMeta{ @@ -99,9 +99,9 @@ var _ = Describe("Common-Instancetypes operand", func() { } Expect(client.Create(context.Background(), virtualMachineClusterInstancetypeCrdObj)).To(Succeed()) - virtualMachineClusterPreferenceCrdObj = &apiextensions.CustomResourceDefinition{ + virtualMachineClusterPreferenceCrdObj = &extv1.CustomResourceDefinition{ TypeMeta: metav1.TypeMeta{ - APIVersion: apiextensions.SchemeGroupVersion.String(), + APIVersion: extv1.SchemeGroupVersion.String(), Kind: "CustomResourceDefinition", }, ObjectMeta: metav1.ObjectMeta{ @@ -142,7 +142,7 @@ var _ = Describe("Common-Instancetypes operand", func() { // Replace the client with a new one without the CRDs or instancetype schema present testScheme := runtime.NewScheme() Expect(internalmeta.AddToScheme(testScheme)).To(Succeed()) - Expect(apiextensions.AddToScheme(testScheme)).To(Succeed()) + Expect(extv1.AddToScheme(testScheme)).To(Succeed()) request.Client = fake.NewClientBuilder().WithScheme(testScheme).Build() @@ -511,8 +511,8 @@ var _ = Describe("Common-Instancetypes operand", func() { }) func addConversionFunctions(s *runtime.Scheme) error { - err := s.AddConversionFunc((*apiextensions.CustomResourceDefinition)(nil), (*metav1.PartialObjectMetadata)(nil), func(a, b interface{}, scope conversion.Scope) error { - crd := a.(*apiextensions.CustomResourceDefinition) + err := s.AddConversionFunc((*extv1.CustomResourceDefinition)(nil), (*metav1.PartialObjectMetadata)(nil), func(a, b interface{}, scope conversion.Scope) error { + crd := a.(*extv1.CustomResourceDefinition) partialMeta := b.(*metav1.PartialObjectMetadata) partialMeta.TypeMeta = crd.TypeMeta @@ -523,8 +523,8 @@ func addConversionFunctions(s *runtime.Scheme) error { return err } - return s.AddConversionFunc((*apiextensions.CustomResourceDefinitionList)(nil), (*metav1.PartialObjectMetadataList)(nil), func(a, b interface{}, scope conversion.Scope) error { - crdList := a.(*apiextensions.CustomResourceDefinitionList) + return s.AddConversionFunc((*extv1.CustomResourceDefinitionList)(nil), (*metav1.PartialObjectMetadataList)(nil), func(a, b interface{}, scope conversion.Scope) error { + crdList := a.(*extv1.CustomResourceDefinitionList) partialMetaList := b.(*metav1.PartialObjectMetadataList) partialMetaList.TypeMeta = crdList.TypeMeta diff --git a/internal/operands/tekton-pipelines/reconcile_test.go b/internal/operands/tekton-pipelines/reconcile_test.go index 79a1c9784..eb0b291ed 100644 --- a/internal/operands/tekton-pipelines/reconcile_test.go +++ b/internal/operands/tekton-pipelines/reconcile_test.go @@ -6,24 +6,26 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" v1 "k8s.io/api/core/v1" rbac "k8s.io/api/rbac/v1" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" + extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" internalmeta "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/fake" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + ssp "kubevirt.io/ssp-operator/api/v1beta2" "kubevirt.io/ssp-operator/internal/common" crd_watch "kubevirt.io/ssp-operator/internal/crd-watch" "kubevirt.io/ssp-operator/internal/operands" tektonbundle "kubevirt.io/ssp-operator/internal/tekton-bundle" . "kubevirt.io/ssp-operator/internal/test-utils" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/fake" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/reconcile" ) const ( @@ -300,16 +302,16 @@ func getMockedRequest() *common.Request { log := logf.Log.WithName("tekton-pipelines-operand") Expect(internalmeta.AddToScheme(scheme.Scheme)).To(Succeed()) - Expect(apiextensions.AddToScheme(scheme.Scheme)).To(Succeed()) + Expect(extv1.AddToScheme(scheme.Scheme)).To(Succeed()) Expect(common.AddConversionFunctions(scheme.Scheme)).To(Succeed()) Expect(pipeline.AddToScheme(scheme.Scheme)).To(Succeed()) Expect(ssp.AddToScheme(scheme.Scheme)).To(Succeed()) client := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build() - tektonCrdObj := &apiextensions.CustomResourceDefinition{ + tektonCrdObj := &extv1.CustomResourceDefinition{ TypeMeta: metav1.TypeMeta{ - APIVersion: apiextensions.SchemeGroupVersion.String(), + APIVersion: extv1.SchemeGroupVersion.String(), Kind: "CustomResourceDefinition", }, ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/operands/tekton-tasks/reconcile_test.go b/internal/operands/tekton-tasks/reconcile_test.go index 13e3a9b7c..5204e6740 100644 --- a/internal/operands/tekton-tasks/reconcile_test.go +++ b/internal/operands/tekton-tasks/reconcile_test.go @@ -6,23 +6,25 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" v1 "k8s.io/api/core/v1" rbac "k8s.io/api/rbac/v1" - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" + extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" internalmeta "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" + "sigs.k8s.io/controller-runtime/pkg/client/fake" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + ssp "kubevirt.io/ssp-operator/api/v1beta2" "kubevirt.io/ssp-operator/internal/common" crd_watch "kubevirt.io/ssp-operator/internal/crd-watch" "kubevirt.io/ssp-operator/internal/operands" tektonbundle "kubevirt.io/ssp-operator/internal/tekton-bundle" . "kubevirt.io/ssp-operator/internal/test-utils" - "sigs.k8s.io/controller-runtime/pkg/client/fake" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/reconcile" ) const ( @@ -158,16 +160,16 @@ func getMockedRequest() common.Request { log := logf.Log.WithName("tekton-tasks-operand") Expect(internalmeta.AddToScheme(scheme.Scheme)).To(Succeed()) - Expect(apiextensions.AddToScheme(scheme.Scheme)).To(Succeed()) + Expect(extv1.AddToScheme(scheme.Scheme)).To(Succeed()) Expect(common.AddConversionFunctions(scheme.Scheme)).To(Succeed()) Expect(pipeline.AddToScheme(scheme.Scheme)).To(Succeed()) Expect(ssp.AddToScheme(scheme.Scheme)).To(Succeed()) client := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build() - tektonCrdObj := &apiextensions.CustomResourceDefinition{ + tektonCrdObj := &extv1.CustomResourceDefinition{ TypeMeta: metav1.TypeMeta{ - APIVersion: apiextensions.SchemeGroupVersion.String(), + APIVersion: extv1.SchemeGroupVersion.String(), Kind: "CustomResourceDefinition", }, ObjectMeta: metav1.ObjectMeta{