client

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNoHeader = fmt.Errorf("table has no header")

ErrorNoHeader occurs when the table lacks an ALL-CAPS header

View Source
var ErrorNoMatch = errors.New("no matches found")

ErrorNoMatch occurs when no item matched had the expected value

Functions

func ContextFromIP added in v0.7.0

func ContextFromIP(apiServer string) (*Cluster, *Context, error)

ContextFromIP searches the $KUBECONFIG for a context using a cluster that matches the apiServer

func ContextFromName added in v0.21.0

func ContextFromName(contextName string) (*Cluster, *Context, error)

func Contexts added in v0.7.0

func Contexts() ([]string, error)

Contexts returns a list of context names

func IPFromContext added in v0.7.0

func IPFromContext(name string) (ip string, err error)

IPFromContext parses $KUBECONFIG, finds the cluster with the given name and returns the cluster's endpoint

func Kubeconfig added in v0.7.0

func Kubeconfig() (objx.Map, error)

Kubeconfig returns the merged $KUBECONFIG of the host

func UnmarshalTable added in v0.9.0

func UnmarshalTable(raw string, ptr interface{}) error

UnmarshalTable unmarshals a raw CLI table into ptr. `json` package is used for getting the dat into the ptr, `json:` struct tags can be used.

Types

type ApplyOpts

type ApplyOpts struct {
	// force allows to ignore checks and force the operation
	Force bool

	// validate allows to enable/disable kubectl validation
	Validate bool

	// autoApprove allows to skip the interactive approval
	AutoApprove bool

	// DryRun string passed to kubectl as --dry-run=<DryRun>
	DryRun string

	// ApplyStrategy to pick a final method for deploying generated objects
	ApplyStrategy string
}

ApplyOpts allow to specify additional parameter for apply operations

type Client

type Client interface {
	// Get the specified object(s) from the cluster
	Get(namespace, kind, name string) (manifest.Manifest, error)
	GetByLabels(namespace, kind string, labels map[string]string) (manifest.List, error)
	GetByState(data manifest.List, opts GetByStateOpts) (manifest.List, error)

	// Apply the configuration to the cluster. `data` must contain a plaintext
	// format that is `kubectl-apply(1)` compatible
	Apply(data manifest.List, opts ApplyOpts) error

	// DiffServerSide runs the diff operation on the server and returns the
	// result in `diff(1)` format
	DiffServerSide(data manifest.List) (*string, error)

	// Delete the specified object(s) from the cluster
	Delete(namespace, kind, name string, opts DeleteOpts) error

	// Namespaces the cluster currently has
	Namespaces() (map[string]bool, error)

	// Namespace retrieves a namespace from the cluster
	Namespace(namespace string) (manifest.Manifest, error)

	// Resources returns all known api-resources of the cluster
	Resources() (Resources, error)

	// Info returns known informational data about the client. Best effort based,
	// fields of `Info` that cannot be stocked with valuable data, e.g.
	// due to an error, shall be left nil.
	Info() Info

	// Close may run tasks once the client is no longer needed.
	Close() error
}

Client for working with Kubernetes

type Cluster added in v0.9.0

type Cluster struct {
	Cluster struct {
		Server string `json:"server"`
	} `json:"cluster"`
	Name string `json:"name"`
}

Cluster is a kubectl cluster

type Config added in v0.9.0

type Config struct {
	Cluster Cluster `json:"cluster"`
	Context Context `json:"context"`
}

Config represents a single KUBECONFIG entry (single context + cluster) Omits the arrays of the original schema, to ease using.

type Context added in v0.9.0

type Context struct {
	Context struct {
		Cluster   string `json:"cluster"`
		User      string `json:"user"`
		Namespace string `json:"namespace"`
	} `json:"context"`
	Name string `json:"name"`
}

Context is a kubectl context

type DeleteOpts

type DeleteOpts ApplyOpts

DeleteOpts allow to specify additional parameters for delete operations Currently not different from ApplyOpts, but may be required in the future

type ErrNamespaceNotFound added in v0.15.1

type ErrNamespaceNotFound struct {
	Namespace string
}

func (ErrNamespaceNotFound) Error added in v0.15.1

func (e ErrNamespaceNotFound) Error() string

type ErrorElementsMismatch added in v0.9.0

type ErrorElementsMismatch struct {
	Header, Row int
}

ErrorElementsMismatch occurs when a row has a different count of elements than it's header

func (ErrorElementsMismatch) Error added in v0.9.0

func (e ErrorElementsMismatch) Error() string

type ErrorNoCluster added in v0.9.0

type ErrorNoCluster string

ErrorNoCluster means that the cluster that was searched for couldn't be found

func (ErrorNoCluster) Error added in v0.9.0

func (e ErrorNoCluster) Error() string

type ErrorNoContext added in v0.9.0

type ErrorNoContext string

ErrorNoContext means that the context that was searched for couldn't be found

func (ErrorNoContext) Error added in v0.9.0

func (e ErrorNoContext) Error() string

