kube

package
Version: v3.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: Apache-2.0 Imports: 42 Imported by: 83

Documentation

Index

Constants

View Source
const KeepPolicy = "keep"

KeepPolicy is the resource policy type for keep

This resource policy type allows resources to skip being deleted

during an uninstallRelease action.
View Source
const ResourcePolicyAnno = "helm.sh/resource-policy"

ResourcePolicyAnno is the annotation name for a resource policy

Variables

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

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

View Source
var ManagedFieldsManager string

ManagedFieldsManager is the name of the manager of Kubernetes managedFields first introduced in Kubernetes 1.18

Functions

func AsVersioned

func AsVersioned(info *resource.Info) runtime.Object

AsVersioned converts the given info into a runtime.Object with the correct group and version set

func GetConfig

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

GetConfig returns a Kubernetes client config.

Deprecated

func SelectorsForObject

func SelectorsForObject(object runtime.Object) (selector labels.Selector, err error)

SelectorsForObject returns the pod label selector for a given object

Modified version of https://github.com/kubernetes/kubernetes/blob/v1.14.1/pkg/kubectl/polymorphichelpers/helpers.go#L84

Types

type Client

type Client struct {
	Factory Factory
	Log     func(string, ...interface{})
	// Namespace allows to bypass the kubeconfig file for the choice of the namespace
	Namespace string
	// contains filtered or unexported fields
}

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, validate bool) (ResourceList, error)

Build validates for Kubernetes objects and returns unstructured infos.

func (*Client) Create

func (c *Client) Create(resources ResourceList) (*Result, error)

Create creates Kubernetes resources specified in the resource list.

func (*Client) Delete

func (c *Client) Delete(resources ResourceList) (*Result, []error)

Delete deletes Kubernetes resources specified in the resources list. It will attempt to delete all resources even if one or more fail and collect any errors. All successfully deleted items will be returned in the `Deleted` ResourceList that is part of the result.

func (*Client) IsReachable

func (c *Client) IsReachable() error

IsReachable tests connectivity to the cluster.

func (*Client) Update

func (c *Client) Update(original, target ResourceList, force bool) (*Result, error)

Update takes the current list of objects and target list of objects and creates resources that don't already exist, 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. If an error occurs, a Result will still be returned with the error, containing all resource updates, creations, and deletions that were attempted. These can be used for cleanup or other logging purposes.

func (*Client) Wait

func (c *Client) Wait(resources ResourceList, timeout time.Duration) error

Wait waits up to the given timeout for the specified resources to be ready.

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) WaitForDelete added in v3.7.0

func (c *Client) WaitForDelete(resources ResourceList, timeout time.Duration) error

WaitForDelete wait up to the given timeout for the specified resources to be deleted.

func (*Client) WaitWithJobs added in v3.5.0

func (c *Client) WaitWithJobs(resources ResourceList, timeout time.Duration) error

WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs.

func (*Client) WatchUntilReady

func (c *Client) WatchUntilReady(resources ResourceList, timeout time.Duration) error

WatchUntilReady watches the resources given and waits until it is ready.

This method 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.
  • Pods: A pod is marked "Ready" when it has successfully completed. This is ascertained by watching the status.phase field in a pod'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.
	Create(resources ResourceList) (*Result, error)

	// Wait waits up to the given timeout for the specified resources to be ready.
	Wait(resources ResourceList, timeout time.Duration) error

	// WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs.
	WaitWithJobs(resources ResourceList, timeout time.Duration) error

	// Delete destroys one or more resources.
	Delete(resources ResourceList) (*Result, []error)

	// WatchUntilReady watches the resources given and waits until it is ready.
	//
	// This method is mainly for hook implementations. It watches for a resource to
	// hit a particular milestone. The milestone depends on the Kind.
	//
	// For Jobs, "ready" means the Job ran to completion (exited without error).
	// For Pods, "ready" means the Pod phase is marked "succeeded".
	// For all other kinds, it means the kind was created or modified without
	// error.
	WatchUntilReady(resources ResourceList, timeout time.Duration) error

	// Update updates one or more resources or creates the resource
	// if it doesn't exist.
	Update(original, target ResourceList, force bool) (*Result, error)

	// Build creates a resource list from a Reader.
	//
	// Reader must contain a YAML stream (one or more YAML documents separated
	// by "\n---\n")
	//
	// Validates against OpenAPI schema if validate is true.
	Build(reader io.Reader, validate bool) (ResourceList, 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)

	// IsReachable checks whether the client is able to connect to the cluster.
	IsReachable() error
}

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

A KubernetesClient must be concurrency safe.

type InterfaceExt added in v3.7.0

type InterfaceExt interface {
	// WaitForDelete wait up to the given timeout for the specified resources to be deleted.
	WaitForDelete(resources ResourceList, timeout time.Duration) error
}

InterfaceExt is introduced to avoid breaking backwards compatibility for Interface implementers.

TODO Helm 4: Remove InterfaceExt and integrate its method(s) into the Interface.

type ReadyChecker added in v3.6.0

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

ReadyChecker is a type that can check core Kubernetes types for readiness.

func NewReadyChecker added in v3.6.0

func NewReadyChecker(cl kubernetes.Interface, log func(string, ...interface{}), opts ...ReadyCheckerOption) ReadyChecker

NewReadyChecker creates a new checker. Passed ReadyCheckerOptions can be used to override defaults.

func (*ReadyChecker) IsReady added in v3.6.0

func (c *ReadyChecker) IsReady(ctx context.Context, v *resource.Info) (bool, error)

IsReady checks if v is ready. It supports checking readiness for pods, deployments, persistent volume claims, services, daemon sets, custom resource definitions, stateful sets, replication controllers, and replica sets. All other resource kinds are always considered ready.

IsReady will fetch the latest state of the object from the server prior to performing readiness checks, and it will return any error encountered.

type ReadyCheckerOption added in v3.6.0

type ReadyCheckerOption func(*ReadyChecker)

ReadyCheckerOption is a function that configures a ReadyChecker.

func CheckJobs added in v3.6.0

func CheckJobs(checkJobs bool) ReadyCheckerOption

CheckJobs returns a ReadyCheckerOption that configures a ReadyChecker to consider readiness of Job resources.

func PausedAsReady added in v3.6.0

func PausedAsReady(pausedAsReady bool) ReadyCheckerOption

PausedAsReady returns a ReadyCheckerOption that configures a ReadyChecker to consider paused resources to be ready. For example a Deployment with spec.paused equal to true would be considered ready.

type ResourceList

type ResourceList []*resource.Info

ResourceList provides convenience methods for comparing collections of Infos.

func (*ResourceList) Append

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

Append adds an Info to the Result.

func (ResourceList) Contains

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

Contains checks to see if an object exists.

func (ResourceList) Difference

func (r ResourceList) Difference(rs ResourceList) ResourceList

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

func (ResourceList) Filter

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

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

func (ResourceList) Get

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

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

func (ResourceList) Intersect

func (r ResourceList) Intersect(rs ResourceList) ResourceList

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

func (ResourceList) Visit

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

Visit implements resource.Visitor.

type Result

type Result struct {
	Created ResourceList
	Updated ResourceList
	Deleted ResourceList
}

Result contains the information of created, updated, and deleted resources for various kube API calls along with helper methods for using those resources

Directories

Path Synopsis
Package fake implements various fake KubeClients for use in testing
Package fake implements various fake KubeClients for use in testing

Jump to

Keyboard shortcuts

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