kube

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

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

Go to latest
Published: Sep 5, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

README

kube

typed way to control kubernetes resources

Documentation

Index

Constants

View Source
const (
	PreCreate  HookType = "pre_create"
	PostCreate HookType = "post_create"

	PreGet  HookType = "pre_get"
	PostGet HookType = "post_get"

	PreDelete  HookType = "pre_delete"
	PostDelete HookType = "post_delete"

	ErrCreate HookErrType = "err_create"
	ErrGet    HookErrType = "err_get"
	ErrDelete HookErrType = "err_delete"
)

Variables

View Source
var WithClientSet = func(clientset ClientSet) Option {
	return func(c *BasicController) {
		c.clientset = clientset
	}
}
View Source
var WithContainerCopy = func() Option {
	return func(c *BasicController) {
		c.Container = c.Container.Copy()
	}
}

OptionContainerCopy creates BasicController copying the Container

View Source
var WithCreateOpts = func(opts v1meta.CreateOptions) Option {
	return func(c *BasicController) {
		c.CreateOpts = opts
	}
}
View Source
var WithHooks = func(hooks Hooks) Option {
	return func(c *BasicController) {
		for t, h := range hooks {
			if existing := c.hooks[t]; existing == nil {
				c.hooks[t] = h
			} else {
				c.hooks[t] = append(c.hooks[t], h...)
			}
		}
	}
}
View Source
var WithHooksFirst = func(hooks Hooks) Option {
	return func(c *BasicController) {
		for t, h := range hooks {
			if existing := c.hooks[t]; existing == nil {
				c.hooks[t] = h
			} else {
				h = append(h, c.hooks[t]...)
				c.hooks[t] = h
			}
		}
	}
}

register hooks as first to run

View Source
var WithKubernetesClient = func(namespace string, client *kubernetes.Clientset) Option {
	return func(c *BasicController) {
		c.clientset = NewClientSet(namespace, client)
	}
}
View Source
var WithoutHooks = func() Option {
	return func(c *BasicController) {
		c.hooks = make(Hooks)
	}
}

delete all hooks

Functions

func NewContainer

func NewContainer(kinds ...Kind) *container

NewContainer creates new container for Kind's

Types

type BasicClientSet

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

KubeClientSet implements BasicClientSet

func (*BasicClientSet) Client

func (c *BasicClientSet) Client() *kubernetes.Clientset

func (*BasicClientSet) ConfigMaps

func (*BasicClientSet) Deployments

func (*BasicClientSet) Ingresses

func (*BasicClientSet) Namespace

func (c *BasicClientSet) Namespace() string

func (*BasicClientSet) Namespaces

func (*BasicClientSet) PersistentVolumeClaims

func (c *BasicClientSet) PersistentVolumeClaims() typedv1core.PersistentVolumeClaimInterface

func (*BasicClientSet) Secrets

func (*BasicClientSet) Services

type BasicController

type BasicController struct {
	Container

	CreateOpts v1meta.CreateOptions
	DeleteOpts v1meta.DeleteOptions
	GetOpts    v1meta.GetOptions
	// contains filtered or unexported fields
}

BasicController implements Controller

func (*BasicController) ClientSet

func (c *BasicController) ClientSet() ClientSet

func (*BasicController) Configure

func (c *BasicController) Configure(opt Option)

func (*BasicController) CreateContainer

func (c *BasicController) CreateContainer() []error

func (*BasicController) CreateKind

func (c *BasicController) CreateKind(kind Kind) (res Resource, err error)

func (*BasicController) DeleteContainer

func (c *BasicController) DeleteContainer() []error

func (*BasicController) DeleteKind

func (c *BasicController) DeleteKind(kind Kind) error

func (*BasicController) GetContainer

func (c *BasicController) GetContainer() []error

func (*BasicController) GetKind

func (c *BasicController) GetKind(kind Kind) (res Resource, err error)

func (*BasicController) Hooks

func (c *BasicController) Hooks() Hooks

type ClientSet

