drain

package
v1.9.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package drain provides a helper to cordon and drain Nodes.

Index

Constants

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 PodListToString

func PodListToString(podList []*corev1.Pod, n int) string

PodListToString returns a comma-separated list of the first n entries of the Pod list.

Types

type EvictionResult

type EvictionResult struct {
	PodsDeletionTimestampSet   []*corev1.Pod
	PodsFailedEviction         map[string][]*corev1.Pod
	PodsToTriggerEvictionLater []*corev1.Pod
	PodsNotFound               []*corev1.Pod
	PodsIgnored                []*corev1.Pod
}

EvictionResult contains the results of an eviction.

func (EvictionResult) ConditionMessage

func (r EvictionResult) ConditionMessage(nodeDrainStartTime *metav1.Time) string

ConditionMessage returns a condition message for the case where a drain is not completed.

func (EvictionResult) DrainCompleted

func (r EvictionResult) DrainCompleted() bool

DrainCompleted returns if a Node is entirely drained, i.e. if all relevant Pods have gone away.

type Helper

type Helper struct {
	// Client is the client for the management cluster.
	Client client.Client

	// RemoteClient is the client for the workload cluster.
	RemoteClient client.Client

	// 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 is used when executing Eviction calls.
	GracePeriodSeconds int

	// SkipWaitForDeleteTimeoutSeconds ignores Pods that have a
	// DeletionTimeStamp > N seconds. This can be used e.g. when a Node is unreachable
	// and the Pods won't drain because of that.
	SkipWaitForDeleteTimeoutSeconds int
}

Helper contains the parameters to control the behaviour of the drain helper.

func (*Helper) CordonNode

func (d *Helper) CordonNode(ctx context.Context, node *corev1.Node) error

CordonNode cordons a Node.

func (*Helper) EvictPods

func (d *Helper) EvictPods(ctx context.Context, podDeleteList *PodDeleteList) EvictionResult

EvictPods evicts the pods.

func (*Helper) GetPodsForEviction

func (d *Helper) GetPodsForEviction(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, nodeName string) (*PodDeleteList, error)

GetPodsForEviction gets Pods running on a Node and then filters and returns them as PodDeleteList, or error if it cannot list Pods or get DaemonSets. All Pods that have to go away can be obtained with .Pods().

type PodDelete

type PodDelete struct {
	Pod    *corev1.Pod
	Status PodDeleteStatus
}

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

type PodDeleteList

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

PodDeleteList is a wrapper around []PodDelete.

func (*PodDeleteList) Pods

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

Pods returns a list of Pods that have to go away before the Node can be considered completely drained.

func (*PodDeleteList) SkippedPods

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

SkippedPods returns a list of Pods that have to be ignored when considering if the Node has been completely drained. Note: As of today the following Pods are skipped: * DaemonSet Pods * static Pods * Pods in deletion (if `SkipWaitForDeleteTimeoutSeconds` is set) * Pods that have the label "cluster.x-k8s.io/drain": "skip" * Pods for which the first MachineDrainRule that matches specifies spec.drain.behavior = "Skip".

type PodDeleteStatus

type PodDeleteStatus struct {
	// DrainBehavior defines the drain behavior of a Pod, it is either "Skip" or "Drain".
	DrainBehavior clusterv1.MachineDrainRuleDrainBehavior

	// DrainOrder defines the order in which Pods are drained.
	// DrainOrder is only used if DrainBehavior is "Drain".
	DrainOrder *int32

	Reason  string
	Message string
}

PodDeleteStatus informs filters if a pod should be deleted.

func MakePodDeleteStatusOkay

func MakePodDeleteStatusOkay() PodDeleteStatus

MakePodDeleteStatusOkay is a helper method to return the corresponding PodDeleteStatus.

func MakePodDeleteStatusOkayWithOrder

func MakePodDeleteStatusOkayWithOrder(order *int32) PodDeleteStatus

MakePodDeleteStatusOkayWithOrder is a helper method to return the corresponding PodDeleteStatus.

func MakePodDeleteStatusSkip

func MakePodDeleteStatusSkip() PodDeleteStatus

MakePodDeleteStatusSkip is a helper method to return the corresponding PodDeleteStatus.

func MakePodDeleteStatusWithError

func MakePodDeleteStatusWithError(message string) PodDeleteStatus

MakePodDeleteStatusWithError is a helper method to return the corresponding PodDeleteStatus.

func MakePodDeleteStatusWithWarning

func MakePodDeleteStatusWithWarning(behavior clusterv1.MachineDrainRuleDrainBehavior, message string) PodDeleteStatus

MakePodDeleteStatusWithWarning is a helper method to return the corresponding PodDeleteStatus.

type PodFilter

type PodFilter func(context.Context, *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