type ErrorNotFound

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

ErrorNotFound means that the requested object is not found on the server

func (ErrorNotFound) Error

func (e ErrorNotFound) Error() string

type ErrorNothingReturned added in v0.14.0

type ErrorNothingReturned struct{}

ErrorNothingReturned means that there was no output returned

func (ErrorNothingReturned) Error added in v0.14.0

func (e ErrorNothingReturned) Error() string

type ErrorUnknownResource

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

ErrorUnknownResource means that the requested resource type is unknown to the server

func (ErrorUnknownResource) Error

func (e ErrorUnknownResource) Error() string

type FilterWriter

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

FilterWriter is an io.Writer that discards every message that matches at least one of the regular expressions.

func (*FilterWriter) Write

func (r *FilterWriter) Write(p []byte) (n int, err error)

type GetByStateOpts added in v0.14.0

type GetByStateOpts struct {
	// ignoreNotFound allows to ignore errors caused by missing objects
	IgnoreNotFound bool
}

GetByStateOpts allow to specify additional parameters for GetByState function Currently there is just ignoreNotFound parameter which is only useful for GetByState() so we only have GetByStateOpts instead of more generic GetOpts for all get operations

type Info

type Info struct {
	// versions
	ClientVersion *semver.Version
	ServerVersion *semver.Version

	// kubeconfig (chosen context + cluster)
	Kubeconfig Config
}

Info contains metadata about the client and its environment

type Kubectl

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

Kubectl uses the `kubectl` command to operate on a Kubernetes cluster

func New

func New(endpoint string) (*Kubectl, error)

New returns a instance of Kubectl with a correct context already discovered.

func NewFromNames added in v0.21.0

func NewFromNames(names []string) (*Kubectl, error)

func (Kubectl) Apply

func (k Kubectl) Apply(data manifest.List, opts ApplyOpts) error

Apply applies the given yaml to the cluster

func (Kubectl) Close added in v0.9.0

func (k Kubectl) Close() error

Close runs final cleanup:

func (Kubectl) Delete

func (k Kubectl) Delete(namespace, kind, name string, opts DeleteOpts) error

Delete deletes the given Kubernetes resource from the cluster

func (Kubectl) DiffClientSide added in v0.17.0

func (k Kubectl) DiffClientSide(data manifest.List) (*string, error)

DiffClientSide takes the desired state and computes the differences, returning them in `diff(1)` format

func (Kubectl) DiffServerSide

func (k Kubectl) DiffServerSide(data manifest.List) (*string, error)

DiffServerSide takes the desired state and computes the differences server-side, returning them in `diff(1)` format

func (Kubectl) Get

func (k Kubectl) Get(namespace, kind, name string) (manifest.Manifest, error)

Get retrieves a single Kubernetes object from the cluster

func (Kubectl) GetByLabels

func (k Kubectl) GetByLabels(namespace, kind string, labels map[string]string) (manifest.List, error)

GetByLabels retrieves all objects matched by the given labels from the cluster. Set namespace to empty string for --all-namespaces

func (Kubectl) GetByState added in v0.10.0

func (k Kubectl) GetByState(data manifest.List, opts GetByStateOpts) (manifest.List, error)

GetByState returns the full object, including runtime fields for each resource in the state

func (Kubectl) Info

func (k Kubectl) Info() Info

Info returns known informational data about the client and its environment

func (Kubectl) Namespace added in v0.15.1

func (k Kubectl) Namespace(namespace string) (manifest.Manifest, error)

Namespace finds a single namespace in the cluster

func (Kubectl) Namespaces

func (k Kubectl) Namespaces() (map[string]bool, error)

Namespaces of the cluster

func (Kubectl) Resources added in v0.9.0

func (k Kubectl) Resources() (Resources, error)

Resources returns all API resources known to the server

func (Kubectl) ValidateServerSide added in v0.21.0

func (k Kubectl) ValidateServerSide(data manifest.List) (*string, error)

ValidateServerSide takes the desired state and computes the differences, returning them in `diff(1)` format It also validates that manifests are valid server-side, but still returns the client-side diff

type Resource added in v0.9.0

type Resource struct {
	APIGroup   string `json:"APIGROUP"`
	APIVersion string `json:"APIVERSION"`
	Kind       string `json:"KIND"`
	Name       string `json:"NAME"`
	Namespaced bool   `json:"NAMESPACED,string"`
	Shortnames string `json:"SHORTNAMES"`
	Verbs      string `json:"VERBS"`
	Categories string `json:"CATEGORIES"`
}

Resource is a Kubernetes API Resource

func (Resource) FQN added in v0.10.0

func (r Resource) FQN() string

type Resources added in v0.9.0

type Resources []Resource

Resources the Kubernetes API knows

func (Resources) Namespaced added in v0.9.0

func (r Resources) Namespaced(m manifest.Manifest) bool

Namespaced returns whether a resource is namespace-specific or cluster-wide

Jump to

Keyboard shortcuts

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