builder

package
v1.8.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 82 Imported by: 0

Documentation

Overview

Package builder is a comment just to silence the linter

Index

Constants

View Source
const (
	DummyImageName            = "dummy-image-name"
	DummyClassName            = "dummyClassName"
	DummyNetworkName          = "dummyNetworkName"
	DummyVolumeName           = "dummy-volume-name"
	DummyPVCName              = "dummyPVCName"
	DummyMetadataCMName       = "dummyMetadataCMName"
	DummyDistroVersion        = "dummyDistroVersion"
	DummyOSType               = "centosGuest"
	DummyStorageClassName     = "dummy-storage-class"
	DummyResourceQuotaName    = "dummy-resource-quota"
	DummyAvailabilityZoneName = "dummy-availability-zone"
)
View Source
const (
	NetworkEnvVDS   = NetworkEnv("vds")
	NetworkEnvNSXT  = NetworkEnv("nsx-t")
	NetworkEnvNamed = NetworkEnv("named")

	NsxTLogicalSwitchUUID = "nsxt-dummy-ls-uuid"
)
View Source
const (
	VMICRDName = "virtualmachineimages.vmoperator.vmware.com"
)

Variables

This section is empty.

Functions

func AddDummyInstanceStorageVolume

func AddDummyInstanceStorageVolume(vm *vmopv1.VirtualMachine)

func AddDummyInstanceStorageVolumeA2 added in v1.8.5

func AddDummyInstanceStorageVolumeA2(vm *vmopv1.VirtualMachine)

func DummyAvailabilityZone

func DummyAvailabilityZone() *topologyv1.AvailabilityZone

func DummyBasicVirtualMachine

func DummyBasicVirtualMachine(name, namespace string) *vmopv1.VirtualMachine

func DummyBasicVirtualMachineA2 added in v1.8.5

func DummyBasicVirtualMachineA2(name, namespace string) *vmopv1.VirtualMachine

func DummyClusterContentLibrary

func DummyClusterContentLibrary(name, uuid string) *imgregv1a1.ClusterContentLibrary

func DummyClusterVirtualMachineImage

func DummyClusterVirtualMachineImage(imageName string) *vmopv1.ClusterVirtualMachineImage

func DummyClusterVirtualMachineImageA2 added in v1.8.5

func DummyClusterVirtualMachineImageA2(imageName string) *vmopv1.ClusterVirtualMachineImage

func DummyContentLibrary

func DummyContentLibrary(name, namespace, uuid string) *imgregv1a1.ContentLibrary

func DummyContentSourceProviderAndBinding

func DummyContentSourceProviderAndBinding(uuid, namespace string) (
	*vmopv1.ContentSource,
	*vmopv1.ContentLibraryProvider,
	*vmopv1.ContentSourceBinding)

func DummyInstanceStorage

func DummyInstanceStorage() vmopv1.InstanceStorage

func DummyInstanceStorageA2 added in v1.8.5

func DummyInstanceStorageA2() vmopv1.InstanceStorage

func DummyInstanceStorageVirtualMachineVolumes

func DummyInstanceStorageVirtualMachineVolumes() []vmopv1.VirtualMachineVolume

func DummyInstanceStorageVirtualMachineVolumesA2 added in v1.8.3

func DummyInstanceStorageVirtualMachineVolumesA2() []vmopv1.VirtualMachineVolume

func DummyPersistentVolumeClaim

func DummyPersistentVolumeClaim() *corev1.PersistentVolumeClaim

func DummyResourceQuota

func DummyResourceQuota(namespace, rlName string) *corev1.ResourceQuota

func DummyStorageClass

func DummyStorageClass() *storagev1.StorageClass

func DummyVirtualMachine

func DummyVirtualMachine() *vmopv1.VirtualMachine

func DummyVirtualMachineA2 added in v1.8.3

func DummyVirtualMachineA2() *vmopv1.VirtualMachine

func DummyVirtualMachineClass

func DummyVirtualMachineClass() *vmopv1.VirtualMachineClass

func DummyVirtualMachineClass2A2 added in v1.8.5

func DummyVirtualMachineClass2A2(name string) *vmopv1.VirtualMachineClass

func DummyVirtualMachineClassA2 added in v1.8.3

func DummyVirtualMachineClassA2() *vmopv1.VirtualMachineClass

func DummyVirtualMachineClassAndBinding

func DummyVirtualMachineClassAndBinding(className, namespace string) (
	*vmopv1.VirtualMachineClass,
	*vmopv1.VirtualMachineClassBinding)

