machinery

package
v0.0.0-...-5576edb Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package machinery provides object reconciliation strategies for arbitrary kubernetes objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action describes the taken reconciliation action.

const (
	// ActionCreated indicates that the object has been created to restore desired state.
	ActionCreated Action = "Created"
	// ActionUpdated indicates that the object has been updated to action on a change in desired state.
	ActionUpdated Action = "Updated"
	// ActionRecovered indicates that the object has been updated to recover values to
	// reflect desired state after interference from another actor of the system.
	ActionRecovered Action = "Recovered"
	// ActionProgressed indicates that the object progressed to newer revision.
	ActionProgressed Action = "Progressed"
	// ActionIdle indicates that no action was necessary. -> NoOp.
	ActionIdle Action = "Idle"
	// ActionCollision indicates aking actions was refused due to a collision with an existing object.
	ActionCollision Action = "Collision"
)

type Comparator

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

Comparator detects divergent state between desired and actual by comparing managed field ownerships. If not all fields from desired are owned by the same field owner in actual, we know that the object has been updated by another actor.

func NewComparator

func NewComparator(
	ownerStrategy divergeDetectorOwnerStrategy,
	discoveryClient discoveryClient,
	scheme *runtime.Scheme,
	fieldOwner string,
) *Comparator

NewComparator returns a new Comparator instance.

func (*Comparator) Compare

func (d *Comparator) Compare(
	owner client.Object,
	desiredObject, actualObject Object,
) (res CompareResult, err error)

Compare checks if a resource has been changed from desired.

type CompareResult

type CompareResult struct {
	// ConflictingMangers is a list of all managers conflicting with "our" field manager.
	ConflictingMangers []CompareResultManagedFields
	// OtherManagers is a list of all other managers working on the object.
	OtherManagers []CompareResultManagedFields
	// DesiredFieldSet contains all fields identified to be
	// part of the desired object. It is used for conflict
	// detection with other field owners.
	DesiredFieldSet *fieldpath.Set
	// Comparison of desired fields to actual fields.
	Comparison *typed.Comparison
}

CompareResult holds the results of a compare check.

func (CompareResult) IsConflict

func (d CompareResult) IsConflict() bool

IsConflict returns true, if another actor has overidden changes.

func (CompareResult) Modified

func (d CompareResult) Modified() []string

Modified returns a list of fields that have been modified.

func (CompareResult) String

func (d CompareResult) String() string

type CompareResultManagedFields

type CompareResultManagedFields struct {
	// Manager causing the conflict.
	Manager string
	// Fields affected by this conflict.
	Fields *fieldpath.Set
}

CompareResultManagedFields combines a manger with the fields it manages.

type CreateCollisionError

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

CreateCollisionError is returned when boxcutter tries to create an object, but it already exists. \ This happens when another actor has created the object and caches are slow, or the colliding object is excluded via cache selectors.

func (CreateCollisionError) Error

func (e CreateCollisionError) Error() string

Error implements golangs error interface.

type Object

type Object interface {
	client.Object
	runtime.Object
}

Object interface combining client.Object and runtime.Object.

type ObjectEngine

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

ObjectEngine reconciles individual objects.

func NewObjectEngine

func NewObjectEngine(
	scheme *runtime.Scheme,
	cache client.Reader,
	writer client.Writer,
	ownerStrategy objectEngineOwnerStrategy,
	comperator comperator,

	fieldOwner string,
	systemPrefix string,
) *ObjectEngine

NewObjectEngine returns a new Engine instance.

func (*ObjectEngine) Reconcile

func (e *ObjectEngine) Reconcile(
	ctx context.Context,
	owner client.Object,
	revision int64,
	desiredObject Object,
	opts ...types.ObjectOption,
) (ObjectResult, error)

Reconcile runs actions to bring actual state closer to desired.

func (*ObjectEngine) Teardown

func (e *ObjectEngine) Teardown(
	ctx context.Context,
	owner client.Object,
	revision int64,
	desiredObject Object,
) (objectGone bool, err error)

