Skip to content

Commit

Permalink
fix: Import correct apiextensions version
Browse files Browse the repository at this point in the history
The previous imported version was incorrect.

Signed-off-by: Andrej Krejcir <[email protected]>
  • Loading branch information
akrejcir committed Dec 8, 2023
1 parent aa03bd5 commit 3c08e53
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 45 deletions.
9 changes: 4 additions & 5 deletions internal/common/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/crd-watch/crd-watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
},
})
Expand Down Expand Up @@ -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",
},
}
Expand Down
18 changes: 9 additions & 9 deletions internal/crd-watch/crd-watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand Down
26 changes: 13 additions & 13 deletions internal/operands/common-instancetypes/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 10 additions & 8 deletions internal/operands/tekton-pipelines/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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{
Expand Down
16 changes: 9 additions & 7 deletions internal/operands/tekton-tasks/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 3c08e53

Please sign in to comment.