func DummyVirtualMachineClassBinding

func DummyVirtualMachineClassBinding(className, namespace string) *vmopv1.VirtualMachineClassBinding

func DummyVirtualMachineImage

func DummyVirtualMachineImage(imageName string) *vmopv1.VirtualMachineImage

func DummyVirtualMachineImageA2 added in v1.8.5

func DummyVirtualMachineImageA2(imageName string) *vmopv1.VirtualMachineImage

func DummyVirtualMachinePublishRequest

func DummyVirtualMachinePublishRequest(name, namespace, sourceName, itemName, clName string) *vmopv1.VirtualMachinePublishRequest

func DummyVirtualMachinePublishRequestA2 added in v1.8.3

func DummyVirtualMachinePublishRequestA2(name, namespace, sourceName, itemName, clName string) *vmopv1.VirtualMachinePublishRequest

func DummyVirtualMachineService

func DummyVirtualMachineService() *vmopv1.VirtualMachineService

func DummyVirtualMachineServiceA2 added in v1.8.3

func DummyVirtualMachineServiceA2() *vmopv1.VirtualMachineService

func DummyVirtualMachineSetResourcePolicy

func DummyVirtualMachineSetResourcePolicy() *vmopv1.VirtualMachineSetResourcePolicy

func DummyVirtualMachineSetResourcePolicy2

func DummyVirtualMachineSetResourcePolicy2(name, namespace string) *vmopv1.VirtualMachineSetResourcePolicy

func DummyVirtualMachineSetResourcePolicy2A2 added in v1.8.5

func DummyVirtualMachineSetResourcePolicy2A2(name, namespace string) *vmopv1.VirtualMachineSetResourcePolicy

func DummyVirtualMachineSetResourcePolicyA2 added in v1.8.3

func DummyVirtualMachineSetResourcePolicyA2() *vmopv1.VirtualMachineSetResourcePolicy

func DummyVirtualMachineWebConsoleRequest added in v1.8.5

func DummyVirtualMachineWebConsoleRequest(namespace, wcrName, vmName, pubKey string) *vmopv1.VirtualMachineWebConsoleRequest

func DummyWebConsoleRequest

func DummyWebConsoleRequest(namespace, wcrName, vmName, pubKey string) *vmopv1.WebConsoleRequest

func KnownObjectTypes added in v1.8.5

func KnownObjectTypes() []client.Object

KnownObjectTypes has the known VM operator types that will be status enabled when initializing the fake client. Add any types here if the fake client needs to patch the Status sub-resource of that resource type.

func LoadCRDs added in v1.8.5

func LoadCRDs(rootFilePath string) ([]*apiextensionsv1.CustomResourceDefinition, error)

func NewFakeClient

func NewFakeClient(objs ...client.Object) client.Client

func NewFakeRecorder

func NewFakeRecorder() (record.Recorder, chan string)

func NewScheme

func NewScheme() *runtime.Scheme

func ToUnstructured

func ToUnstructured(obj runtime.Object) (*unstructured.Unstructured, error)

func WebConsoleRequestKeyPair

func WebConsoleRequestKeyPair() (privateKey *rsa.PrivateKey, publicKeyPem string)

Types

type IntegrationTestContext

type IntegrationTestContext struct {
	context.Context
	Client       client.Client
	Namespace    string
	PodNamespace string
}

IntegrationTestContext is used for integration testing. Each IntegrationTestContext contains one separate namespace.

func (*IntegrationTestContext) AfterEach

func (ctx *IntegrationTestContext) AfterEach()

AfterEach should be invoked by ginkgo.AfterEach to destroy the test namespace.

type NetworkEnv added in v1.8.1

type NetworkEnv string

type NewReconcilerFunc

type NewReconcilerFunc func() Reconciler

NewReconcilerFunc is a base type for functions that return a reconciler.

type Reconciler

type Reconciler interface{}

Reconciler is a base type for builder's reconcilers.

type TestContextForVCSim

type TestContextForVCSim struct {
	// NOTE: Unit test in the context of test suite framework means we use
	// the fake k8s client, which is sufficient for our needs. Otherwise,
	// unit testing is a little misleading here since we're using vcsim.
	*UnitTestContext

	PodNamespace string
	VCClient     *govmomi.Client
	Datacenter   *object.Datacenter
	Finder       *find.Finder
	RestClient   *rest.Client
	Recorder     record.Recorder

	// When WithFaultDomains is true:
	ZoneCount       int
	ClustersPerZone int
	ZoneNames       []string

	// When WithContentLibrary is true:
	ContentLibraryImageName string
	ContentLibraryID        string

	// When WithoutStorageClass is false:
	StorageClassName string
	StorageProfileID string

	NetworkRef object.NetworkReference
	// contains filtered or unexported fields
}

