common

package
v2.0.8+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceCreated    = "Created"
	ResourceUpdated    = "Updated"
	ResourceDeleted    = "Deleted"
	ResourceWait       = "Wait"
	ResourceDependency = "Dependency"
)

Common event record reasons

View Source
const (
	NoChangesAfterReconciled           = "configuration changes ignored after initial synchronization has completed"
	ChangedAllowedAfterReconciled      = "manual override; allowing configuration changes after initial synchronization"
	NoProvisioningAfterReconciled      = "resource provisioning ignored after initial synchronization has completed"
	ProvisioningAllowedAfterReconciled = "manual override; allowing resource provisioning after initial synchronization"
)

Defines common log strings from commonly performed validation checks across all different reconcilers.

Variables

View Source
var (
	// RetryImmediate should be used whenever a known transient error is
	// detected and there is a very likely that retrying immediately will
	// succeed.  For example,
	RetryImmediate = reconcile.Result{Requeue: true, RequeueAfter: time.Second}

	// RetrySystemNotReady should be used whenever a controller needs to wait
	// for the system controller to finish its reconcile task.  The system
	// controller kicks the other controllers when it has finish so there
	// is no need to automatically requeue these events.
	RetrySystemNotReady = reconcile.Result{Requeue: false}

	// RetryMissingClient should be used for any object reconciliation that
	// fails because of the platform client is missing or was reset.  The system
	// controller is responsible for re-creating the client and it will kick
	// the other controllers once it has re-established a connection to the
	// target system.
	RetryMissingClient = reconcile.Result{Requeue: false}

	// RetryTransientError should be used for any object reconciliation that
	// fails because of a transient error and needs to be re-attempted at a
	// future time.
	RetryTransientError = reconcile.Result{Requeue: true, RequeueAfter: 20 * time.Second}

	// RetryUserError should be used for any errors caught after an API request
	// that is likely due to data validation errors.  These could theoretically
	// not retry and just sit and wait for the user to correct the error, but
	// to mitigate against dependency errors or transient errors we will retry.
	RetryUserError = reconcile.Result{Requeue: true, RequeueAfter: time.Minute}

	// RetryValidationError should be used for any errors resulting from an
	// upfront validation error.  There is no point in trying again since the
	// data is invalid.  Just wait for the user to correct the issue.
	RetryValidationError = reconcile.Result{Requeue: false}

	// RetryServerError should be used for any errors caught after an API
	// request that is likely due to internal server errors.  These could
	// theoretically not retry and just sit and wait for the user to correct the
	// error, but to mitigate against dependency errors or transient errors we
	// will retry.
	RetryServerError = reconcile.Result{Requeue: true, RequeueAfter: time.Minute}

	// RetryNetworkError should be used for any DNS resolution errors.  There
	// is a good chance that these errors will persist for a while until the
	// user intervenes so slow down retry attempts.
	RetryResolutionError = reconcile.Result{Requeue: true, RequeueAfter: 5 * time.Minute}

	// RetryNetworkError should be used for any errors caught after a API
	// request that is likely due to network errors.  This could happen
	// because of a misconfiguration of the endpoint URL or whenever the system
	// becomes temporarily unreachable.  We need to retry until the system
	// becomes reachable.  Since the most likely explanation is that the
	// active controller was rebooted then it makes sense to keep retrying
	// frequently because it will come back relatively quickly.
	// TODO(alegacy): consider backing off using a rate limiter queue.
	RetryNetworkError = reconcile.Result{Requeue: true, RequeueAfter: 15 * time.Second}

	// RetryNever is used when the reconciler will be triggered by a separate
	// mechanism and no retry is necessary.
	RetryNever = reconcile.Result{Requeue: false}
)
View Source
var DefaultMergeTransformer = MergeTransformer{OverwriteSlices: true}

DefaultMergeTransformer defines the default behaviour used throughout this package.

Functions

func FormatStruct

func FormatStruct(obj interface{}) string

func NewChangeAfterInSync

func NewChangeAfterInSync(msg string) error

NewChangeAfterInSync defines a constructor for the ChangeAfterReconciled error type.

func NewHTTPSClientRequired

func NewHTTPSClientRequired(msg string) error

NewHTTPSClientRequired defines a constructor for the HTTPClientRequired error type.

func NewMissingKubernetesResource

func NewMissingKubernetesResource(msg string) error

NewMissingKubernetesResource defines a constructor for the ErrMissingKubernetesResource error type.

func NewResourceConfigurationDependency

func NewResourceConfigurationDependency(msg string) error

NewResourceConfigurationDependency defines a constructor for the ErrResourceStatusDependency error type.

func NewResourceStatusDependency

func NewResourceStatusDependency(msg string) error

