utils

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DestoryVMRequeueInterval = 10 * time.Second
View Source
const RequeueTimeout = 5 * time.Second

Variables

This section is empty.

Functions

func ContainsAlreadyExistsSubstring added in v0.4.3

func ContainsAlreadyExistsSubstring(err error) bool

func ContainsNoMatchSubstring added in v0.4.3

func ContainsNoMatchSubstring(err error) bool

func GenerateAffinityGroupName added in v0.4.3

func GenerateAffinityGroupName(csm infrav1.CloudStackMachine, capiMachine *capiv1.Machine) (string, error)

The computed affinity group name relevant to this machine.

func GetManagementOwnerRef

func GetManagementOwnerRef(capiMachine *capiv1.Machine) *meta.OwnerReference

GetManagementOwnerRef returns the reference object pointing to the CAPI machine's manager.

func GetOwnerOfKind added in v0.4.3

func GetOwnerOfKind(ctx context.Context, c clientPkg.Client, owned clientPkg.Object, owner clientPkg.Object) error

GetOwnerOfKind returns the Cluster object owning the current resource of passed kind.

func IsOwnerDeleted

func IsOwnerDeleted(ctx context.Context, client clientPkg.Client, capiMachine *capiv1.Machine) (bool, error)

IsOwnerDeleted returns a boolean if the owner of the CAPI machine has been deleted.

Types

type CloudStackBaseContext added in v0.4.3

type CloudStackBaseContext struct {
	Log         logr.Logger
	RequestCtx  context.Context
	Request     ctrl.Request
	CAPICluster *capiv1.Cluster
	CSCluster   *infrav1.CloudStackCluster
	Patcher     *patch.Helper
}

CloudStackBaseContext is the base CloudStack data structure created/copied for each reconciliation request to avoid concurrent member access.

type CloudStackReconcilerMethod added in v0.4.3

type CloudStackReconcilerMethod func() (ctrl.Result, error)

CloudStackReconcilerMethod is the method type used in RunReconciliationStages. Additional arguments can be added by wrapping this type in another function affectively currying them.

type ConcreteRunner added in v0.4.3

type ConcreteRunner interface {
	ReconcileDelete() (ctrl.Result, error)
	Reconcile() (ctrl.Result, error)
	GetReconcilationSubject() client.Object
}

type ReconcilerBase added in v0.4.3

type ReconcilerBase struct {
	BaseLogger logr.Logger
	Scheme     *runtime.Scheme
	K8sClient  client.Client
	CSClient   cloud.Client
}

ReconcilerBase is the base set of components we use in k8s reconcilers. These are items that are not copied for each reconciliation request, and must be written to with caution.

func (*ReconcilerBase) InitFromMgr added in v0.4.3

func (r *ReconcilerBase) InitFromMgr(mgr ctrl.Manager, client cloud.Client)

InitFromMgr just initiates a ReconcilerBase using given manager's fields/methods.

type ReconciliationRunner added in v0.4.3

type ReconciliationRunner struct {
	ReconcilerBase
	CloudStackBaseContext
	ReconciliationSubject client.Object // Underlying crd interface.
	ConditionalResult     bool          // Stores a conidtinal result for stringing if else type methods.

	ReconcileDelete CloudStackReconcilerMethod
	Reconcile       CloudStackReconcilerMethod
	CSUser          cloud.Client
	// contains filtered or unexported fields
}

ReconciliationRunner is the base structure used to run reconciliation methods and implements several.

func NewRunner added in v0.4.3

func NewRunner(concreteRunner ConcreteRunner, subject client.Object) ReconciliationRunner

func (*ReconciliationRunner) CheckIfPaused added in v0.4.3

func (r *ReconciliationRunner) CheckIfPaused() (ctrl.Result, error)

CheckIfPaused returns with requeue later set if paused.

func (*ReconciliationRunner) CheckOwnedCRDsForReadiness added in v0.4.3

func (r *ReconciliationRunner) CheckOwnedCRDsForReadiness(gvks ...schema.GroupVersionKind) CloudStackReconcilerMethod

CheckOwnedCRDsForReadiness queries for the readiness of CRDs of GroupVersionKind passed.

func (*ReconciliationRunner) CreateZone added in v0.4.3