func (*TestContextForVCSim) AfterEach

func (c *TestContextForVCSim) AfterEach()

AfterEach is a comment just to silence the linter TODO: Once we update ginkgo, this is more suitable as an AfterAll().

func (*TestContextForVCSim) ContentLibraryItemTemplate

func (c *TestContextForVCSim) ContentLibraryItemTemplate(srcVMName, templateName string)

func (*TestContextForVCSim) CreateVirtualMachineSetResourcePolicy

func (c *TestContextForVCSim) CreateVirtualMachineSetResourcePolicy(
	name string,
	nsInfo WorkloadNamespaceInfo) (*v1alpha1.VirtualMachineSetResourcePolicy, *object.Folder)

func (*TestContextForVCSim) CreateVirtualMachineSetResourcePolicyA2 added in v1.8.5

func (c *TestContextForVCSim) CreateVirtualMachineSetResourcePolicyA2(
	name string,
	nsInfo WorkloadNamespaceInfo) (*v1alpha2.VirtualMachineSetResourcePolicy, *object.Folder)

func (*TestContextForVCSim) CreateWorkloadNamespace

func (c *TestContextForVCSim) CreateWorkloadNamespace() WorkloadNamespaceInfo

func (*TestContextForVCSim) GetAZClusterComputes

func (c *TestContextForVCSim) GetAZClusterComputes(azName string) []*object.ClusterComputeResource

func (*TestContextForVCSim) GetResourcePoolForNamespace

func (c *TestContextForVCSim) GetResourcePoolForNamespace(namespace, azName, childName string) *object.ResourcePool

func (*TestContextForVCSim) GetSingleClusterCompute

func (c *TestContextForVCSim) GetSingleClusterCompute() *object.ClusterComputeResource

func (*TestContextForVCSim) GetVMFromMoID

func (c *TestContextForVCSim) GetVMFromMoID(moID string) *object.VirtualMachine

type TestSuite

type TestSuite struct {
	context.Context
	// contains filtered or unexported fields
}

TestSuite is used for unit and integration testing builder. Each TestSuite contains one independent test environment and a controller manager.

func NewFunctionalTestSuite

func NewFunctionalTestSuite(addToManagerFunc func(ctx *ctrlCtx.ControllerManagerContext, mgr manager.Manager) error) *TestSuite

NewFunctionalTestSuite returns a new test suite used for functional tests. The functional test starts all the controllers, and creates all the providers so it is a more fully functioning env than an integration test with a single controller running.

func NewTestSuite

func NewTestSuite() *TestSuite

NewTestSuite returns a new test suite used for unit and/or integration test.

func NewTestSuiteForController

func NewTestSuiteForController(addToManagerFn pkgmgr.AddToManagerFunc, initProvidersFn pkgmgr.InitializeProvidersFunc) *TestSuite

NewTestSuiteForController returns a new test suite used for controller integration test.

func NewTestSuiteForControllerWithFSS

func NewTestSuiteForControllerWithFSS(addToManagerFn pkgmgr.AddToManagerFunc,
	initProvidersFn pkgmgr.InitializeProvidersFunc, fssMap map[string]bool) *TestSuite

NewTestSuiteForControllerWithFSS returns a new test suite used for controller integration test with FSS set.

func NewTestSuiteForMutatingWebhook

func NewTestSuiteForMutatingWebhook(
	addToManagerFn pkgmgr.AddToManagerFunc,
	newMutatorFn builder.MutatorFunc,
	webhookName string) *TestSuite

NewTestSuiteForMutatingWebhook returns a new test suite used for unit and integration testing mutating webhooks created using the "pkg/builder" package.

func NewTestSuiteForMutatingWebhookwithFSS added in v1.8.5

func NewTestSuiteForMutatingWebhookwithFSS(
	addToManagerFn pkgmgr.AddToManagerFunc,
	newMutatorFn builder.MutatorFunc,
	webhookName string,
	fssMap map[string]bool) *TestSuite

NewTestSuiteForMutatingWebhookwithFSS returns a new test suite used for unit and integration testing mutating webhooks created using the "pkg/builder" package with FSS set.

