drain

package
v0.31.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 24 Imported by: 87

Documentation

Index

Constants

View Source
const (
	// EvictionKind represents the kind of evictions object
	EvictionKind = "Eviction"
	// EvictionSubresource represents the kind of evictions object as pod's subresource
	EvictionSubresource = "pods/eviction"
)
View Source
const (
	// PodDeleteStatusTypeOkay is "Okay"
	PodDeleteStatusTypeOkay = "Okay"
	// PodDeleteStatusTypeSkip is "Skip"
	PodDeleteStatusTypeSkip = "Skip"
	// PodDeleteStatusTypeWarning is "Warning"
	PodDeleteStatusTypeWarning = "Warning"
	// PodDeleteStatusTypeError is "Error"
	PodDeleteStatusTypeError = "Error"
)

Variables

This section is empty.

Functions

func CheckEvictionSupport

func CheckEvictionSupport(clientset kubernetes.Interface) (schema.GroupVersion, error)

CheckEvictionSupport uses Discovery API to find out if the server support eviction subresource If support, it will return its groupVersion; Otherwise, it will return an empty GroupVersion

func RunCordonOrUncordon

func RunCordonOrUncordon(drainer *Helper, node *corev1.Node, desired bool) error

RunCordonOrUncordon demonstrates the canonical way to cordon or uncordon a Node

func RunNodeDrain

func RunNodeDrain(drainer *Helper, nodeName string) error

RunNodeDrain shows the canonical way to drain a node. You should first cordon the node, e.g. using RunCordonOrUncordon

Types

type CordonHelper

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

CordonHelper wraps functionality to cordon/uncordon nodes

func NewCordonHelper

func NewCordonHelper(node *corev1.Node) *CordonHelper

NewCordonHelper returns a new CordonHelper

func NewCordonHelperFromRuntimeObject

func NewCordonHelperFromRuntimeObject(nodeObject runtime.Object, scheme *runtime.Scheme, gvk schema.GroupVersionKind) (*CordonHelper, error)

NewCordonHelperFromRuntimeObject returns a new CordonHelper, or an error if given object is not a node or cannot be encoded as JSON

func (*CordonHelper) PatchOrReplace

func (c *CordonHelper) PatchOrReplace(clientset kubernetes.Interface, serverDryRun bool) (error, error)

PatchOrReplace uses given clientset to update the node status, either by patching or updating the given node object; it may return error if the object cannot be encoded as JSON, or if either patch or update calls fail; it will also return a second error whenever creating a patch has failed

func (*CordonHelper) PatchOrReplaceWithContext added in v0.21.0

func (c *CordonHelper) PatchOrReplaceWithContext(clientCtx context.Context, clientset kubernetes.Interface, serverDryRun bool) (error, error)

PatchOrReplaceWithContext provides the option to pass a custom context while updating the node status

func (*CordonHelper) UpdateIfRequired

func (c *CordonHelper) UpdateIfRequired(desired bool) bool

UpdateIfRequired returns true if c.node.Spec.Unschedulable isn't already set, or false when no change is needed

type Helper