Teardown ensures the given object is safely removed from the cluster.

type ObjectProbeResult

type ObjectProbeResult struct {
	Success  bool
	Messages []string
}

ObjectProbeResult records probe results for the object.

type ObjectResult

type ObjectResult interface {
	// Action taken by the reconcile engine.
	Action() Action
	// Object as last seen on the cluster after creation/update.
	Object() Object
	// Success returns true when the operation is considered successful.
	// Operations are considered a success, when the object reflects desired state,
	// is owned by the right controller and passes the given probe.
	Success() bool
	// Probes returns the results from the given object Probes.
	Probes() map[string]ObjectProbeResult
	// String returns a human readable description of the Result.
	String() string
}

ObjectResult is the common Result interface for multiple result types.

type ObjectResultCollision

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

ObjectResultCollision is returned when conflicting with an existing object.

func (ObjectResultCollision) Action

func (r ObjectResultCollision) Action() Action

Action taken by the reconcile engine.

func (ObjectResultCollision) CompareResult

func (r ObjectResultCollision) CompareResult() CompareResult

CompareResult returns the results from checking the actual object on the cluster against the desired spec. Contains informations about differences that had to be reconciled.

func (ObjectResultCollision) ConflictingOwner

func (r ObjectResultCollision) ConflictingOwner() (*metav1.OwnerReference, bool)

ConflictingOwner Conflicting owner if Action == RefusingConflict.

func (ObjectResultCollision) Object

func (r ObjectResultCollision) Object() Object

Object as last seen on the cluster after creation/update.

func (ObjectResultCollision) Probes

func (r ObjectResultCollision) Probes() map[string]ObjectProbeResult

Probe returns the results from the given object Probe.

func (ObjectResultCollision) String

func (r ObjectResultCollision) String() string

String returns a human readable description of the Result.

func (ObjectResultCollision) Success

func (r ObjectResultCollision) Success() bool

Success returns true when the operation is considered successful. Operations are considered a success, when the object reflects desired state, is owned by the right controller and passes the given probe.

type ObjectResultCreated

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

ObjectResultCreated is returned when the Object was just created.

func (ObjectResultCreated) Action

func (r ObjectResultCreated) Action() Action

Action taken by the reconcile engine.

func (ObjectResultCreated) Object

func (r ObjectResultCreated) Object() Object

Object as last seen on the cluster after creation/update.

func (ObjectResultCreated) Probes

Probes returns the results from the given object Probe.

func (ObjectResultCreated) String

func (r ObjectResultCreated) String() string

String returns a human readable description of the Result.

func (ObjectResultCreated) Success

func (r ObjectResultCreated) Success() bool

Success returns true when the operation is considered successful. Operations are considered a success, when the object reflects desired state, is owned by the right controller and passes the given probe.

type ObjectResultIdle

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

ObjectResultIdle is returned when nothing was done.

func (ObjectResultIdle) Action

func (r ObjectResultIdle) Action() Action

Action taken by the reconcile engine.

func (ObjectResultIdle) CompareResult

func (r ObjectResultIdle) CompareResult() CompareResult

CompareResult returns the results from checking the actual object on the cluster against the desired spec. Contains informations about differences that had to be reconciled.

func (ObjectResultIdle) Object

func (r ObjectResultIdle) Object() Object

Object as last seen on the cluster after creation/update.

func (ObjectResultIdle) Probes

func (r ObjectResultIdle) Probes() map[string]ObjectProbeResult

Probe returns the results from the given object Probe.

func (ObjectResultIdle) String

func (r ObjectResultIdle) String() string

String returns a human readable description of the Result.

func (ObjectResultIdle) Success

func (r ObjectResultIdle) Success() bool

Success returns true when the operation is considered successful. Operations are considered a success, when the object reflects desired state, is owned by the right controller and passes the given probe.

type ObjectResultProgressed

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

ObjectResultProgressed is returned when the object has been progressed to a newer revision.

func (ObjectResultProgressed) Action