func NewTestSuiteForValidatingWebhook

func NewTestSuiteForValidatingWebhook(
	addToManagerFn pkgmgr.AddToManagerFunc,
	newValidatorFn builder.ValidatorFunc,
	webhookName string) *TestSuite

NewTestSuiteForValidatingWebhook returns a new test suite used for unit and integration testing validating webhooks created using the "pkg/builder" package.

func NewTestSuiteForValidatingWebhookwithFSS added in v1.8.5

func NewTestSuiteForValidatingWebhookwithFSS(
	addToManagerFn pkgmgr.AddToManagerFunc,
	newValidatorFn builder.ValidatorFunc,
	webhookName string,
	fssMap map[string]bool) *TestSuite

NewTestSuiteForValidatingWebhookwithFSS returns a new test suite used for unit and integration testing validating webhooks created using the "pkg/builder" package with FSS set.

func (*TestSuite) AfterSuite

func (s *TestSuite) AfterSuite()

AfterSuite should be invoked by ginkgo.AfterSuite.

func (*TestSuite) BeforeSuite

func (s *TestSuite) BeforeSuite()

BeforeSuite should be invoked by ginkgo.BeforeSuite.

func (*TestSuite) GetEnvTestConfig

func (s *TestSuite) GetEnvTestConfig() *rest.Config

func (*TestSuite) GetInstalledCRD

func (s *TestSuite) GetInstalledCRD(crdName string) *apiextensionsv1.CustomResourceDefinition

func (*TestSuite) GetLogger

func (s *TestSuite) GetLogger() logr.Logger

func (*TestSuite) NewIntegrationTestContext

func (s *TestSuite) NewIntegrationTestContext() *IntegrationTestContext

NewIntegrationTestContext should be invoked by ginkgo.BeforeEach

This function creates a namespace with a random name to separate integration test cases

This function returns a TestSuite context The resources created by this function may be cleaned up by calling AfterEach with the IntegrationTestContext returned by this function.

func (*TestSuite) NewTestContextForVCSim

func (s *TestSuite) NewTestContextForVCSim(
	config VCSimTestConfig,
	initObjects ...client.Object) *TestContextForVCSim

func (*TestSuite) NewUnitTestContextForController

func (s *TestSuite) NewUnitTestContextForController(initObjects ...client.Object) *UnitTestContextForController

NewUnitTestContextForController returns a new unit test context for this suite's reconciler.

Returns nil if unit testing is disabled.

func (*TestSuite) NewUnitTestContextForMutatingWebhook

func (s *TestSuite) NewUnitTestContextForMutatingWebhook(obj *unstructured.Unstructured) *UnitTestContextForMutatingWebhook

NewUnitTestContextForMutatingWebhook returns a new unit test context for this suite's mutator.

Returns nil if unit testing is disabled.

func (*TestSuite) NewUnitTestContextForValidatingWebhook

func (s *TestSuite) NewUnitTestContextForValidatingWebhook(
	obj, oldObj *unstructured.Unstructured,
	initObjects ...client.Object) *UnitTestContextForValidatingWebhook

NewUnitTestContextForValidatingWebhook returns a new unit test context for this suite's validator.

Returns nil if unit testing is disabled.

func (*TestSuite) Register

func (s *TestSuite) Register(t *testing.T, name string, runIntegrationTestsFn, runUnitTestsFn func())

Register should be invoked by the function to which *testing.T is passed.

Use runUnitTestsFn to pass a function that will be invoked if unit testing is enabled with Describe("Unit tests", runUnitTestsFn).

Use runIntegrationTestsFn to pass a function that will be invoked if integration testing is enabled with Describe("Unit tests", runIntegrationTestsFn).

func (*TestSuite) UpdateCRDScope

func (s *TestSuite) UpdateCRDScope(oldCrd *apiextensionsv1.CustomResourceDefinition, newScope string)

type UnitTestContext

type UnitTestContext struct {
	goctx.Context
	Client client.Client
	Scheme *runtime.Scheme
}

UnitTestContext is used for general purpose unit testing.

func NewUnitTestContext

func NewUnitTestContext(initObjects ...client.Object) *UnitTestContext

NewUnitTestContext returns a new UnitTestContext.

func (*UnitTestContext) AfterEach

func (ctx *UnitTestContext) AfterEach()

AfterEach should be invoked by ginkgo.AfterEach to cleanup.

type UnitTestContextForController