type Helper struct {
	Ctx    context.Context
	Client kubernetes.Interface
	Force  bool

	// GracePeriodSeconds is how long to wait for a pod to terminate.
	// IMPORTANT: 0 means "delete immediately"; set to a negative value
	// to use the pod's terminationGracePeriodSeconds.
	GracePeriodSeconds int

	IgnoreAllDaemonSets bool
	Timeout             time.Duration
	DeleteEmptyDirData  bool
	Selector            string
	PodSelector         string
	ChunkSize           int64

	// DisableEviction forces drain to use delete rather than evict
	DisableEviction bool

	// SkipWaitForDeleteTimeoutSeconds ignores pods that have a
	// DeletionTimeStamp > N seconds. It's up to the user to decide when this
	// option is appropriate; examples include the Node is unready and the pods
	// won't drain otherwise
	SkipWaitForDeleteTimeoutSeconds int

	// AdditionalFilters are applied sequentially after base drain filters to
	// exclude pods using custom logic.  Any filter that returns PodDeleteStatus
	// with Delete == false will immediately stop execution of further filters.
	AdditionalFilters []PodFilter

	Out    io.Writer
	ErrOut io.Writer

	DryRunStrategy cmdutil.DryRunStrategy

	// OnPodDeletedOrEvicted is called when a pod is evicted/deleted; for printing progress output
	// Deprecated: use OnPodDeletionOrEvictionFinished instead
	OnPodDeletedOrEvicted func(pod *corev1.Pod, usingEviction bool)

	// OnPodDeletionOrEvictionFinished is called when a pod is eviction/deletetion is failed; for printing progress output
	OnPodDeletionOrEvictionFinished func(pod *corev1.Pod, usingEviction bool, err error)

	// OnPodDeletionOrEvictionStarted is called when a pod eviction/deletion is started; for printing progress output
	OnPodDeletionOrEvictionStarted func(pod *corev1.Pod, usingEviction bool)
}

Helper contains the parameters to control the behaviour of drainer

func (*Helper) DeleteOrEvictPods

func (d *Helper) DeleteOrEvictPods(pods []corev1.Pod) error

DeleteOrEvictPods deletes or evicts the pods on the api server

func (*Helper) DeletePod

func (d *Helper) DeletePod(pod corev1.Pod) error

DeletePod will delete the given pod, or return an error if it couldn't

func (*Helper) EvictPod

func (d *Helper) EvictPod(pod corev1.Pod, evictionGroupVersion schema.GroupVersion) error

EvictPod will evict the given pod, or return an error if it couldn't

func (*Helper) GetPodsForDeletion

func (d *Helper) GetPodsForDeletion(nodeName string) (*PodDeleteList, []error)

GetPodsForDeletion receives resource info for a node, and returns those pods as PodDeleteList, or error if it cannot list pods. All pods that are ready to be deleted can be obtained with .Pods(), and string with all warning can be obtained with .Warnings(), and .Errors() for all errors that occurred during deletion.

type PodDelete added in v0.20.0

type PodDelete struct {
	Pod    corev1.Pod
	Status PodDeleteStatus
}

PodDelete informs filtering logic whether a pod should be deleted or not

type PodDeleteList added in v0.20.0

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

PodDeleteList is a wrapper around []PodDelete

func (*PodDeleteList) Pods added in v0.20.0

func (l *PodDeleteList) Pods() []corev1.Pod

Pods returns a list of all pods marked for deletion after filtering.

func (*PodDeleteList) Warnings added in v0.20.0

func (l *PodDeleteList) Warnings() string

Warnings returns all warning messages concatenated into a string.

type PodDeleteStatus added in v0.20.0

type PodDeleteStatus struct {
	Delete  bool
	Reason  string
	Message string
}

PodDeleteStatus informs filters if a pod should be deleted

func MakePodDeleteStatusOkay added in v0.20.0

func MakePodDeleteStatusOkay() PodDeleteStatus

MakePodDeleteStatusOkay is a helper method to return the corresponding PodDeleteStatus

func MakePodDeleteStatusSkip added in v0.20.0

func MakePodDeleteStatusSkip() PodDeleteStatus

MakePodDeleteStatusSkip is a helper method to return the corresponding PodDeleteStatus

func MakePodDeleteStatusWithError added in v0.20.0

func MakePodDeleteStatusWithError(message string) PodDeleteStatus

MakePodDeleteStatusWithError is a helper method to return the corresponding PodDeleteStatus

func MakePodDeleteStatusWithWarning added in v0.20.0

func MakePodDeleteStatusWithWarning(delete bool, message string) PodDeleteStatus

MakePodDeleteStatusWithWarning is a helper method to return the corresponding PodDeleteStatus

type PodFilter added in v0.20.0

type PodFilter func(corev1.Pod) PodDeleteStatus

PodFilter takes a pod and returns a PodDeleteStatus

Jump to

Keyboard shortcuts

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