func (r ObjectResultProgressed) Action() Action

Action taken by the reconcile engine.

func (ObjectResultProgressed) CompareResult

func (r ObjectResultProgressed) CompareResult() CompareResult

CompareResult returns the results from checking the actual object on the cluster against the desired spec. Contains informations about differences that had to be reconciled.

func (ObjectResultProgressed) Object

func (r ObjectResultProgressed) Object() Object

Object as last seen on the cluster after creation/update.

func (ObjectResultProgressed) Probes

func (r ObjectResultProgressed) Probes() map[string]ObjectProbeResult

Probe returns the results from the given object Probe.

func (ObjectResultProgressed) String

func (r ObjectResultProgressed) String() string

String returns a human readable description of the Result.

func (ObjectResultProgressed) Success

func (r ObjectResultProgressed) Success() bool

Success returns true when the operation is considered successful. Operations are considered a success, when the object reflects desired state, is owned by the right controller and passes the given probe.

type ObjectResultRecovered

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

ObjectResultRecovered is returned when the object had to be reset after conflicting with another actor.

func (ObjectResultRecovered) Action

func (r ObjectResultRecovered) Action() Action

Action taken by the reconcile engine.

func (ObjectResultRecovered) CompareResult

func (r ObjectResultRecovered) CompareResult() CompareResult

CompareResult returns the results from checking the actual object on the cluster against the desired spec. Contains informations about differences that had to be reconciled.

func (ObjectResultRecovered) Object

func (r ObjectResultRecovered) Object() Object

Object as last seen on the cluster after creation/update.

func (ObjectResultRecovered) Probes

func (r ObjectResultRecovered) Probes() map[string]ObjectProbeResult

Probe returns the results from the given object Probe.

func (ObjectResultRecovered) String

func (r ObjectResultRecovered) String() string

String returns a human readable description of the Result.

func (ObjectResultRecovered) Success

func (r ObjectResultRecovered) Success() bool

Success returns true when the operation is considered successful. Operations are considered a success, when the object reflects desired state, is owned by the right controller and passes the given probe.

type ObjectResultUpdated

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

ObjectResultUpdated is returned when the object is updated.

func (ObjectResultUpdated) Action

func (r ObjectResultUpdated) Action() Action

Action taken by the reconcile engine.

func (ObjectResultUpdated) CompareResult

func (r ObjectResultUpdated) CompareResult() CompareResult

CompareResult returns the results from checking the actual object on the cluster against the desired spec. Contains informations about differences that had to be reconciled.

func (ObjectResultUpdated) Object

func (r ObjectResultUpdated) Object() Object

Object as last seen on the cluster after creation/update.

func (ObjectResultUpdated) Probes

func (r ObjectResultUpdated) Probes() map[string]ObjectProbeResult

Probe returns the results from the given object Probe.

func (ObjectResultUpdated) String

func (r ObjectResultUpdated) String() string

String returns a human readable description of the Result.

func (ObjectResultUpdated) Success

func (r ObjectResultUpdated) Success() bool

Success returns true when the operation is considered successful. Operations are considered a success, when the object reflects desired state, is owned by the right controller and passes the given probe.

type PhaseEngine

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

PhaseEngine groups reconciliation of a list of objects, after all of them have passed preflight checks and performs probing after the objects have been reconciled.

func NewPhaseEngine

func NewPhaseEngine(
	objectEngine objectEngine,
	phaseValidator phaseValidator,
) *PhaseEngine

NewPhaseEngine returns a new PhaseEngine instance.

func (*PhaseEngine) Reconcile

func (e *PhaseEngine) Reconcile(
	ctx context.Context,
	owner client.Object,
	revision int64,
	phase types.PhaseAccessor,
) (PhaseResult, error)

Reconcile runs actions to bring actual state closer to desired.

func (*PhaseEngine) Teardown

func (e *PhaseEngine) Teardown(
	ctx context.Context,
	owner client.Object,
	revision int64,
	phase types.PhaseAccessor,
) (PhaseTeardownResult, error)