type UnitTestContextForController struct {
	// context is the context.ControllerManagerContext for being tested.
	context.ControllerManagerContext

	// Client is the k8s client to access resources.
	Client client.Client

	// reconciler is the reconcile.Reconciler being unit tested.
	Reconciler reconcile.Reconciler

	// Events is a channel that fake recorder records events to.
	Events chan string
}

UnitTestContextForController is used for unit testing controllers.

func NewUnitTestContextForController

func NewUnitTestContextForController(initObjects []client.Object) *UnitTestContextForController

NewUnitTestContextForController returns a new UnitTestContextForController for unit testing controllers.

func (*UnitTestContextForController) AfterEach

func (ctx *UnitTestContextForController) AfterEach()

AfterEach should be invoked by ginkgo.AfterEach to cleanup.

type UnitTestContextForMutatingWebhook

type UnitTestContextForMutatingWebhook struct {
	// WebhookRequestContext is initialized with fake.NewWebhookRequestContext
	// and is used for unit testing.
	context.WebhookRequestContext

	// Client is the k8s client to access resources.
	Client client.Client

	// Key may be used to lookup Ctx.Cluster with Ctx.Client.Get.
	Key client.ObjectKey

	// mutator is the builder.Mutator being unit tested.
	builder.Mutator
}

UnitTestContextForMutatingWebhook is used for unit testing mutating webhooks.

func NewUnitTestContextForMutatingWebhook

func NewUnitTestContextForMutatingWebhook(
	mutatorFn builder.MutatorFunc,
	obj *unstructured.Unstructured) *UnitTestContextForMutatingWebhook

NewUnitTestContextForMutatingWebhook returns a new UnitTestContextForMutatingWebhook for unit testing mutating webhooks.

type UnitTestContextForValidatingWebhook

type UnitTestContextForValidatingWebhook struct {
	// WebhookRequestContext is initialized with fake.NewWebhookRequestContext
	// and is used for unit testing.
	context.WebhookRequestContext

	// Client is the k8s client to access resources.
	Client client.Client

	// Key may be used to lookup Ctx.Obj with Ctx.Client.Get.
	Key client.ObjectKey

	// validator is the builder.Validator being unit tested.
	builder.Validator
}

UnitTestContextForValidatingWebhook is used for unit testing validating webhooks.

func NewUnitTestContextForValidatingWebhook

func NewUnitTestContextForValidatingWebhook(
	validatorFn builder.ValidatorFunc,
	obj, oldObj *unstructured.Unstructured,
	initObjects ...client.Object) *UnitTestContextForValidatingWebhook

NewUnitTestContextForValidatingWebhook returns a new UnitTestContextForValidatingWebhook for unit testing validating webhooks.

type VCSimTestConfig

type VCSimTestConfig struct {
	// WithFaultDomains enables the HA WCP_FAULTDOMAINS_FSS.
	WithFaultDomains bool

	// NumFaultDomains is the number of zones when WithFaultDomains is true.
	NumFaultDomains int

	// WithContentLibrary configures a Content Library, populated with one image's
	// name available in the TestContextForVCSim.ContentLibraryImageName.
	WithContentLibrary bool

	// WithInstanceStorage enables the WCP_INSTANCE_STORAGE FSS.
	WithInstanceStorage bool

	// WithoutStorageClass disables the storage class required, meaning that the
	// Datastore will be used instead. In WCP production the storage class is
	// always required; the Datastore is only needed for gce2e.
	WithoutStorageClass bool

	// WithJSONExtraConfig enables additional ExtraConfig that is included when
	// creating a VM.
	WithJSONExtraConfig string

	// WithDefaultNetwork string sets the default network VM NICs will use.
	// In WCP production this is never set; it only exists for current
	// limitations of gce2e.
	WithDefaultNetwork string

	// WithVMClassAsConfig enables the WCP_VM_CLASS_AS_CONFIG FSS.
	WithVMClassAsConfig bool

	// WithVMClassAsConfigDaynDate enables the WCP_VM_CLASS_AS_CONFIG_DAYNDATE FSS.
	WithVMClassAsConfigDaynDate bool

	// WithV1A2 enables the VMServiceV1Alpha2FSS FSS.
	WithV1A2 bool

	// WithNetworkEnv is the network environment type.
	WithNetworkEnv NetworkEnv
}

VCSimTestConfig configures the vcsim environment.

type WorkloadNamespaceInfo

type WorkloadNamespaceInfo struct {
	Namespace string
	Folder    *object.Folder
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL