juggler

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StatusReconcilerNotFound states that no registered reconciler was able to handle the component.
	StatusReconcilerNotFound = ComponentStatus{Name: "ReconcilerNotFound", IsReady: false, EmitsEvent: ComponentEventWarning}

	// StatusObservationFailed states that the current state (installed, healthy, etc.)
	// of the component could not be determined.
	StatusObservationFailed = ComponentStatus{Name: "ObservationFailed", IsReady: false, EmitsEvent: ComponentEventWarning}

	// StatusUninstallFailed states that a component could not be uninstalled.
	StatusUninstallFailed = ComponentStatus{Name: "UninstallFailed", IsReady: false, EmitsEvent: ComponentEventWarning}

	// StatusUninstalled states that a component has been uninstalled.
	StatusUninstalled = ComponentStatus{Name: "Uninstalled", IsReady: false, EmitsEvent: ComponentEventNormal}

	// StatusDisabled states that a component is disabled and no action has been taken.
	StatusDisabled = ComponentStatus{Name: "Disabled", IsReady: false, EmitsEvent: ComponentEventNone}

	// StatusComponentNotAllowed states that a component is not allowed to be installed.
	StatusComponentNotAllowed = ComponentStatus{Name: "ComponentNotAllowed", IsReady: false, EmitsEvent: ComponentEventWarning}

	// StatusDependencyCheckFailed states that a dependency check failed (e.g. dependency not enabled)
	StatusDependencyCheckFailed = ComponentStatus{Name: "DependencyCheckFailed", IsReady: false, EmitsEvent: ComponentEventWarning}

	// StatusInstallFailed states that a component could not be installed.
	StatusInstallFailed = ComponentStatus{Name: "InstallFailed", IsReady: false, EmitsEvent: ComponentEventWarning}

	// StatusInstalled states that a component has been installed.
	StatusInstalled = ComponentStatus{Name: "Installed", IsReady: false, EmitsEvent: ComponentEventNormal}

	// StatusUpdateFailed states that a component could not be updated.
	StatusUpdateFailed = ComponentStatus{Name: "UpdateFailed", IsReady: false, EmitsEvent: ComponentEventWarning}

	// StatusUnhealthy states that a component is unhealthy.
	StatusUnhealthy = ComponentStatus{Name: "Unhealthy", IsReady: false, EmitsEvent: ComponentEventNone}

	// StatusHealthy states that a component is healthy and no action has been taken.
	StatusHealthy = ComponentStatus{Name: "Healthy", IsReady: true, EmitsEvent: ComponentEventNone}
)

Functions

This section is empty.

Types

type Component

type Component interface {
	// GetName returns the name of the component.
	GetName() string

	// GetDependencies returns all dependencies of the component.
	GetDependencies() []Component

	// IsEnabled returns if a component is enabled.
	IsEnabled() bool

	// Hooks returns the hooks for a component.
	Hooks() ComponentHooks

	// IsInstallable returns if a component is installable.
	// And if not, the error which describes why it is not installable.
	IsInstallable(ctx context.Context) (bool, error)
}

Component is an interface for manageable components.

type ComponentEventRecorder

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

func NewComponentEventRecorder

func NewComponentEventRecorder(recorder EventRecorder, component Component) *ComponentEventRecorder

ComponentEventRecorder returns a new (opinionated) EventRecorder for a given EventRecorder and a Component.

func (*ComponentEventRecorder) Event

func (c *ComponentEventRecorder) Event(status ComponentStatus, message string)

type ComponentEventType

type ComponentEventType string
const (
	// No event
	ComponentEventNone ComponentEventType = ""

	// Information only and will not cause any problems
	ComponentEventNormal ComponentEventType = ComponentEventType(EventNormal)

	// These events are to warn that something might go wrong
	ComponentEventWarning ComponentEventType = ComponentEventType(EventWarning)
)

type ComponentHooks

type ComponentHooks struct {
	PreUninstall func(ctx context.Context, c client.Client) error
	PreInstall   func(ctx context.Context, c client.Client) error
	PreUpdate    func(ctx context.Context, c client.Client) error
}

ComponentHooks defines hooks for a Component.

type ComponentObservation

type ComponentObservation struct {
	ResourceExists bool
	ResourceHealthiness
}

type ComponentReconciler

type ComponentReconciler interface {
	// KnownTypes returns a list of component types that are supported by this reconciler.
	KnownTypes() []reflect.Type
	// Observe returns a ComponentObservation to return the state of a Component
	// inside the cluster to the ComponentReconciler
	Observe(ctx context.Context, component Component) (ComponentObservation, error)
	// Uninstall triggers an uninstall of a Component in the cluster
	Uninstall(ctx context.Context, component Component) error
	// Update updates a Component in the cluster
	Update(ctx context.Context, component Component) error
	// Install triggers an install of a Component in the cluster
	Install(ctx context.Context, component Component) error
	// PreUninstall calls the pre-uninstall hook of a Component.
	PreUninstall(ctx context.Context, component Component) error
	// PreUninstall calls the pre-install hook of a Component.
	PreInstall(ctx context.Context, component Component) error
	// PreUpdate calls the pre-update hook of a Component.
	PreUpdate(ctx context.Context, component Component) error
}