func (r *ReconciliationRunner) CreateZone(zoneSpec infrav1.Zone) error

CreateZone generates a specified CloudStackZone CRD owned by the ReconcilationSubject.

func (*ReconciliationRunner) CreateZones added in v0.4.3

func (r *ReconciliationRunner) CreateZones(zoneSpecs []infrav1.Zone) CloudStackReconcilerMethod

CreateZones generates a CloudStackClusterZone CRD for each of the ReconcilationSubject's Zones. Returns a CloudStackReconcilerMethod to curry zoneSpecs.

func (*ReconciliationRunner) Else added in v0.4.3

func (*ReconciliationRunner) ForRequest added in v0.4.3

ForRequest sets the reconciliation request.

func (*ReconciliationRunner) GenerateIsolatedNetwork added in v0.4.3

func (r *ReconciliationRunner) GenerateIsolatedNetwork(name string) CloudStackReconcilerMethod

GenerateIsolatedNetwork of the passed name that's owned by the ReconciliationSubject.

func (*ReconciliationRunner) GetCAPICluster added in v0.4.3

func (r *ReconciliationRunner) GetCAPICluster() (ctrl.Result, error)

GetCAPICluster gets the CAPI cluster the reconciliation subject belongs to.

func (*ReconciliationRunner) GetCSCluster added in v0.4.3

func (r *ReconciliationRunner) GetCSCluster() (ctrl.Result, error)

GetCSCluster gets the CAPI cluster the reconciliation subject belongs to.

func (*ReconciliationRunner) GetObjectByName added in v0.4.3

func (r *ReconciliationRunner) GetObjectByName(name string, target client.Object, nameGetter ...func() string) CloudStackReconcilerMethod

GetObjectByName gets an object by name and type of object. The namespace is assumed to be the same as the ReconciliationSubject. Not found is not considered an error. Check the object after.

func (*ReconciliationRunner) GetOrCreateAffinityGroup added in v0.4.3

func (r *ReconciliationRunner) GetOrCreateAffinityGroup(name string, affinityType string, ag *infrav1.CloudStackAffinityGroup) CloudStackReconcilerMethod

GenerateIsolatedNetwork of the passed name that's owned by the ReconciliationSubject.

func (*ReconciliationRunner) GetOwnerOfKind added in v0.4.3

GetOwnerOfKind uses the ReconciliationSubject's owner references to get the owner object of kind passed.

func (*ReconciliationRunner) GetParent added in v0.4.3

GetParent returns the object owning the current resource of passed kind.

func (*ReconciliationRunner) GetReconcilationSubject added in v0.4.3

func (r *ReconciliationRunner) GetReconcilationSubject() client.Object

func (*ReconciliationRunner) GetReconciliationSubject added in v0.4.3

func (r *ReconciliationRunner) GetReconciliationSubject() (res ctrl.Result, reterr error)

GetReconcilationSubject gets the reconciliation subject of type defined by the concrete reconciler. It also sets up a patch helper at this point.

func (*ReconciliationRunner) GetZones added in v0.4.3

GetZones gets CloudStackZones owned by a CloudStackCluster via an ownership label.

func (*ReconciliationRunner) IfDeletionTimestampIsZero added in v0.4.3

func (*ReconciliationRunner) IsoNetMetaName added in v0.4.4

func (r *ReconciliationRunner) IsoNetMetaName(name string) string

func (*ReconciliationRunner) LogReconciliationSubject added in v0.4.3

func (r *ReconciliationRunner) LogReconciliationSubject() (ctrl.Result, error)

func (*ReconciliationRunner) NewChildObjectMeta added in v0.4.3

func (r *ReconciliationRunner) NewChildObjectMeta(name string) metav1.ObjectMeta

NewChildObjectMeta creates a meta object with ownership reference and labels matching the current cluster.

func (*ReconciliationRunner) PatchChangesBackToAPI added in v0.4.3

func (r *ReconciliationRunner) PatchChangesBackToAPI() (res ctrl.Result, retErr error)

PatchChangesBackToAPI patches changes to the ReconciliationSubject back to the appropriate API.

func (*ReconciliationRunner) RequeueIfCloudStackClusterNotReady added in v0.4.3

func (r *ReconciliationRunner) RequeueIfCloudStackClusterNotReady() (ctrl.Result, error)

