controllers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

README

Controllers

Plant Controller

Plant controller relies on the assumption that resources which are required to be generated (assuming, many) should have a simple and straightforward way to be implemented and integrated into the chain.

That is why the internal logic of PlantReconciler depends of workflow.Manager which manages the actual business logic, and the StateHandler(not yet an interface), which bridges between the dependencies and control loop states. Workflow Manager (and similar components) can be used to define the actual business logic required for creating, managing, and removing the API resource-based logic.

Check documentation and actual usage.

type PlantReconciler struct {
    Client   client.Client
    Scheme   *runtime.Scheme
    Workflow workflow.Manager // separates business from state-control logic
    Recorder record.EventRecorder
}

type AbstractedReconciler interface {
    // Just an initializer
    Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)
    
    // StateHandler
    ErrorHandle(ctx context.Context, plant *v1.Plant, err error) (ctrl.Result, error)
    StateHandle(ctx context.Context, plant *v1.Plant) (bool, error)
    UpdateStatus(ctx context.Context, plant *v1.Plant, opts ...func (*v1.Plant)) error
	
    // Business logic (minimal)
    HandleProcessingState(ctx context.Context, plant *v1.Plant) (bool, error)
    HandleDeletingState(ctx context.Context, plant *v1.Plant) (bool, error)
}

// This is an owner/parent resource, consider extending
type Plant struct {
	State string // e.g., State field which can be used for state-based control
	
	// everything else 
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PlantReconciler

type PlantReconciler struct {
	Client   client.Client // differentiate Client and PlantReconciler calls
	Scheme   *runtime.Scheme
	Workflow workflow.Manager
	Recorder record.EventRecorder
}

PlantReconciler reconciles a Plant object

func (*PlantReconciler) ErrorHandle

func (r *PlantReconciler) ErrorHandle(ctx context.Context, plant *apiv1.Plant, err error) (ctrl.Result, error)

ErrorHandle logs the error, puts Plant into apiv1.StateError state, and returns rescheduled result.

func (*PlantReconciler) HandleDeletingState

func (r *PlantReconciler) HandleDeletingState(ctx context.Context, plant *apiv1.Plant) (bool, error)

HandleDeletingState remove all hanging resources. The garbage collector will handle internal resource deletion, while we handle the external ones here.

func (*PlantReconciler) HandleProcessingState

func (r *PlantReconciler) HandleProcessingState(ctx context.Context, plant *apiv1.Plant) (bool, error)

HandleProcessingState processes all child resources by ensuring that they are in proper states. Check runHandler to get more details on how child resource execution is handled. Returns true if reconcile should be triggered. Updates Status with observed results.

func (*PlantReconciler) Reconcile

func (r *PlantReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile ensures that Plant and its owned resources match the required states from the cluster. This method will fetch the controlled Plant object, ensure that Plant has Finalizers and required states to safely address deletion, and finally, invoke StateHandle to perform control tasks based on the requirements. Reconcile relies on StateHandle to handle the request, and ErrorHandle to handle the errors. Request will be rescheduled if an error occurs.

func (*PlantReconciler) SetupWithManager

func (r *PlantReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager.

func (*PlantReconciler) StateHandle

func (r *PlantReconciler) StateHandle(ctx context.Context, plant *apiv1.Plant) (bool, error)

StateHandle runs the main control loop based on the configured Plant state. Returns true if reconcile should be triggered.

func (*PlantReconciler) UpdateResults

func (r *PlantReconciler) UpdateResults(ctx context.Context, plant *apiv1.Plant, results []resource.ExecuteResult) error

UpdateResults will handle results from executions by adding them to Plant status

func (*PlantReconciler) UpdateStatus

func (r *PlantReconciler) UpdateStatus(ctx context.Context, plant *apiv1.Plant, opts ...func(*apiv1.Plant)) error

UpdateStatus will update plants status using provided values and options.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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