Teardown ensures the given phase is safely removed from the cluster.

type PhaseObject

type PhaseObject struct {
	Object *unstructured.Unstructured
	Opts   []types.ObjectOption
}

PhaseObject represents an object and it's options.

type PhaseResult

type PhaseResult interface {
	// GetName returns the name of the phase.
	GetName() string
	// GetPreflightViolation returns the preflight
	// violation, if one was encountered.
	GetPreflightViolation() (validation.PhaseViolation, bool)
	// GetObjects returns results for individual objects.
	GetObjects() []ObjectResult
	// InTransition returns true if the Phase has not yet fully rolled out,
	// if the phase has objects progressed to a new revision or
	// if objects have unresolved conflicts.
	InTransistion() bool
	// IsComplete returns true when all objects have
	// successfully been reconciled and pass their probes.
	IsComplete() bool
	// HasProgressed returns true when all objects have been progressed to a newer revision.
	HasProgressed() bool
	String() string
}

PhaseResult interface to access results of phase reconcile.

type PhaseTeardownResult

type PhaseTeardownResult interface {
	GetName() string
	// IsComplete returns true when all objects have been deleted,
	// finalizers have been processes and the objects are longer
	// present on the kube-apiserver.
	IsComplete() bool
	// Gone returns a list of objects that have been confirmed
	// to be gone from the kube-apiserver.
	Gone() []types.ObjectRef
	// Waiting returns a list of objects that have yet to be
	// cleaned up on the kube-apiserver.
	Waiting() []types.ObjectRef

	String() string
}

PhaseTeardownResult interface to access results of phase teardown.

type RevisionEngine

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

RevisionEngine manages rollout and teardown of multiple phases.

func NewRevisionEngine

func NewRevisionEngine(
	phaseEngine phaseEngine,
	revisionValidator revisionValidator,
	client client.Writer,
) *RevisionEngine

NewRevisionEngine returns a new RevisionEngine instance.

func (*RevisionEngine) Reconcile

Reconcile runs actions to bring actual state closer to desired.

func (*RevisionEngine) Teardown

Teardown ensures the given revision is safely removed from the cluster.

type RevisionResult

type RevisionResult interface {
	// GetPreflightViolation returns the preflight violation of the entire Revision.
	// Revision preflight checks are not as extensive as phase-preflight checks.
	GetPreflightViolation() (validation.RevisionViolation, bool)
	// GetPhases returns results for individual phases.
	GetPhases() []PhaseResult
	// InTransition returns true if the Phase has not yet fully rolled out,
	// if the phase has objects progressed to a new revision or
	// if objects have unresolved conflicts.
	InTransistion() bool
	// IsComplete returns true when all objects have
	// successfully been reconciled and pass their probes.
	IsComplete() bool
	// HasProgressed returns true when all phases have been progressed to a newer revision.
	HasProgressed() bool
	String() string
}

RevisionResult holds details about the revision reconciliation run.

type RevisionTeardownResult

type RevisionTeardownResult interface {
	// GetPhases returns results for individual phases.
	GetPhases() []PhaseTeardownResult
	// IsComplete returns true when all objects have been deleted,
	// finalizers have been processes and the objects are longer
	// present on the kube-apiserver.
	IsComplete() bool
	// GetWaitingPhaseNames returns a list of phase names waiting
	// to be torn down.
	GetWaitingPhaseNames() []string
	// GetActivePhaseName returns the name of the phase that is
	// currently being torn down (e.g. waiting on finalizers).
	// Second return is false when no phase is active.
	GetActivePhaseName() (string, bool)
	// GetGonePhaseNames returns a list of phase names already processed.
	GetGonePhaseNames() []string
	// String returns a human readable report.
	String() string
}

RevisionTeardownResult holds the results of a Teardown operation.

Directories

Path Synopsis
Package types contains common type definitions for boxcutter machinery.
Package types contains common type definitions for boxcutter machinery.

Jump to

Keyboard shortcuts

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