RequeueIfCloudStackClusterNotReady requeues the reconciliation request if the CloudStackCluster is not ready.

func (*ReconciliationRunner) RequeueIfMissingBaseCRs added in v0.4.3

func (r *ReconciliationRunner) RequeueIfMissingBaseCRs() (ctrl.Result, error)

RequeueIfMissingBaseCRs checks that the ReconciliationSubject, CAPI Cluster, and CloudStackCluster objects were actually fetched and reques if not. The base reconciliation stages will continue even if not so as to allow deletion.

func (*ReconciliationRunner) RequeueWithMessage added in v0.4.3

func (r *ReconciliationRunner) RequeueWithMessage(msg string, keysAndValues ...interface{}) (ctrl.Result, error)

RequeueWithMessage is a convenience method to log requeue message and then return a result with RequeueAfter set.

func (*ReconciliationRunner) ReturnWrappedError added in v0.4.3

func (r *ReconciliationRunner) ReturnWrappedError(err error, msg string) (ctrl.Result, error)

ReturnWrappedError is a convenience method to log requeue message and then return a result with RequeueAfter set.

func (*ReconciliationRunner) RunBaseReconciliationStages added in v0.4.3

func (r *ReconciliationRunner) RunBaseReconciliationStages() (res ctrl.Result, retErr error)

RunBaseReconciliationStages runs the base reconciliation stages which are to setup the logger, get the reconciliation subject, get CAPI and CloudStackClusters, and call either r.Reconcile or r.ReconcileDelete.

func (*ReconciliationRunner) RunReconciliationStages added in v0.4.3

func (r *ReconciliationRunner) RunReconciliationStages(fns ...CloudStackReconcilerMethod) (ctrl.Result, error)

RunReconciliationStages runs CloudStackReconcilerMethods in order and exits if an error or requeue condition is set. On exit patches changes back to API.

func (*ReconciliationRunner) SetCSUser added in v0.4.3

func (r *ReconciliationRunner) SetCSUser() (ctrl.Result, error)

SetCSUser sets the CSUser client to any user that can operate in specified domain and account if specified.

func (*ReconciliationRunner) SetReconciliationSubjectToConcreteSubject added in v0.4.3

func (r *ReconciliationRunner) SetReconciliationSubjectToConcreteSubject(subject client.Object) CloudStackReconcilerMethod

SetReconciliationSubjectToConcreteSubject sets reconciliation subject to passed concrete object.

func (*ReconciliationRunner) SetReturnEarly added in v0.4.3

func (r *ReconciliationRunner) SetReturnEarly()

SetReturnEarly sets the runner to return early. This causes the runner to break from running further reconciliation stages and return whatever result the current method returns.

func (*ReconciliationRunner) SetupLogger added in v0.4.3

func (r *ReconciliationRunner) SetupLogger() (res ctrl.Result, retErr error)

SetupLogger sets up the reconciler's logger to log with name and namespace values.

func (*ReconciliationRunner) SetupPatcher added in v0.4.3

func (r *ReconciliationRunner) SetupPatcher() (res ctrl.Result, retErr error)

SetupPatcher initializes the patcher with the ReconciliationSubject. This must be done before changes to the ReconciliationSubject for changes to be patched back later.

func (*ReconciliationRunner) ShouldReturn added in v0.4.3

func (r *ReconciliationRunner) ShouldReturn(rslt ctrl.Result, err error) bool

RunReconciliationStage runs a CloudStackReconcilerMethod and returns a boolean to indicate whether that stage would have returned a result that cuts the process short or not.

func (*ReconciliationRunner) UsingBaseReconciler added in v0.4.3

func (r *ReconciliationRunner) UsingBaseReconciler(base ReconcilerBase) *ReconciliationRunner

func (*ReconciliationRunner) WithRequestCtx added in v0.4.3

func (r *ReconciliationRunner) WithRequestCtx(ctx context.Context) *ReconciliationRunner

WithRequestCtx sets the request context.

func (*ReconciliationRunner) ZoneMetaName added in v0.4.4

func (r *ReconciliationRunner) ZoneMetaName(zoneSpec infrav1.Zone) string

ZoneMetaName creates a meta name for a zone based on the cluster and zone information.

Jump to

Keyboard shortcuts

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