kubectl

package
v1.14.1-beta.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package kubectl provides the functions used by the kubectl command line tool under k8s.io/kubernetes/cmd. The functions are kept in this package to better support unit testing. The main() method for kubectl is only an entry point and should contain no functionality.

Index

Constants

View Source
const (
	ChangeCauseAnnotation = "kubernetes.io/change-cause"
)

Variables

View Source
var ErrPodCompleted = fmt.Errorf("pod ran to completion")

ErrPodCompleted is returned by PodRunning or PodContainerRunning to indicate that the pod has already reached completed state.

Functions

func AbortRollingUpdate added in v0.17.0

func AbortRollingUpdate(c *RollingUpdaterConfig) error

func AddDeploymentKeyToReplicationController added in v0.17.0

func AddDeploymentKeyToReplicationController(oldRc *corev1.ReplicationController, rcClient corev1client.ReplicationControllersGetter, podClient corev1client.PodsGetter, deploymentKey, deploymentValue, namespace string, out io.Writer) (*corev1.ReplicationController, error)

func ControllerHasDesiredReplicas added in v1.10.0

func ControllerHasDesiredReplicas(rcClient corev1client.ReplicationControllersGetter, controller *corev1.ReplicationController) wait.ConditionFunc

ControllerHasDesiredReplicas returns a condition that will be true if and only if the desired replica count for a controller's ReplicaSelector equals the Replicas count.

func CreateApplyAnnotation added in v1.2.0

func CreateApplyAnnotation(obj runtime.Object, codec runtime.Encoder) error

CreateApplyAnnotation gets the modified configuration of the object, without embedding it again, and then sets it on the object as the annotation.

func CreateNewControllerFromCurrentController added in v0.17.0

func CreateNewControllerFromCurrentController(rcClient corev1client.ReplicationControllersGetter, codec runtime.Codec, cfg *NewControllerConfig) (*corev1.ReplicationController, error)

func CreateOrUpdateAnnotation added in v1.2.0

func CreateOrUpdateAnnotation(createAnnotation bool, obj runtime.Object, codec runtime.Encoder) error

CreateOrUpdateAnnotation creates the annotation used by kubectl apply only when createAnnotation is true Otherwise, only update the annotation when it already exists

func FindSourceController added in v0.17.0

func FindSourceController(r corev1client.ReplicationControllersGetter, namespace, name string) (*corev1.ReplicationController, error)

func GetModifiedConfiguration added in v1.1.1

func GetModifiedConfiguration(obj runtime.Object, annotate bool, codec runtime.Encoder) ([]byte, error)

GetModifiedConfiguration retrieves the modified configuration of the object. If annotate is true, it embeds the result as an annotation in the modified configuration. If an object was read from the command input, it will use that version of the object. Otherwise, it will use the version from the server.

func GetNextControllerAnnotation added in v0.17.0

func GetNextControllerAnnotation(rc *corev1.ReplicationController) (string, bool)

func GetOriginalConfiguration added in v1.1.1

func GetOriginalConfiguration(obj runtime.Object) ([]byte, error)

GetOriginalConfiguration retrieves the original configuration of the object from the annotation, or nil if no annotation was found.

func LoadExistingNextReplicationController added in v0.17.0

func LoadExistingNextReplicationController(c corev1client.ReplicationControllersGetter, namespace, newName string) (*corev1.ReplicationController, error)

func PodCompleted added in v1.10.0

func PodCompleted(event watch.Event) (bool, error)

PodCompleted returns true if the pod has run to completion, false if the pod has not yet reached running state, or an error in any other case.

func PodRunningAndReady added in v1.10.0

func PodRunningAndReady(event watch.Event) (bool, error)

PodRunningAndReady returns true if the pod is running and ready, false if the pod has not yet reached those states, returns ErrPodCompleted if the pod has run to completion, or an error in any other case.

func Rename added in v0.17.0

func ScaleCondition added in v0.18.0

func ScaleCondition(r Scaler, precondition *ScalePrecondition, namespace, name string, count uint, updatedResourceVersion *string, gr schema.GroupResource) wait.ConditionFunc

