kube

package module
v0.0.0-...-48b8188 Latest Latest
Warning

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

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

README

A Simple Kubernetes Client in Go

This package is part of the blog article Building a Kubernetes Client in Go.

This is a work in progress, until patch() is not done the Apply() will fail.

TODO

  • Complete the patch() method
  • Documentation
  • Testing
  • Add more simple features

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRESTConfig

func BuildRESTConfig(context, kubeconfig string) (*rest.Config, error)

BuildRESTConfig builds a kubernetes REST client config using the following rules from ToRawKubeConfigLoader()

Types

type Client

type Client struct {
	Config *Config
	// contains filtered or unexported fields
}

Client is a kubernetes client, like `kubectl`

func NewClient

func NewClient(context, kubeconfig string) *Client

NewClient creates a kubernetes client

func NewClientE

func NewClientE(context, kubeconfig string) (*Client, error)

NewClientE creates a kubernetes client, returns an error if fail

func (*Client) Apply

func (c *Client) Apply(content []byte) error

Apply creates a resource with the given content

func (*Client) ApplyFile

func (c *Client) ApplyFile(filename string) error

Apply creates a resource with the given content

func (*Client) ApplyNamespace

func (c *Client) ApplyNamespace(namespace string) error

ApplyNamespace creates the given namespace if does not exists

func (*Client) Builder

func (c *Client) Builder() *resource.Builder

Builder creates a builder for the given namespace

func (*Client) Create

func (c *Client) Create(content []byte) error

Create creates a resource with the given content

func (*Client) CreateFile

func (c *Client) CreateFile(filename string) error

CreateFile creates a resource with the given content

func (*Client) CreateNamespace

func (c *Client) CreateNamespace(namespace string) error

CreateNamespace creates a namespace with the given name

func (*Client) Namespace

func (c *Client) Namespace(namespace string) (*v1.Namespace, error)

Namespace returns the namespace with the given name. If not found returns a IsNotFound error

func (*Client) ResultForContent

func (c *Client) ResultForContent(content []byte, unstructured bool) *resource.Result

ResultForContent returns the builder results for the given content

func (*Client) ResultForFilenameParam

func (c *Client) ResultForFilenameParam(filenames []string, unstructured bool) *resource.Result

ResultForFilenameParam returns the builder results for the given list of files or URLs

func (*Client) ResultForReader

func (c *Client) ResultForReader(r io.Reader, unstructured bool) *resource.Result

ResultForReader returns the builder results for the given reader

func (*Client) UnstructuredBuilder

func (c *Client) UnstructuredBuilder() *resource.Builder

UnstructuredBuilder creates an unstructure builder for the given namespace

type Config

type Config struct {
	KubeConfig string
	Context    string
	// contains filtered or unexported fields
}

Config is the client configuration. It implements RESTClientGetter

func NewConfig

func NewConfig(context, kubeconfig string) *Config

NewConfig creates a new client configuration

func (*Config) ClientForMapping

func (c *Config) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)

ClientForMapping creates a resource REST client from the given mappings

func (*Config) DynamicClient

func (c *Config) DynamicClient() (dynamic.Interface, error)

DynamicClient creates a dynamic client from the configuration

func (*Config) KubernetesClientSet

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

KubernetesClientSet creates a kubernetes clientset from the configuration

func (*Config) NewBuilder

func (c *Config) NewBuilder() *resource.Builder

NewBuilder returns a new resource builder for structured api objects.

func (*Config) OpenAPISchema

func (c *Config) OpenAPISchema() (openapi.Resources, error)

OpenAPISchema returns metadata and structural information about Kubernetes object definitions.

func (*Config) RESTClient

func (c *Config) RESTClient() (*rest.RESTClient, error)

RESTClient creates a REST client from the configuration

func (*Config) ToDiscoveryClient

func (c *Config) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

ToDiscoveryClient returns a CachedDiscoveryInterface using a computed RESTConfig

func (*Config) ToRESTConfig

func (c *Config) ToRESTConfig() (*rest.Config, error)

ToRESTConfig creates a kubernetes REST client config

func (*Config) ToRESTMapper

func (c *Config) ToRESTMapper() (meta.RESTMapper, error)

ToRESTMapper returns a mapper

func (*Config) ToRawKubeConfigLoader

func (c *Config) ToRawKubeConfigLoader() clientcmd.ClientConfig

ToRawKubeConfigLoader creates a client config using the following rules: 1. builds from the given kubeconfig path, if not empty 2. use the in cluster config if running in-cluster 3. gets the config from KUBECONFIG env var 4. Uses $HOME/.kube/config

func (*Config) UnstructuredClientForMapping

func (c *Config) UnstructuredClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error)

UnstructuredClientForMapping creates a unstructured resource REST client from the given mappings

func (*Config) Validator

func (c *Config) Validator(validate bool) (validation.Schema, error)

Validator returns a schema that can validate objects stored on disk.

Jump to

Keyboard shortcuts

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