reconcile

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package reconcile defines the Reconciler interface to implement Kubernetes APIs. Reconciler is provided to Controllers at creation time as the API implementation.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func func(Request) (Result, error)

Func is a function that implements the reconcile interface.

Example

This example implements a simple no-op reconcile function that prints the object to be Reconciled.

package main

import (
	"fmt"

	"k8s.io/apimachinery/pkg/types"
	"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

func main() {
	type Reconciler struct{}

	r := reconcile.Func(func(o reconcile.Request) (reconcile.Result, error) {
		// Create your business logic to create, update, delete objects here.
		fmt.Printf("Name: %s, Namespace: %s", o.Name, o.Namespace)
		return reconcile.Result{}, nil
	})

	r.Reconcile(reconcile.Request{NamespacedName: types.NamespacedName{Namespace: "default", Name: "test"}})

}
Output:

Name: test, Namespace: default

func (Func) Reconcile

func (r Func) Reconcile(o Request) (Result, error)

Reconcile implements Reconciler.

type Reconciler

type Reconciler interface {
	// Reconciler performs a full reconciliation for the object referred to by the Request.
	// The Controller will requeue the Request to be processed again if an error is non-nil or
	// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
	Reconcile(Request) (Result, error)
}

Reconciler implements a Kubernetes API for a specific Resource by Creating, Updating or Deleting Kubernetes objects, or by making changes to systems external to the cluster (e.g. cloudproviders, github, etc).

reconcile implementations compare the state specified in an object by a user against the actual cluster state, and then perform operations to make the actual cluster state reflect the state specified by the user.

Typically, reconcile is triggered by a Controller in response to cluster Events (e.g. Creating, Updating, Deleting Kubernetes objects) or external Events (GitHub Webhooks, polling external sources, etc).

Example reconcile Logic:

  • Reader an object and all the Pods it owns.
  • Observe that the object spec specifies 5 replicas but actual cluster contains only 1 Pod replica.
  • Create 4 Pods and set their OwnerReferences to the object.

reconcile may be implemented as either a type:

type reconcile struct {}

func (reconcile) reconcile(controller.Request) (controller.Result, error) {
	// Implement business logic of reading and writing objects here
	return controller.Result{}, nil
}

Or as a function:

controller.Func(func(o controller.Request) (controller.Result, error) {
	// Implement business logic of reading and writing objects here
	return controller.Result{}, nil
})

Reconciliation is level-based, meaning action isn't driven off changes in individual Events, but instead is driven by actual cluster state read from the apiserver or a local cache. For example if responding to a Pod Delete Event, the Request won't contain that a Pod was deleted, instead the reconcile function observes this when reading the cluster state and seeing the Pod as missing.

type Request

type Request struct {
	// NamespacedName is the name and namespace of the object to reconcile.
	types.NamespacedName
}

Request contains the information necessary to reconcile a Kubernetes object. This includes the information to uniquely identify the object - its Name and Namespace. It does NOT contain information about any specific Event or the object contents itself.

type Result

type Result struct {
	// Requeue tells the Controller to requeue the reconcile key.  Defaults to false.
	Requeue bool
}

Result contains the result of a Reconciler invocation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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