builder

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 86 Imported by: 0

Documentation

Overview

Package builder is a comment just to silence the linter.

Index

Constants

View Source
const (
	DummyVMIID                = "vmi-0123456789"
	DummyImageName            = "dummy-image-name"
	DummyClassName            = "dummyClassName"
	DummyVolumeName           = "dummy-volume-name"
	DummyPVCName              = "dummyPVCName"
	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")
	NetworkEnvVPC   = NetworkEnv("nsx-t-vpc")
	NetworkEnvNamed = NetworkEnv("named")

	NsxTLogicalSwitchUUID = "nsxt-dummy-ls-uuid"
	VPCLogicalSwitchUUID  = "vpc-dummy-ls-uuid"
)

Variables

This section is empty.

Functions

func AddDummyInstanceStorageVolumeA2 added in v1.8.5

func AddDummyInstanceStorageVolumeA2(vm *vmopv1.VirtualMachine)

func DummyAvailabilityZone

func DummyAvailabilityZone() *topologyv1.AvailabilityZone

func DummyBasicVirtualMachineA2 added in v1.8.5

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

func DummyClusterContentLibrary

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

func DummyClusterVirtualMachineImageA2 added in v1.8.5

func DummyClusterVirtualMachineImageA2(imageName string) *vmopv1.ClusterVirtualMachineImage

func DummyContentLibrary

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

func DummyInstanceStorageA2 added in v1.8.5

func DummyInstanceStorageA2() vmopv1.InstanceStorage

func DummyInstanceStorageVirtualMachineVolumesA2 added in v1.8.3

func DummyInstanceStorageVirtualMachineVolumesA2() []vmopv1.VirtualMachineVolume

func DummyNamedAvailabilityZone added in v1.8.6

func DummyNamedAvailabilityZone(name string) *topologyv1.AvailabilityZone

func DummyPersistentVolumeClaim

func DummyPersistentVolumeClaim() *corev1.PersistentVolumeClaim

func DummyResourceQuota

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

func DummyStorageClass

func DummyStorageClass() *storagev1.StorageClass

func DummyStoragePolicyQuota added in v1.8.6

func DummyStoragePolicyQuota(quotaName, quotaNs, className string) *cnsstoragev1.StoragePolicyQuota

func DummyVirtualMachineA2 added in v1.8.3

func DummyVirtualMachineA2() *vmopv1.VirtualMachine

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 DummyVirtualMachineImageA2 added in v1.8.5

func DummyVirtualMachineImageA2(imageName string) *vmopv1.VirtualMachineImage

func DummyVirtualMachinePublishRequestA2 added in v1.8.3

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

func DummyVirtualMachineServiceA2 added in v1.8.3

func DummyVirtualMachineServiceA2() *vmopv1.VirtualMachineService

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) 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) GetFirstClusterFromFirstZone added in v1.8.6

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

func (*TestContextForVCSim) GetFirstZoneName added in v1.8.6

func (c *TestContextForVCSim) GetFirstZoneName() string

func (*TestContextForVCSim) GetResourcePoolForNamespace

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

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 NewTestSuiteForControllerWithContext added in v1.8.6

func NewTestSuiteForControllerWithContext(
	ctx context.Context,
	addToManagerFn pkgmgr.AddToManagerFunc,
	initProvidersFn pkgmgr.InitializeProvidersFunc) *TestSuite

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

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 NewTestSuiteForMutatingWebhookWithContext added in v1.8.6

func NewTestSuiteForMutatingWebhookWithContext(
	ctx context.Context,
	addToManagerFn pkgmgr.AddToManagerFunc,
	newMutatorFn builder.MutatorFunc,
	webhookName string) *TestSuite

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

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 NewTestSuiteForValidatingWebhookWithContext added in v1.8.6

func NewTestSuiteForValidatingWebhookWithContext(
	ctx context.Context,
	addToManagerFn pkgmgr.AddToManagerFunc,
	newValidatorFn builder.ValidatorFunc,
	webhookName string) *TestSuite

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

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) GetManager added in v1.8.6

func (s *TestSuite) GetManager() pkgmgr.Manager

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) SetManagerNewCacheFunc added in v1.8.6

func (s *TestSuite) SetManagerNewCacheFunc(f ctrlcache.NewCacheFunc)

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 {
	// NumFaultDomains is the number of zones.
	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

	// WithNetworkEnv is the network environment type.
	WithNetworkEnv NetworkEnv

	// WithAutoVADPBackupRestore enables the WCP_VMSERVICE_BACKUPRESTORE FSS.
	WithAutoVADPBackupRestore bool
}

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