ScaleCondition is a closure around Scale that facilitates retries via util.wait

func SetNextControllerAnnotation added in v0.17.0

func SetNextControllerAnnotation(rc *corev1.ReplicationController, name string)

func UpdateApplyAnnotation added in v1.1.1

func UpdateApplyAnnotation(obj runtime.Object, codec runtime.Encoder) error

UpdateApplyAnnotation calls CreateApplyAnnotation if the last applied configuration annotation is already present. Otherwise, it does nothing.

func UpdateExistingReplicationController added in v0.17.0

func UpdateExistingReplicationController(rcClient corev1client.ReplicationControllersGetter, podClient corev1client.PodsGetter, oldRc *corev1.ReplicationController, namespace, newName, deploymentKey, deploymentValue string, out io.Writer) (*corev1.ReplicationController, error)

func WaitForScaleHasDesiredReplicas added in v1.11.0

func WaitForScaleHasDesiredReplicas(sClient scaleclient.ScalesGetter, gr schema.GroupResource, resourceName string, namespace string, newSize uint, waitForReplicas *RetryParams) error

WaitForScaleHasDesiredReplicas waits until condition scaleHasDesiredReplicas is satisfied or returns error when timeout happens

Types

type DaemonSetHistoryViewer added in v1.7.0

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

func (*DaemonSetHistoryViewer) ViewHistory added in v1.7.0

func (h *DaemonSetHistoryViewer) ViewHistory(namespace, name string, revision int64) (string, error)

ViewHistory returns a revision-to-history map as the revision history of a deployment TODO: this should be a describer

type DaemonSetRollbacker added in v1.7.0

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

func (*DaemonSetRollbacker) Rollback added in v1.7.0

func (r *DaemonSetRollbacker) Rollback(obj runtime.Object, updatedAnnotations map[string]string, toRevision int64, dryRun bool) (string, error)

type DaemonSetStatusViewer added in v1.6.0

type DaemonSetStatusViewer struct{}

DaemonSetStatusViewer implements the StatusViewer interface.

func (*DaemonSetStatusViewer) Status added in v1.6.0

func (s *DaemonSetStatusViewer) Status(obj runtime.Unstructured, revision int64) (string, bool, error)

Status returns a message describing daemon set status, and a bool value indicating if the status is considered done.

type DeploymentHistoryViewer added in v1.2.0

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

func (*DeploymentHistoryViewer) ViewHistory added in v1.4.0

func (h *DeploymentHistoryViewer) ViewHistory(namespace, name string, revision int64) (string, error)

ViewHistory returns a revision-to-replicaset map as the revision history of a deployment TODO: this should be a describer

type DeploymentRollbacker added in v1.2.0

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

func (*DeploymentRollbacker) Rollback added in v1.2.0

func (r *DeploymentRollbacker) Rollback(obj runtime.Object, updatedAnnotations map[string]string, toRevision int64, dryRun bool) (string, error)

type DeploymentStatusViewer added in v1.3.0

type DeploymentStatusViewer struct{}

DeploymentStatusViewer implements the StatusViewer interface.

func (*DeploymentStatusViewer) Status added in v1.3.0

func (s *DeploymentStatusViewer) Status(obj runtime.Unstructured, revision int64) (string, bool, error)

Status returns a message describing deployment status, and a bool value indicating if the status is considered done.

type HistoryViewer added in v1.2.0

type HistoryViewer interface {
	ViewHistory(namespace, name string, revision int64) (string, error)
}

HistoryViewer provides an interface for resources have historical information.

func HistoryViewerFor added in v1.2.0

func HistoryViewerFor(kind schema.GroupKind, c kubernetes.Interface) (HistoryViewer, error)

HistoryViewerFor returns an implementation of HistoryViewer interface for the given schema kind

type HistoryVisitor added in v1.9.0

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

func (*HistoryVisitor) VisitCronJob added in v1.9.0