type ComponentResult

type ComponentResult struct {
	Component Component
	Result    ComponentStatus
	Message   string
}

ComponentResult contains information about an operation performed by the component manager.

func (ComponentResult) ToCondition

func (r ComponentResult) ToCondition() metav1.Condition

ToCondition converts a ComponentResult to a Kubernetes Condition.

type ComponentStatus

type ComponentStatus struct {
	Name       string
	IsReady    bool
	EmitsEvent ComponentEventType
}

ComponentStatus indicates the status of a component.

type EventRecorder

type EventRecorder interface {
	Event(eventtype EventType, reason, message string)

	// Eventf is just like Event, but with Sprintf for the message field.
	Eventf(eventtype EventType, reason, messageFmt string, args ...interface{})

	// AnnotatedEventf is just like eventf, but with annotations attached
	AnnotatedEventf(annotations map[string]string, eventtype EventType, reason, messageFmt string, args ...interface{})
}

EventRecorder is an opinionated record.EventRecorder for the Juggler.

func NewEventRecorder

func NewEventRecorder(recorder record.EventRecorder, object runtime.Object) EventRecorder

NewEventRecorder returns a new (opinionated) EventRecorder for a given record.EventRecorder and a runtime.Object.

type EventType

type EventType string
const (
	// Information only and will not cause any problems
	EventNormal EventType = EventType(corev1.EventTypeNormal)

	// These events are to warn that something might go wrong
	EventWarning EventType = EventType(corev1.EventTypeWarning)
)

type Juggler

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

Juggler manages components.

func NewJuggler

func NewJuggler(logger logr.Logger, recorder EventRecorder) *Juggler

NewJuggler initializes a new Juggler.

func (*Juggler) Reconcile

func (am *Juggler) Reconcile(ctx context.Context) []ComponentResult

Reconcile compares the current and desired state for each registered component and takes measures to reach the desired state if necessary. The implementation is inspired by Crossplanes Managed resource reconciler

func (*Juggler) RegisterComponent

func (am *Juggler) RegisterComponent(component ...Component)

RegisterComponent makes the Juggler aware of new components.

func (*Juggler) RegisterOrphanedComponents

func (am *Juggler) RegisterOrphanedComponents(ctx context.Context) error

RegisterOrphanedComponents calls registered reconcilers that implement the optional `OrphanedComponentsDetector` interface and registers orphaned components so that they can be uninstalled.

func (*Juggler) RegisterReconciler

func (am *Juggler) RegisterReconciler(reconciler ...ComponentReconciler)

RegisterReconciler makes the Juggler aware of new reconcilers.

func (*Juggler) RegisteredComponents

func (am *Juggler) RegisteredComponents() int

RegisteredComponents returns the number of registered components.

type KeepOnUninstall

type KeepOnUninstall interface {
	KeepOnUninstall() bool
}

KeepOnUninstall can be implemented by components that should not be uninstalled, e.g. CRDs.

type ObjectEventRecorder

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

ObjectEventRecorder is the EventRecorder for the Juggler. It encapsulates the record.EventRecorder interface.

func (*ObjectEventRecorder) AnnotatedEventf

func (oer *ObjectEventRecorder) AnnotatedEventf(annotations map[string]string, eventtype EventType, reason,
	messageFmt string, args ...interface{})

func (*ObjectEventRecorder) Event

func (oer *ObjectEventRecorder) Event(eventtype EventType, reason, message string)

func (*ObjectEventRecorder) Eventf

func (oer *ObjectEventRecorder) Eventf(eventtype EventType, reason, messageFmt string, args ...interface{})

type OrphanedComponentsDetector

type OrphanedComponentsDetector interface {
	// DetectOrphanedComponents searches for orphaned components. The `configuredComponents` contains a list of
	// configured components supported by the reconciler. It should be used to calculate the delta between
	// existing and configured components.
	// Orphaned=Existing\Configured (set difference D=M\N).
	DetectOrphanedComponents(ctx context.Context, configuredComponents []Component) ([]Component, error)
}

OrphanedComponentsDetector can be implemented by a `ComponentReconciler` to signal that it supports the discovery of orphaned components.

type ResourceHealthiness

type ResourceHealthiness struct {
	Healthy bool
	Message string
}

type StatusVisibility

type StatusVisibility interface {
	// IsStatusInternal method implemented by a component
	// indicates that the component is internal or external.
	IsStatusInternal() bool
}

StatusVisibility interface defines methods that can be optionally implemented by components. A component can implement this interface to indicate that the component is to be considered internal. If the component does not implement this interface, it is considered as external.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