utils

package
v0.4.10-rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 25 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 *clusterv1.Machine, capiCluster *clusterv1.Cluster) (string, error)

The computed affinity group name relevant to this machine.

func GetManagementOwnerRef

func GetManagementOwnerRef(capiMachine *clusterv1.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 *clusterv1.Machine) (bool, error)

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

func WithClusterSuffix

func WithClusterSuffix(name string, clusterName string) string

WithClusterSuffix appends a hyphen and the cluster name to a name if not already present.

Types

type CloudClientExtension

type CloudClientExtension interface {
	RegisterExtension(*ReconciliationRunner) CloudClientExtension
	AsFailureDomainUser(*infrav1.CloudStackFailureDomainSpec) CloudStackReconcilerMethod
}

type CloudClientImplementation

type CloudClientImplementation struct {
	CloudClientExtension
	*ReconciliationRunner
}

func (*CloudClientImplementation) AsFailureDomainUser

AsFailureDomainUser uses the credentials specified in the failure domain to set the ReconciliationSubject's CSUser client.

func (*CloudClientImplementation) RegisterExtension

type CloudStackBaseContext

type CloudStackBaseContext struct {
	Log         logr.Logger
	RequestCtx  context.Context
	Request     ctrl.Request
	CAPICluster *clusterv1.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)
}

type ReconcilerBase

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

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
	CloudClientExtension
	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
	ControllerKind  string
	// 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, kind string) *ReconciliationRunner

NewRunner creates a new ReconciliationRunner pointing to the concrete reconciliation subject.

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) CheckOwnedObjectsDeleted

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

CheckOwnedObjectsDeleted queries for the presence of owned objects and requeues if any are still present. Primarily used to prevent deletions of owners before dependents.

func (*ReconciliationRunner) CheckPresent

CheckPresent checks that each object given was fetched.

func (*ReconciliationRunner) CreateFailureDomain

func (r *ReconciliationRunner) CreateFailureDomain(fdSpec infrav1.CloudStackFailureDomainSpec) error

CreateFailureDomain creates a specified CloudStackFailureDomain CRD owned by the ReconcilationSubject.

func (*ReconciliationRunner) CreateFailureDomains

CreateFailureDomains creates a CloudStackFailureDomain CRD for each of the ReconcilationSubject's FailureDomains.

func (*ReconciliationRunner) DeleteOwnedObjects

CheckOwnedObjectsDeleted queries for the presence of owned objects and requeues if any are still present. Primarily used to prevent deletions of owners before dependents.

func (*ReconciliationRunner) Else

Else can be used to run a different stage if a previous conditional was false.

func (*ReconciliationRunner) ForRequest

ForRequest sets the reconciliation request.

func (*ReconciliationRunner) GenerateIsolatedNetwork

func (r *ReconciliationRunner) GenerateIsolatedNetwork(name string, fdNameFunc func() 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) GetFailureDomainByName

func (r *ReconciliationRunner) GetFailureDomainByName(nameFunc func() string, fd *infrav1.CloudStackFailureDomain) CloudStackReconcilerMethod

GetFailureDomainByName gets a single FailureDomain by name and requeues if it's not found.

func (*ReconciliationRunner) GetFailureDomains

GetFailureDomains gets CloudStackFailureDomains owned by a CloudStackCluster.

func (*ReconciliationRunner) GetFailureDomainsAndRequeueIfMissing

func (r *ReconciliationRunner) GetFailureDomainsAndRequeueIfMissing(fds *infrav1.CloudStackFailureDomainList) CloudStackReconcilerMethod

GetFailureDomainsAndRequeueIfMissing gets CloudStackFailureDomains owned by a CloudStackCluster and requeues if none are found.

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

GetOrCreateAffinityGroup of the passed name that's owned by the failure domain of the reconciliation subject and the control plane that manages it.

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) 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) 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) RemoveExtraneousFailureDomains

RemoveExtraneousFailureDomains deletes failure domains no longer listed under the CloudStackCluster's spec.

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) RunIf

RunIf accepts a conditional method and CloudStackReconcilerMethod and runs the CloudStackBaseContext if the conditional method is true.

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) 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

UsingBaseReconciler sets up the reconciler to use base reconciler data and either default or alternative feature implementations.

func (*ReconciliationRunner) WithAdditionalCommonStages

func (r *ReconciliationRunner) WithAdditionalCommonStages(fns ...CloudStackReconcilerMethod) *ReconciliationRunner

WithAdditionalCommonStages adds reconciliation stages to the base set of reconciliation stages ran before both Reconcile() and ReconcileDelete().

func (*ReconciliationRunner) WithRequestCtx

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

WithRequestCtx sets the request context.

Jump to

Keyboard shortcuts

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