func (v *HistoryVisitor) VisitCronJob(kind kapps.GroupKindElement)

func (*HistoryVisitor) VisitDaemonSet added in v1.9.0

func (v *HistoryVisitor) VisitDaemonSet(kind kapps.GroupKindElement)

func (*HistoryVisitor) VisitDeployment added in v1.9.0

func (v *HistoryVisitor) VisitDeployment(elem kapps.GroupKindElement)

func (*HistoryVisitor) VisitJob added in v1.9.0

func (v *HistoryVisitor) VisitJob(kind kapps.GroupKindElement)

func (*HistoryVisitor) VisitPod added in v1.9.0

func (v *HistoryVisitor) VisitPod(kind kapps.GroupKindElement)

func (*HistoryVisitor) VisitReplicaSet added in v1.9.0

func (v *HistoryVisitor) VisitReplicaSet(kind kapps.GroupKindElement)

func (*HistoryVisitor) VisitReplicationController added in v1.9.0

func (v *HistoryVisitor) VisitReplicationController(kind kapps.GroupKindElement)

func (*HistoryVisitor) VisitStatefulSet added in v1.9.0

func (v *HistoryVisitor) VisitStatefulSet(kind kapps.GroupKindElement)

type NewControllerConfig added in v1.2.5

type NewControllerConfig struct {
	Namespace        string
	OldName, NewName string
	Image            string
	Container        string
	DeploymentKey    string
	PullPolicy       corev1.PullPolicy
}

type PreconditionError added in v0.9.0

type PreconditionError struct {
	Precondition  string
	ExpectedValue string
	ActualValue   string
}

A PreconditionError is returned when a resource fails to match the scale preconditions passed to kubectl.

func (PreconditionError) Error added in v0.9.0

func (pe PreconditionError) Error() string

type RESTClient

type RESTClient interface {
	Get() *client.Request
	Post() *client.Request
	Patch(types.PatchType) *client.Request
	Delete() *client.Request
	Put() *client.Request
}

RESTClient is a client helper for dealing with RESTful resources in a generic way.

type RetryParams added in v0.15.0

type RetryParams struct {
	Interval, Timeout time.Duration
}

RetryParams encapsulates the retry parameters used by kubectl's scaler.

func NewRetryParams added in v0.18.0

func NewRetryParams(interval, timeout time.Duration) *RetryParams

type RollbackVisitor added in v1.10.0

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

func (*RollbackVisitor) VisitCronJob added in v1.10.0

func (v *RollbackVisitor) VisitCronJob(kind kapps.GroupKindElement)

func (*RollbackVisitor) VisitDaemonSet added in v1.10.0

func (v *RollbackVisitor) VisitDaemonSet(kind kapps.GroupKindElement)

func (*RollbackVisitor) VisitDeployment added in v1.10.0

func (v *RollbackVisitor) VisitDeployment(elem kapps.GroupKindElement)

func (*RollbackVisitor) VisitJob added in v1.10.0

func (v *RollbackVisitor) VisitJob(kind kapps.GroupKindElement)

func (*RollbackVisitor) VisitPod added in v1.10.0

func (v *RollbackVisitor) VisitPod(kind kapps.GroupKindElement)

func (*RollbackVisitor) VisitReplicaSet added in v1.10.0

func (v *RollbackVisitor) VisitReplicaSet(kind kapps.GroupKindElement)

func (*RollbackVisitor) VisitReplicationController added in v1.10.0

func (v *RollbackVisitor) VisitReplicationController(kind kapps.GroupKindElement)

func (*RollbackVisitor) VisitStatefulSet added in v1.10.0

func (v *RollbackVisitor) VisitStatefulSet(kind kapps.GroupKindElement)

type Rollbacker added in v1.2.0

type Rollbacker interface {
	Rollback(obj runtime.Object, updatedAnnotations map[string]string, toRevision int64, dryRun bool) (string, error)
}

Rollbacker provides an interface for resources that can be rolled back.

func RollbackerFor added in v1.2.0

func RollbackerFor(kind schema.GroupKind, c kubernetes.Interface) (Rollbacker, error)

