sync

package
v0.27.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRecognizedObject added in v0.18.0

func IsRecognizedObject(specObj crclient.Object) bool

IsRecognizedObject returns whether the provided object kind is recognized by the sync package to support updating existing objects on the cluster. If the object is not recognized, passing it to SyncObjectWithCluster will fail. Instead, SyncUnrecognizedObjectWithCluster should be used.

func SyncObjectWithCluster

func SyncObjectWithCluster(specObj crclient.Object, api ClusterAPI) (crclient.Object, error)

SyncObjectWithCluster synchronises the state of specObj to the cluster, creating or updating the cluster object as required. If specObj is in sync with the cluster, returns the object as it exists on the cluster. Returns a NotInSyncError if an update is required, UnrecoverableSyncError if object provided is invalid, or generic error if an unexpected error is encountered

func SyncUnrecognizedObjectWithCluster added in v0.18.0

func SyncUnrecognizedObjectWithCluster(specObj crclient.Object, api ClusterAPI) (crclient.Object, error)

SyncUnrecognizedObjectWithCluster allows syncing objects not supported by SyncObjectWithCluster. As there is no generic way of deciding if an object needs to be updated, a WarningError is returned if the object exists on the cluster. The only object updating performed by this function is to ensure labels/annotations and ownerReferences in specObj are synced to the cluster. The reason arbitrary updates are not supported is 1) certain objects have defaulted fields that can always trigger naive diff checks (causing reconciles to get stuck), and 2) it's unknown which fields are unmodifiable, (e.g. services must keep ClusterIP once set; pod fields cannot be changed after creation)

Types

type ClusterAPI

type ClusterAPI struct {
	Client           crclient.Client
	NonCachingClient crclient.Client
	Scheme           *runtime.Scheme
	Logger           logr.Logger
	Ctx              context.Context
}

type NotInSyncError

type NotInSyncError struct {
	Reason NotInSyncReason
	Object crclient.Object
}

NotInSyncError is returned when a spec object is out-of-sync with its cluster counterpart

func NewNotInSync

func NewNotInSync(obj crclient.Object, reason NotInSyncReason) *NotInSyncError

NewNotInSync wraps creation of NotInSyncErrors for simplicity

func (*NotInSyncError) Error

func (e *NotInSyncError) Error() string

type NotInSyncReason

type NotInSyncReason string
const (
	UpdatedObjectReason NotInSyncReason = "Updated object"
	CreatedObjectReason NotInSyncReason = "Created object"
	DeletedObjectReason NotInSyncReason = "Deleted object"
	NeedRetryReason     NotInSyncReason = "Need to retry"
)

type UnrecoverableSyncError

type UnrecoverableSyncError struct {
	Cause error
}

UnrecoverableSyncError is returned when provided objects cannot be synced with the cluster due to an unexpected error (e.g. they are invalid according to the object's spec).

func (*UnrecoverableSyncError) Error

func (e *UnrecoverableSyncError) Error() string

func (*UnrecoverableSyncError) Unwrap added in v0.18.0

func (e *UnrecoverableSyncError) Unwrap() error

type WarningError added in v0.18.0

type WarningError struct {
	Message string
	Err     error
}

WarningError is returned when syncing is successful and can continue but there is a warning regarding the objects synced to the cluster (e.g. they will not be updated)

func (*WarningError) Error added in v0.18.0

func (e *WarningError) Error() string

func (*WarningError) Unwrap added in v0.18.0

func (e *WarningError) Unwrap() error

Jump to

Keyboard shortcuts

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