NewResourceStatusDependency defines a constructor for the ErrResourceStatusDependency error type.

func NewSystemDependency

func NewSystemDependency(msg string) error

NewSystemDependency defines a constructor for the ErrSystemDependency error type.

func NewUserDataError

func NewUserDataError(msg string) error

NewUserDataError defines a constructor for the ErrUserDataError error type.

func NewValidationError

func NewValidationError(msg string) error

NewValidationError defines a constructor for the ValidationError error type.

Types

type BaseError

type BaseError struct {
	// contains filtered or unexported fields
}

BaseError defines the common error reporting struct for all other errors defined in this package

func (BaseError) Error added in v1.0.0

func (in BaseError) Error() string

Error implements the Error interface for all structures that are derived from this one.

type ChangeAfterReconciled added in v1.0.0

type ChangeAfterReconciled struct {
	BaseError
}

ChangeAfterReconciled defines a new error type used to signal that a a configuration changes was received after the resource has already been synchronized with the system state.

type ErrMissingKubernetesResource

type ErrMissingKubernetesResource struct {
	BaseError
}

ErrMissingKubernetesResource defines an error to be used when reporting that an operation is unable to find a required resource from the kubernetes API. This error is not intended for system resources that are missing. For those use ErrMissingSystemResource

type ErrResourceStatusDependency

type ErrResourceStatusDependency struct {
	BaseError
}

ErrResourceStatusDependency defines an error to be used when reporting that an operation is unable to continue because a resource is not in the correct state.

type ErrSystemDependency

type ErrSystemDependency struct {
	BaseError
}

ErrSystemDependency defines an error to be used when reporting that the system itself or a set of multiple resources are not in the correct state to proceed with an operation.

type ErrUserDataError

type ErrUserDataError struct {
	BaseError
}

ErrUserDataError defines an error to be used when reporting that an operation is unable to continue because the requested configuration is incorrect or incomplete.

type ErrorHandler

type ErrorHandler struct {
	logr.Logger
	manager.CloudManager
}

ErrorHandler is the common implementation of the ReconcilerErrorHandler interface.

func (*ErrorHandler) HandleReconcilerError

func (h *ErrorHandler) HandleReconcilerError(request reconcile.Request, in error) (result reconcile.Result, err error)

HandleReconcilerError is the common error handler implementation for all controllers. It is responsible for looking at the type of error that was caught and determine what the best resolution might be.

type EventLogger

type EventLogger struct {
	record.EventRecorder
	logr.Logger
}

EventLogger is an implementation of a ReconcilerEventLogger. Its purpose is to simultaneously generate a log with every event and to prefix each event message with the object name.

func (*EventLogger) NormalEvent

func (in *EventLogger) NormalEvent(object runtime.Object, reason string, messageFmt string, args ...interface{})

NormalEvent generates a log and event for a "normal" event.

func (*EventLogger) WarningEvent

func (in *EventLogger) WarningEvent(object runtime.Object, reason string, messageFmt string, args ...interface{})

WarningEvent generates a log and event for a "warning" event. The intent is that this should only be used when declaring a reconciler error... all other events should use "NormalEvent".

type HTTPSClientRequired

type HTTPSClientRequired struct {
	BaseError
}

HTTPSClientRequired defines a new error type used to signal that a a configuration changes requires an HTTPS URL before continuing.

type MergeTransformer

type MergeTransformer struct {
	OverwriteSlices bool
}

MergeTransformer defines a struct used to pass behaviour attributes to the merge function so that our transformer can be controller from outside of the mergo API.

func (MergeTransformer) Transformer

func (t MergeTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error

Transformer implements a struct merge strategy for arrays and slices. The default mergo approach to merging slices is to leave them intact unless the AppendSlices modifier is used. That would cause both the parent and subclass arrays to be concatenated together. This transformer provides a way to replace individual array elements if they are found to match an element in the destination array. This is only possible if the array element structs implement the IsKeyEqual method.

type ReconcilerErrorHandler

type ReconcilerErrorHandler interface {
	HandleReconcilerError(request reconcile.Request, in error) (reconcile.Result, error)
}

ReconcilerErrorHandler defines the interface type associated to any reconciler error handler.

type ReconcilerEventLogger

type ReconcilerEventLogger interface {
	NormalEvent(object runtime.Object, reason string, messageFmt string, args ...interface{})
	WarningEvent(object runtime.Object, reason string, messageFmt string, args ...interface{})
}

ReconcilerEventLogger is an interface that is intended to allow specialized behavior when generating an event.

type ValidationError

type ValidationError struct {
	BaseError
}

ValidationError defines a new error type used to differentiate data validation errors from other types of errors.

Jump to

Keyboard shortcuts

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