syncer

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOwnerDeleted is returned when the object owner is marked for deletion.
	ErrOwnerDeleted = fmt.Errorf("owner is deleted")

	// ErrIgnore is returned for ignored errors.
	// Ignored errors are treated by the syncer as successful syncs.
	ErrIgnore = fmt.Errorf("ignored error")
)

Functions

func IgnoredError

func IgnoredError(err error) error

IgnoredError wraps and marks errors as being ignored.

func Sync

func Sync(ctx context.Context, syncer Interface, recorder record.EventRecorder) error

Sync mutates the subject of the syncer interface using controller-runtime CreateOrUpdate method, when obj is not nil. It takes care of setting owner references and recording kubernetes events where appropriate.

Types

type Interface

type Interface interface {
	// Object returns the object for which sync applies.
	Object() interface{}

	// Owner returns the object owner or nil if object does not have one.
	ObjectOwner() runtime.Object

	// Sync persists data into the external store.
	Sync(context.Context) (SyncResult, error)
}

Interface represents a syncer. A syncer persists an object (known as subject), into a store (kubernetes apiserver or generic stores) and records kubernetes events.

func NewExternalSyncer

func NewExternalSyncer(
	name string, owner runtime.Object, obj interface{}, syncFn func(context.Context, interface{}) (controllerutil.OperationResult, error),
) Interface

NewExternalSyncer creates a new syncer which syncs a generic object persisting it's state into and external store The name is used for logging and event emitting purposes and should be an valid go identifier in upper camel case. (eg. GiteaRepo).

func NewObjectSyncer

func NewObjectSyncer(name string, owner, obj client.Object, c client.Client, syncFn controllerutil.MutateFn) Interface

NewObjectSyncer creates a new kubernetes.Object syncer for a given object with an owner and persists data using controller-runtime's CreateOrUpdate. The name is used for logging and event emitting purposes and should be an valid go identifier in upper camel case. (eg. MysqlStatefulSet).

func NewRemoveResourceSyncer added in v0.7.0

func NewRemoveResourceSyncer(name string, owner, obj client.Object, c client.Client) Interface

NewRemoveResourceSyncer creates a new kubernetes.Object syncer for a given object with an owner and persists data using controller-runtime's Delete. The name is used for logging and event emitting purposes and should be an valid go identifier in upper camel case. (eg. MysqlStatefulSet).

type ObjectSyncer

type ObjectSyncer struct {
	Owner  client.Object
	Obj    client.Object
	SyncFn controllerutil.MutateFn
	Name   string
	Client client.Client
	// contains filtered or unexported fields
}

ObjectSyncer is a syncer.Interface for syncing kubernetes.Objects only by passing a SyncFn.

func (*ObjectSyncer) Object

func (s *ObjectSyncer) Object() interface{}

Object returns the ObjectSyncer subject.

func (*ObjectSyncer) ObjectOwner

func (s *ObjectSyncer) ObjectOwner() runtime.Object

ObjectOwner returns the ObjectSyncer owner.

func (*ObjectSyncer) Sync

func (s *ObjectSyncer) Sync(ctx context.Context) (SyncResult, error)

Sync does the actual syncing and implements the syncer.Inteface Sync method.

type RemoveResourceSyncer added in v0.7.0

type RemoveResourceSyncer struct {
	Owner  client.Object
	Obj    client.Object
	Name   string
	Client client.Client
}

RemoveResourceSyncer is a syncer.Interface for deleting kubernetes.Objects.

func (*RemoveResourceSyncer) Object added in v0.7.0

func (s *RemoveResourceSyncer) Object() interface{}

Object returns the ObjectSyncer subject.

func (*RemoveResourceSyncer) ObjectOwner added in v0.7.0

func (s *RemoveResourceSyncer) ObjectOwner() runtime.Object

ObjectOwner returns the ObjectSyncer owner.

func (*RemoveResourceSyncer) Sync added in v0.7.0

Sync does the actual syncing and implements the syncer.Inteface Sync method.

type SyncResult

type SyncResult struct {
	Operation    controllerutil.OperationResult
	EventType    string
	EventReason  string
	EventMessage string
}

SyncResult is a result of an Sync call.

func (*SyncResult) SetEventData

func (r *SyncResult) SetEventData(eventType, reason, message string)

SetEventData sets event data on an SyncResult.

type WithoutOwner

type WithoutOwner struct{}

WithoutOwner partially implements implements the syncer interface for the case the subject has no owner.

func (*WithoutOwner) GetOwner

func (*WithoutOwner) GetOwner() client.Object

GetOwner implementation of syncer interface for the case the subject has no owner.

Jump to

Keyboard shortcuts

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