utils

package
v0.4.6-rc1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 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

func ContainsAlreadyExistsSubstring(err error) bool

func ContainsNoMatchSubstring

func ContainsNoMatchSubstring(err error) bool

func GenerateAffinityGroupName

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

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

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

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

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

type ReconcilerBase

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

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

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

type ReconciliationRunner

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

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

func (*ReconciliationRunner) CheckIfPaused

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

CheckIfPaused returns with requeue later set if paused.

func (*ReconciliationRunner) CheckOwnedCRDsForReadiness

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

CheckOwnedCRDsForReadiness queries for the readiness of CRDs of GroupVersionKind passed.

func (*ReconciliationRunner) CreateZone

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

CreateZone generates a specified CloudStackZone CRD owned by the ReconcilationSubject.

func (*ReconciliationRunner) CreateZones

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

func (*ReconciliationRunner) ForRequest

ForRequest sets the reconciliation request.

func (*ReconciliationRunner) GenerateIsolatedNetwork

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

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

func (*ReconciliationRunner) GetCAPICluster

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

GetCAPICluster gets the CAPI cluster the reconciliation subject belongs to.

func (*ReconciliationRunner) GetCSCluster

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

GetCSCluster gets the CAPI cluster the reconciliation subject belongs to.

func (*ReconciliationRunner) GetObjectByName

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

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

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

func (*ReconciliationRunner) GetParent

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

func (*ReconciliationRunner) GetReconcilationSubject

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

func (*ReconciliationRunner) GetReconciliationSubject

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

GetZones gets CloudStackZones owned by a CloudStackCluster.

func (*ReconciliationRunner) GetZonesAndRequeueIfMissing

func (r *ReconciliationRunner) GetZonesAndRequeueIfMissing(zones *infrav1.CloudStackZoneList) CloudStackReconcilerMethod

GetZonesAndRequeueIfMissing gets CloudStackZones owned by a CloudStackCluster and requeues if none are found.

func (*ReconciliationRunner) IfDeletionTimestampIsZero

func (*ReconciliationRunner) IsoNetMetaName

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

func (*ReconciliationRunner) LogReconciliationSubject

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

func (*ReconciliationRunner) NewChildObjectMeta

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

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

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

func (*ReconciliationRunner) RequeueIfCloudStackClusterNotReady

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

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

func (*ReconciliationRunner) RequeueIfMissingBaseCRs

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

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

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

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

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

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

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

SetReconciliationSubjectToConcreteSubject sets reconciliation subject to passed concrete object.

func (*ReconciliationRunner) SetReturnEarly

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

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

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

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

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

func (*ReconciliationRunner) WithRequestCtx

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

WithRequestCtx sets the request context.

func (*ReconciliationRunner) ZoneMetaName

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