RollbackerFor returns an implementation of Rollbacker interface for the given schema kind

type RollingUpdater added in v0.9.0

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

RollingUpdater provides methods for updating replicated pods in a predictable, fault-tolerant way.

func NewRollingUpdater added in v0.9.0

NewRollingUpdater creates a RollingUpdater from a client.

func (*RollingUpdater) Update added in v0.9.0

func (r *RollingUpdater) Update(config *RollingUpdaterConfig) error

Update all pods for a ReplicationController (oldRc) by creating a new controller (newRc) with 0 replicas, and synchronously scaling oldRc and newRc until oldRc has 0 replicas and newRc has the original # of desired replicas. Cleanup occurs based on a RollingUpdaterCleanupPolicy.

Each interval, the updater will attempt to make progress however it can without violating any availability constraints defined by the config. This means the amount scaled up or down each interval will vary based on the timeliness of readiness and the updater will always try to make progress, even slowly.

If an update from newRc to oldRc is already in progress, we attempt to drive it to completion. If an error occurs at any step of the update, the error will be returned.

A scaling event (either up or down) is considered progress; if no progress is made within the config.Timeout, an error is returned.

TODO: make this handle performing a rollback of a partially completed rollout.

type RollingUpdaterCleanupPolicy added in v0.16.0

type RollingUpdaterCleanupPolicy string

RollingUpdaterCleanupPolicy is a cleanup action to take after the deployment is complete.

const (
	// DeleteRollingUpdateCleanupPolicy means delete the old controller.
	DeleteRollingUpdateCleanupPolicy RollingUpdaterCleanupPolicy = "Delete"
	// PreserveRollingUpdateCleanupPolicy means keep the old controller.
	PreserveRollingUpdateCleanupPolicy RollingUpdaterCleanupPolicy = "Preserve"
	// RenameRollingUpdateCleanupPolicy means delete the old controller, and rename
	// the new controller to the name of the old controller.
	RenameRollingUpdateCleanupPolicy RollingUpdaterCleanupPolicy = "Rename"
)

type RollingUpdaterConfig added in v0.16.0

type RollingUpdaterConfig struct {
	// Out is a writer for progress output.
	Out io.Writer
	// OldRC is an existing controller to be replaced.
	OldRc *corev1.ReplicationController
	// NewRc is a controller that will take ownership of updated pods (will be
	// created if needed).
	NewRc *corev1.ReplicationController
	// UpdatePeriod is the time to wait between individual pod updates.
	UpdatePeriod time.Duration
	// Interval is the time to wait between polling controller status after
	// update.
	Interval time.Duration
	// Timeout is the time to wait for controller updates before giving up.
	Timeout time.Duration
	// MinReadySeconds is the number of seconds to wait after the pods are ready
	MinReadySeconds int32
	// CleanupPolicy defines the cleanup action to take after the deployment is
	// complete.
	CleanupPolicy RollingUpdaterCleanupPolicy
	// MaxUnavailable is the maximum number of pods that can be unavailable during the update.
	// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
	// Absolute number is calculated from percentage by rounding up.
	// This can not be 0 if MaxSurge is 0.
	// By default, a fixed value of 1 is used.
	// Example: when this is set to 30%, the old RC can be scaled down to 70% of desired pods
	// immediately when the rolling update starts. Once new pods are ready, old RC
	// can be scaled down further, followed by scaling up the new RC, ensuring
	// that the total number of pods available at all times during the update is at
	// least 70% of desired pods.
	MaxUnavailable intstr.IntOrString
	// MaxSurge is the maximum number of pods that can be scheduled above the desired number of pods.
	// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
	// This can not be 0 if MaxUnavailable is 0.
	// Absolute number is calculated from percentage by rounding up.
	// By default, a value of 1 is used.
	// Example: when this is set to 30%, the new RC can be scaled up immediately
	// when the rolling update starts, such that the total number of old and new pods do not exceed
	// 130% of desired pods. Once old pods have been killed, new RC can be scaled up
	// further, ensuring that total number of pods running at any time during
	// the update is at most 130% of desired pods.
	MaxSurge intstr.IntOrString
	// OnProgress is invoked if set during each scale cycle, to allow the caller to perform additional logic or
	// abort the scale. If an error is returned the cleanup method will not be invoked. The percentage value
	// is a synthetic "progress" calculation that represents the approximate percentage completion.
	OnProgress func(oldRc, newRc *corev1.ReplicationController, percentage int) error
}

