Git Product home page Git Product logo

controller-lifecycle-operator-sdk's Introduction

Build Status

controller-lifecycle-operator-sdk

Library helping in building HCO (Hyperconverged Cluster Operator - https://github.com/kubevirt/hyperconverged-cluster-operator) compatible Kubernetes operators.

Building parts

The controller-lifecycle-operator-sdk consists of following parts, that can be used together or separately:

  • API (pkg/sdk/api) package defining common types and constants that are required by the other parts of the library and that are compatible with HCO;
  • SDK package providing several helper functions used in the other parts of the library;
  • Callbacks (pkg/sdk/callbacks) package providing object-type bound callback registration and dispatching facilities - used to execute additional resource-management login in predefined places in the reconciliation loop;
  • Resources package providing resource definition helpers (deployment, service, etc. builders);
  • OpenAPI package providing OpenAPI definition of the common Status structure;
  • Reconciler (pkg/sdk/reconciler) package providing Reconciler structure responsible for executing operator lifecycle reconciliation

API

The pkg/sdk/api provides definition of a Status structure that has to be used in operator configuration Custom Resource as follows to allow the Reconciler to work properly:

// ConfigStatus defines the observed state of Config
type ConfigStatus struct {
	sdkapi.Status `json:",inline"`
}

// Config is the Schema for the config API
type Config struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   ConfigSpec   `json:"spec,omitempty"`
	Status ConfigStatus `json:"status,omitempty"`
}

The sdkapi.Status is inlined in a configuration CR-specific ConfigStatus structure.

The package defines also a set of phases that the configuration CR can be assigned.

Callbacks

The pkg/sdk/callbacks package defines CallbackDispatcher structure that allows its clients to register and notify callbacks assigned to Kubernetes resource object types (anything that fulfills runtime.Object interface). CallbackDispatcher implements following interface:

type CallbackDispatcher interface {
	// AddCallback registers a callback for given object type
	AddCallback(runtime.Object, callbacks.ReconcileCallback)

	// InvokeCallbacks executes callbacks for desired/current object type
	InvokeCallbacks(l logr.Logger, cr interface{}, s callbacks.ReconcileState, desiredObj, currentObj runtime.Object, recorder record.EventRecorder) error
} 

AddCallback method registers callback function under the type of obj key; there can be multiple callbacks registered for the same object type. InvokeCallbacks method executes all callbacks registered under the type of desiredObj and currentObj; s provides information about the stage of reconciliation when the call is made. desiredObj and currentObj are resources representing desired state of some object, and the current one (as stored in the cluster). It is the callback's responsibility to move the object to the desired state.

Reconciler

Reconciler structure from pkg/sdk/reconciler package is meant to work as a delegate for a Reconcile method in a controller that serves as a HCO-deployed operator. That method is responsible for managing both operator's deployment and state of any resources under its purview.

The Reconciler to work properly requires its client to provide an implementation of a CrManager interface. The interface defines several methods that are implementor domain-specific, like creation of a configuration Custom Resource, retrieval of sdkapi.Status sub-resource from the configuration CustomResource or others that can be found in reconciler.go.

Reference implementation

The reference implementation shows how the SDK can be used to manage other resources.

controller-lifecycle-operator-sdk's People

Contributors

akrejcir avatar mhenriks avatar pkliczewski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.