operatorkit

package module
v0.0.0-...-f8211af Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

README

Kubernetes Operator Kit

FOSSA Status

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 but is independent. Much more thought needs to be put into API design, but at least provides the basis for the library with working code.

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.

FOSSA Status

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

func NewHTTPClientFromConfig

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

NewHTTPClient creates a Kubernetes client from a given Kubernetes *rest.Config 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 for a sample operator Package main for a sample operator
pkg/apis/myproject/v1alpha1
Package v1 is the v1 version of the API.
Package v1 is the v1 version of the API.
pkg/client/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
pkg/client/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
pkg/client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
pkg/client/clientset/versioned/typed/myproject/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
pkg/client/clientset/versioned/typed/myproject/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.

Jump to

Keyboard shortcuts

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