type ClientSet interface {
	Namespace() string
	Client() *kubernetes.Clientset
	Namespaces() typedv1core.NamespaceInterface
	Deployments() typedv1apps.DeploymentInterface
	Ingresses() typedv1beta1net.IngressInterface
	Secrets() typedv1core.SecretInterface
	Services() typedv1core.ServiceInterface
	ConfigMaps() typedv1core.ConfigMapInterface
	PersistentVolumeClaims() typedv1core.PersistentVolumeClaimInterface
}

ClientSet is meant to manipulate Resource state in kubernetes

func NewClientSet

func NewClientSet(namespace string, client *kubernetes.Clientset) ClientSet

NewClientSet creates new KubeClientSet for a given namespace

type Container

type Container interface {
	Kinds() []Kind                  // Kinds() should returns container Kind's
	Self() Container                // Self() returns the Container instance itself
	Copy() Container                // Copy() should return a copy of Container so it can be declared once per package
	Update(Kind, Resource) error    // Update() overrides underlying Kind Resource
	GetResource(Kind) Resource      // GetResource() returns underlying Resource for a Kind
	ForEachResource(func(Resource)) // ForEachResource() performs function on each Resource
	ForEachKind(func(Kind))         // ForEachKind() performs function on each Kind

	// caster methods to get underlying Resource instance for a Kind
	Namespace(Kind) *v1core.Namespace
	Deployment(Kind) *v1apps.Deployment
	Ingress(Kind) *v1beta1net.Ingress
	Secret(Kind) *v1core.Secret
	Service(Kind) *v1core.Service
	ConfigMap(Kind) *v1core.ConfigMap
	PersistentVolumeClaim(Kind) *v1core.PersistentVolumeClaim
}

Container is meant to hold binding between Kind and it's Resource

type Controller

type Controller interface {
	Container // Container of which Controller is in control

	Hooks() Hooks
	Configure(option Option) // Configure accepts Option to modify Controller
	ClientSet() ClientSet

	// todo should hooks run here?
	GetKind(Kind) (Resource, error)    // GetKind(Kind) performs kubernetes get request updating underlying Resource
	CreateKind(Kind) (Resource, error) // CreateKind(Kind) performs kubernetes create request for underlying Resource
	DeleteKind(Kind) error             // DeleteKind(Kind) performs kubernetes delete request for underlying Resource

	GetContainer() []error    // GetContainer() performs kubernetes get request for all Kind's in Container
	CreateContainer() []error // CreateContainer() performs kubernetes create request for all Kind's in Container
	DeleteContainer() []error // DeleteContainer() performs kubernetes delete request for all Kind's in Container
}

Controller is meant to perform actions on Container via ClientSet a Controller can use Container New() method to construct itself - that allows declaring Container once per package. Each method on Controller handles the underlying Container - updating Resource's that it holds.

func NewController

func NewController(container Container, opts ...Option) Controller

NewController creates new Controller

type Hook

type Hook func(Container) error

Hook is a hook for a Container for ex. hooks.SetLabels sets labels for all Resource's in a Container

type HookErr

type HookErr func(Container, Kind, error) error

HookErr is a hook that happens when an error occurs during get/create/delete

type HookErrType

type HookErrType string

type HookType

type HookType string

type Hooks

type Hooks map[HookType][]Hook

HookMap is a map of slice of Hook executed for specified Kind

type HooksErr

type HooksErr map[HookErrType][]HookErr

HooksErr is a map of HookErr executed when an error occurs

type HooksManager

type HooksManager interface {
	Hooks() Hooks
	Override(Hooks)
	Register(Hooks)
}

todo hooks per kind

type Kind

type Kind interface {
	Name() string
	Cast() Resource // Cast() should return new instance of Resource
	Delete(contr ClientSet, ctx context.Context, name string, opts v1meta.DeleteOptions) error
	Get(contr ClientSet, ctx context.Context, name string, opts v1meta.GetOptions) (Resource, error)
	Create(contr ClientSet, ctx context.Context, res Resource, opts v1meta.CreateOptions) (Resource, error)
}

Kind is meant to be declared as a constant, that is - a string that allows accessing the underlying kubernetes state of the Resource in a typed (constant) way via Container.

type Option

type Option func(*BasicController)

type Resource

Resource represents kubernetes resource grouping common interfaces that they implement

Directories

Path Synopsis
testing

Jump to

Keyboard shortcuts

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