operatorkit

package module
v0.0.0-...-4df41cf Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2017 License: Apache-2.0 Imports: 20 Imported by: 0

README

Kubernetes Operator Kit

A Kubernetes Operator is a controller for custom resources. The purpose of the operator kit is to provide a common library for implementing operators.

The library originated from the Rook operator. Much more thought needs to be put into API design, but at least provides the basis for the library with working code. With enough interest, this could become a Kubernetes incubator project.

Features

The operator kit is a simple collection of features that will be useful for operators.

  • CRD handling: creating, retrieving, and watching CRDs on K8s 1.7+
  • TPR handling: creating, retrieving, and watching TPRs on versions prior to 1.7
  • Timing: helpers to timeout when taking too long or retry when when working with kubernetes resources

Roadmap

The operator kit is still in its infancy and needs plenty of work before it is considered stable.

  • Community collaboration on the requirements and design
  • Leader election for HA
  • Tests

The conversation has been started here.

Sample Code

To help you get started, a simple operator with a single custom resource is provided here.

Contributing

Contributions are welcome! See Contributing to get started.

Report a Bug

For filing bugs, suggesting improvements, or requesting new features, help out by opening an issue.

Licensing

The operator kit is under the Apache 2.0 license. The appropriate license information can be found in the headers of the source files.

Documentation

Overview

Package kit for Kubernetes operators

Package kit for Kubernetes operators

Package kit for Kubernetes operators

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVersionOutdated indicates that the custom resource is outdated and needs to be refreshed
	ErrVersionOutdated = errors.New("requested version is outdated in apiserver")
)

Functions

func CreateCustomResources

func CreateCustomResources(context Context, resources []CustomResource) error

CreateCustomResources creates the given custom resources and waits for them to initialize The resource is of kind CRD if the Kubernetes server is 1.7.0 and above. The resource is of kind TPR if the Kubernetes server is below 1.7.0.

func NewHTTPClient

func NewHTTPClient(group, version string, schemeBuilder runtime.SchemeBuilder) (rest.Interface, *runtime.Scheme, error)

NewHTTPClient creates a Kubernetes client to interact with API extensions for Custom Resources

Types

type Context

type Context struct {
	Clientset             kubernetes.Interface
	APIExtensionClientset apiextensionsclient.Interface
	Interval              time.Duration
	Timeout               time.Duration
}

Context hold the clientsets used for creating and watching custom resources

type CustomResource

type CustomResource struct {
	// Name of the custom resource
	Name string

	// Plural of the custom resource in plural
	Plural string

	// Group the custom resource belongs to
	Group string

	// Version which should be defined in a const above
	Version string

	// Scope of the CRD. Namespaced or cluster
	Scope apiextensionsv1beta1.ResourceScope

	// Kind is the serialized interface of the resource.
	Kind string
}

CustomResource is for creating a Kubernetes TPR/CRD

type ResourceWatcher

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

ResourceWatcher watches a custom resource for desired state

func NewWatcher

func NewWatcher(resource CustomResource, namespace string, handlers cache.ResourceEventHandlerFuncs, client rest.Interface) *ResourceWatcher

NewWatcher creates an instance of a custom resource watcher for the given resource

func (*ResourceWatcher) Watch

func (w *ResourceWatcher) Watch(objType runtime.Object, done chan struct{}) error

Watch begins watching the custom resource (TPR/CRD). The call will block until a Done signal is raised during in the context. When the watch has detected a create, update, or delete event, it will handled by the functions in the resourceEventHandlers. After the callback returns, the watch loop will continue for the next event. If the callback returns an error, the error will be logged.

Directories

Path Synopsis
Package main for a sample operator Package main for a sample operator Package main to manage a sample operator.
Package main for a sample operator Package main for a sample operator Package main to manage a sample operator.

Jump to

Keyboard shortcuts

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