RollingUpdaterConfig is the configuration for a rolling deployment process.

type ScalePrecondition added in v0.18.0

type ScalePrecondition struct {
	Size            int
	ResourceVersion string
}

ScalePrecondition describes a condition that must be true for the scale to take place If CurrentSize == -1, it is ignored. If CurrentResourceVersion is the empty string, it is ignored. Otherwise they must equal the values in the resource for it to be valid.

type Scaler added in v0.18.0

type Scaler interface {
	// Scale scales the named resource after checking preconditions. It optionally
	// retries in the event of resource version mismatch (if retry is not nil),
	// and optionally waits until the status of the resource matches newSize (if wait is not nil)
	// TODO: Make the implementation of this watch-based (#56075) once #31345 is fixed.
	Scale(namespace, name string, newSize uint, preconditions *ScalePrecondition, retry, wait *RetryParams, gr schema.GroupResource) error
	// ScaleSimple does a simple one-shot attempt at scaling - not useful on its own, but
	// a necessary building block for Scale
	ScaleSimple(namespace, name string, preconditions *ScalePrecondition, newSize uint, gr schema.GroupResource) (updatedResourceVersion string, err error)
}

Scaler provides an interface for resources that can be scaled.

func NewScaler added in v1.11.0

func NewScaler(scalesGetter scaleclient.ScalesGetter) Scaler

NewScaler get a scaler for a given resource

type StatefulSetHistoryViewer added in v1.7.0

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

func (*StatefulSetHistoryViewer) ViewHistory added in v1.7.0

func (h *StatefulSetHistoryViewer) ViewHistory(namespace, name string, revision int64) (string, error)

ViewHistory returns a list of the revision history of a statefulset TODO: this should be a describer TODO: needs to implement detailed revision view

type StatefulSetRollbacker added in v1.8.0

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

func (*StatefulSetRollbacker) Rollback added in v1.8.0

func (r *StatefulSetRollbacker) Rollback(obj runtime.Object, updatedAnnotations map[string]string, toRevision int64, dryRun bool) (string, error)

toRevision is a non-negative integer, with 0 being reserved to indicate rolling back to previous configuration

type StatefulSetStatusViewer added in v1.7.0

type StatefulSetStatusViewer struct{}

StatefulSetStatusViewer implements the StatusViewer interface.

func (*StatefulSetStatusViewer) Status added in v1.7.0

func (s *StatefulSetStatusViewer) Status(obj runtime.Unstructured, revision int64) (string, bool, error)

Status returns a message describing statefulset status, and a bool value indicating if the status is considered done.

type StatusViewer added in v1.3.0

type StatusViewer interface {
	Status(obj runtime.Unstructured, revision int64) (string, bool, error)
}

StatusViewer provides an interface for resources that have rollout status.

func StatusViewerFor added in v1.3.0

func StatusViewerFor(kind schema.GroupKind) (StatusViewer, error)

StatusViewerFor returns a StatusViewer for the resource specified by kind.

Directories

Path Synopsis
cmd
cp
get
run
set
set/env
Package env provides functions to incorporate environment variables into set env.
Package env provides functions to incorporate environment variables into set env.
taint
Package taints implements utilites for working with taints
Package taints implements utilites for working with taints
top
util/openapi
Package openapi is a collection of libraries for fetching the openapi spec from a Kubernetes server and then indexing the type definitions.
Package openapi is a collection of libraries for fetching the openapi spec from a Kubernetes server and then indexing the type definitions.
qos

Jump to

Keyboard shortcuts

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