Skip to content

Commit

Permalink
Enable v1a2 controller and webhook integration tests
Browse files Browse the repository at this point in the history
- This change enables controller and webhook integration tests for v1alpha2.
- The testsuite works with the v1A2 FSS to create the right CRD storage versions prior to
the integration tests. This way, the right v1a1 and v1a2 CRDs are installed with the right storage versions when v1a1/v1a2 controller/webhook
integration tests are run.
  • Loading branch information
sreyasn committed Aug 23, 2023
1 parent 0ba28e4 commit 484e5b7
Show file tree
Hide file tree
Showing 20 changed files with 278 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ import (

"github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/v1alpha2/clustercontentlibraryitem"
ctrlContext "github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
providerfake "github.com/vmware-tanzu/vm-operator/pkg/vmprovider/fake"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

var intgFakeVMProvider = providerfake.NewVMProviderA2()

var suite = builder.NewTestSuiteForController(
var suite = builder.NewTestSuiteForControllerWithFSS(
clustercontentlibraryitem.AddToManager,
func(ctx *ctrlContext.ControllerManagerContext, _ ctrlmgr.Manager) error {
ctx.VMProviderA2 = intgFakeVMProvider
return nil
},
)
map[string]bool{lib.VMServiceV1Alpha2FSS: true})

func TestClusterContentLibraryItem(t *testing.T) {
_ = intgTests
suite.Register(t, "ClusterContentLibraryItem controller suite", nil /*intgTests*/, unitTests)
suite.Register(t, "ClusterContentLibraryItem controller suite", intgTests, unitTests)
}

var _ = BeforeSuite(suite.BeforeSuite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func clItemReconcile() {

imageName, err := utils.GetImageFieldNameFromItem(clItemKey.Name)
Expect(err).ToNot(HaveOccurred())
vmiKey := client.ObjectKey{Name: imageName}
vmiKey := client.ObjectKey{Name: imageName, Namespace: ctx.Namespace}

By("Finalizer should be added to ContentLibraryItem", func() {
waitForContentLibraryItemFinalizer(clItemKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ var suite = builder.NewTestSuiteForControllerWithFSS(
ctx.VMProviderA2 = intgFakeVMProvider
return nil
},
map[string]bool{lib.VMImageRegistryFSS: true},
)
map[string]bool{
lib.VMImageRegistryFSS: true,
lib.VMServiceV1Alpha2FSS: true})

func TestContentLibraryItem(t *testing.T) {
_ = intgTests
suite.Register(t, "ContentLibraryItem controller suite", nil /*intgTests*/, unitTests)
suite.Register(t, "ContentLibraryItem controller suite", intgTests, unitTests)
}

var _ = BeforeSuite(suite.BeforeSuite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ import (

virtualmachine "github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/v1alpha2"
ctrlContext "github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
providerfake "github.com/vmware-tanzu/vm-operator/pkg/vmprovider/fake"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

var intgFakeVMProvider = providerfake.NewVMProviderA2()

var suite = builder.NewTestSuiteForController(
var suite = builder.NewTestSuiteForControllerWithFSS(
virtualmachine.AddToManager,
func(ctx *ctrlContext.ControllerManagerContext, _ ctrlmgr.Manager) error {
ctx.VMProviderA2 = intgFakeVMProvider
return nil
},
)
map[string]bool{lib.VMServiceV1Alpha2FSS: true})

func TestVirtualMachine(t *testing.T) {
_ = intgTests
suite.Register(t, "VirtualMachine controller suite", nil /*intgTests*/, unitTests)
suite.Register(t, "VirtualMachine controller suite", intgTests, unitTests)
}

var _ = BeforeSuite(suite.BeforeSuite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
. "github.com/onsi/ginkgo"

virtualmachineclass "github.com/vmware-tanzu/vm-operator/controllers/virtualmachineclass/v1alpha2"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/pkg/manager"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

var suite = builder.NewTestSuiteForController(
var suite = builder.NewTestSuiteForControllerWithFSS(
virtualmachineclass.AddToManager,
manager.InitializeProvidersNoopFn,
)
map[string]bool{lib.VMServiceV1Alpha2FSS: true})

func TestVirtualMachineClass(t *testing.T) {
_ = intgTests
suite.Register(t, "VirtualMachineClass controller suite", nil /*intgTests*/, unitTests)
suite.Register(t, "VirtualMachineClass controller suite", intgTests, unitTests)
}

var _ = BeforeSuite(suite.BeforeSuite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ var suite = builder.NewTestSuiteForControllerWithFSS(
ctx.VMProviderA2 = intgFakeVMProvider
return nil
},
map[string]bool{lib.VMImageRegistryFSS: true},
)
map[string]bool{
lib.VMImageRegistryFSS: true,
lib.VMServiceV1Alpha2FSS: true})

func TestVirtualMachinePublishRequest(t *testing.T) {
_ = intgTests
suite.Register(t, "VirtualMachinePublishRequest controller suite", nil /*intgTests*/, unitTests)
suite.Register(t, "VirtualMachinePublishRequest controller suite", intgTests, unitTests)
}

var _ = BeforeSuite(suite.BeforeSuite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import (
. "github.com/onsi/ginkgo"

virtualmachineservice "github.com/vmware-tanzu/vm-operator/controllers/virtualmachineservice/v1alpha2"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/pkg/manager"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

var suite = builder.NewTestSuiteForController(
var suite = builder.NewTestSuiteForControllerWithFSS(
virtualmachineservice.AddToManager,
manager.InitializeProvidersNoopFn,
)
map[string]bool{lib.VMServiceV1Alpha2FSS: true})

func TestVirtualMachineService(t *testing.T) {
_ = intgTests
suite.Register(t, "VirtualMachineService controller suite", nil /*intgTests*/, unitTests)

suite.Register(t, "VirtualMachineService controller suite", intgTests, unitTests)
}

var _ = BeforeSuite(suite.BeforeSuite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ import (

virtualmachinesetresourcepolicy "github.com/vmware-tanzu/vm-operator/controllers/virtualmachinesetresourcepolicy/v1alpha2"
ctrlContext "github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
providerfake "github.com/vmware-tanzu/vm-operator/pkg/vmprovider/fake"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

var intgFakeVMProvider = providerfake.NewVMProviderA2()

var suite = builder.NewTestSuiteForController(
var suite = builder.NewTestSuiteForControllerWithFSS(
virtualmachinesetresourcepolicy.AddToManager,
func(ctx *ctrlContext.ControllerManagerContext, _ ctrlmgr.Manager) error {
ctx.VMProviderA2 = intgFakeVMProvider
return nil
},
)
map[string]bool{lib.VMServiceV1Alpha2FSS: true})

func TestVirtualMachineSetResourcePolicy(t *testing.T) {
_ = intgTests
suite.Register(t, "VirtualMachineSetResourcePolicy controller suite", nil /*intgTests*/, unitTests)

suite.Register(t, "VirtualMachineSetResourcePolicy controller suite", intgTests, unitTests)
}

var _ = BeforeSuite(suite.BeforeSuite)
Expand Down
9 changes: 5 additions & 4 deletions controllers/volume/v1alpha2/volume_controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ import (

volume "github.com/vmware-tanzu/vm-operator/controllers/volume/v1alpha2"
ctrlContext "github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
providerfake "github.com/vmware-tanzu/vm-operator/pkg/vmprovider/fake"
"github.com/vmware-tanzu/vm-operator/test/builder"
)

var intgFakeVMProvider = providerfake.NewVMProviderA2()

var suite = builder.NewTestSuiteForController(
var suite = builder.NewTestSuiteForControllerWithFSS(
volume.AddToManager,
func(ctx *ctrlContext.ControllerManagerContext, _ ctrlmgr.Manager) error {
ctx.VMProviderA2 = intgFakeVMProvider
return nil
},
)
map[string]bool{lib.VMServiceV1Alpha2FSS: true})

func TestVolume(t *testing.T) {
_ = intgTests
suite.Register(t, "Volume controller suite", nil /*intgTests*/, unitTests)

suite.Register(t, "Volume controller suite", intgTests, unitTests)
}

var _ = BeforeSuite(suite.BeforeSuite)
Expand Down
6 changes: 6 additions & 0 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
cnsv1alpha1 "github.com/vmware-tanzu/vm-operator/external/vsphere-csi-driver/pkg/syncer/cnsoperator/apis/cnsnodevmattachment/v1alpha1"

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
vmopv1alpha2 "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
"github.com/vmware-tanzu/vm-operator/pkg/context"
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/pkg/record"
"github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere"
)
Expand All @@ -49,6 +51,10 @@ func New(opts Options) (Manager, error) {
_ = netopv1alpha1.AddToScheme(opts.Scheme)
_ = topologyv1.AddToScheme(opts.Scheme)
_ = imgregv1a1.AddToScheme(opts.Scheme)

if lib.IsVMServiceV1Alpha2FSSEnabled() {
_ = vmopv1alpha2.AddToScheme(opts.Scheme)
}
// +kubebuilder:scaffold:scheme

// controller-runtime Client creates an Informer for each resource that we watch.
Expand Down
Loading

0 comments on commit 484e5b7

Please sign in to comment.