kube

package
v3.0.0-alpha.1+incompa... Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoObjectsVisited = errors.New("no objects visited")

ErrNoObjectsVisited indicates that during a visit operation, no matching objects were found.

Functions

func GetConfig

func GetConfig(kubeconfig, context, namespace string) *genericclioptions.ConfigFlags

GetConfig returns a Kubernetes client config.

Types

type Client

type Client struct {
	Factory Factory
	Log     func(string, ...interface{})
}

Client represents a client capable of communicating with the Kubernetes API.

func New

New creates a new Client.

func (*Client) Build

func (c *Client) Build(reader io.Reader) (Result, error)

Build validates for Kubernetes objects and returns resource Infos from a io.Reader.

func (*Client) BuildUnstructured

func (c *Client) BuildUnstructured(reader io.Reader) (Result, error)

BuildUnstructured validates for Kubernetes objects and returns unstructured infos.

func (*Client) Create

func (c *Client) Create(reader io.Reader) error

Create creates Kubernetes resources from an io.reader.

Namespace will set the namespace.

func (*Client) Delete

func (c *Client) Delete(reader io.Reader) error

Delete deletes Kubernetes resources from an io.reader.

Namespace will set the namespace.

func (*Client) KubernetesClientSet

func (c *Client) KubernetesClientSet() (*kubernetes.Clientset, error)

KubernetesClientSet returns a client set from the client factory.

func (*Client) Update

func (c *Client) Update(originalReader, targetReader io.Reader, force, recreate bool) error

Update reads in the current configuration and a target configuration from io.reader and creates resources that don't already exists, updates resources that have been modified in the target configuration and deletes resources from the current configuration that are not present in the target configuration.

Namespace will set the namespaces.

func (*Client) Wait

func (c *Client) Wait(reader io.Reader, timeout time.Duration) error

func (*Client) WaitAndGetCompletedPodPhase

func (c *Client) WaitAndGetCompletedPodPhase(name string, timeout time.Duration) (v1.PodPhase, error)

WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase and returns said phase (PodSucceeded or PodFailed qualify).

func (*Client) WatchUntilReady

func (c *Client) WatchUntilReady(reader io.Reader, timeout time.Duration) error

WatchUntilReady watches the resource given in the reader, and waits until it is ready.

This function is mainly for hook implementations. It watches for a resource to hit a particular milestone. The milestone depends on the Kind.

For most kinds, it checks to see if the resource is marked as Added or Modified by the Kubernetes event stream. For some kinds, it does more:

  • Jobs: A job is marked "Ready" when it has successfully completed. This is ascertained by watching the Status fields in a job's output.

Handling for other kinds will be added as necessary.

type Factory

type Factory interface {
	// ToRawKubeConfigLoader return kubeconfig loader as-is
	ToRawKubeConfigLoader() clientcmd.ClientConfig
	// KubernetesClientSet gives you back an external clientset
	KubernetesClientSet() (*kubernetes.Clientset, error)
	// NewBuilder returns an object that assists in loading objects from both disk and the server
	// and which implements the common patterns for CLI interactions with generic resources.
	NewBuilder() *resource.Builder
	// Returns a schema that can validate objects stored on disk.
	Validator(validate bool) (validation.Schema, error)
}

Factory provides abstractions that allow the Kubectl command to be extended across multiple types of resources and different API sets.

type Interface

type Interface interface {
	// Create creates one or more resources.
	//
	// reader must contain a YAML stream (one or more YAML documents separated
	// by "\n---\n").
	Create(reader io.Reader) error

	Wait(r io.Reader, timeout time.Duration) error

	// Delete destroys one or more resources.
	//
	// reader must contain a YAML stream (one or more YAML documents separated
	// by "\n---\n").
	Delete(io.Reader) error

	// Watch the resource in reader until it is "ready".
	//
	// For Jobs, "ready" means the job ran to completion (excited without error).
	// For all other kinds, it means the kind was created or modified without
	// error.
	WatchUntilReady(reader io.Reader, timeout time.Duration) error

	// Update updates one or more resources or creates the resource
	// if it doesn't exist.
	//
	// reader must contain a YAML stream (one or more YAML documents separated
	// by "\n---\n").
	Update(originalReader, modifiedReader io.Reader, force bool, recreate bool) error

	Build(reader io.Reader) (Result, error)
	BuildUnstructured(reader io.Reader) (Result, error)

	// WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase
	// and returns said phase (PodSucceeded or PodFailed qualify).
	WaitAndGetCompletedPodPhase(name string, timeout time.Duration) (v1.PodPhase, error)
}

KubernetesClient represents a client capable of communicating with the Kubernetes API.

A KubernetesClient must be concurrency safe.

type PrintingKubeClient

type PrintingKubeClient struct {
	Out io.Writer
}

PrintingKubeClient implements KubeClient, but simply prints the reader to the given output.

func (*PrintingKubeClient) Build

func (p *PrintingKubeClient) Build(_ io.Reader) (Result, error)

Build implements KubeClient Build.

func (*PrintingKubeClient) BuildUnstructured

func (p *PrintingKubeClient) BuildUnstructured(_ io.Reader) (Result, error)

func (*PrintingKubeClient) Create

func (p *PrintingKubeClient) Create(r io.Reader) error

Create prints the values of what would be created with a real KubeClient.

func (*PrintingKubeClient) Delete

func (p *PrintingKubeClient) Delete(r io.Reader) error

Delete implements KubeClient delete.

It only prints out the content to be deleted.

func (*PrintingKubeClient) Get

func (p *PrintingKubeClient) Get(r io.Reader) (string, error)

Get prints the values of what would be created with a real KubeClient.

func (*PrintingKubeClient) Update

func (p *PrintingKubeClient) Update(_, modifiedReader io.Reader, _, _ bool) error

Update implements KubeClient Update.

func (*PrintingKubeClient) Wait

func (*PrintingKubeClient) WaitAndGetCompletedPodPhase

func (p *PrintingKubeClient) WaitAndGetCompletedPodPhase(_ string, _ time.Duration) (v1.PodPhase, error)

WaitAndGetCompletedPodPhase implements KubeClient WaitAndGetCompletedPodPhase.

func (*PrintingKubeClient) WatchUntilReady

func (p *PrintingKubeClient) WatchUntilReady(r io.Reader, _ time.Duration) error

WatchUntilReady implements KubeClient WatchUntilReady.

type Result

type Result []*resource.Info

Result provides convenience methods for comparing collections of Infos.

func (*Result) Append

func (r *Result) Append(val *resource.Info)

Append adds an Info to the Result.

func (Result) Contains

func (r Result) Contains(info *resource.Info) bool

Contains checks to see if an object exists.

func (Result) Difference

func (r Result) Difference(rs Result) Result

Difference will return a new Result with objects not contained in rs.

func (Result) Filter

func (r Result) Filter(fn func(*resource.Info) bool) Result

Filter returns a new Result with Infos that satisfy the predicate fn.

func (Result) Get

func (r Result) Get(info *resource.Info) *resource.Info

Get returns the Info from the result that matches the name and kind.

func (Result) Intersect

func (r Result) Intersect(rs Result) Result

Intersect will return a new Result with objects contained in both Results.

func (Result) Visit

func (r Result) Visit(fn resource.VisitorFunc) error

Visit implements resource.Visitor.

Jump to

Keyboard shortcuts

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