k8s

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxRetriesK8SOperation = 5
)

Variables

View Source
var (
	ErrAction             = errors.New("not valid action")
	ErrNodeNotFound       = errors.New("node not found")
	ErrNodeDoesNotMatch   = fmt.Errorf("node does not match")
	ErrProviderIDMismatch = errors.New("provider ID mismatch")
	ErrNodeWatcherClosed  = fmt.Errorf("node watcher closed, no more events will be received")
)

Functions

func CordonNode

func CordonNode(ctx context.Context, log logrus.FieldLogger, clientset kubernetes.Interface, node *v1.Node) error

func DefaultBackoff

func DefaultBackoff() wait.Backoff

func DeletePod

func DeletePod(ctx context.Context, options metav1.DeleteOptions, pod v1.Pod, podDeleteRetries int, podDeleteRetryDelay time.Duration, clientset kubernetes.Interface, log logrus.FieldLogger) error

DeletePod deletes a pod from the cluster.

func EvictPod

func EvictPod(ctx context.Context, pod v1.Pod, podEvictRetryDelay time.Duration, clientset kubernetes.Interface, log logrus.FieldLogger, version schema.GroupVersion) error

EvictPod evicts a pod from a k8s node.

func GetDrainTimeout

func GetDrainTimeout(action *castai.ClusterAction) time.Duration

GetDrainTimeout returns drain timeout adjusted to action creation time. the result is clamped between 0s and the requested timeout.

func GetNodeByIDs

func GetNodeByIDs(ctx context.Context, clientSet corev1client.NodeInterface, nodeName, nodeID, providerID string, log logrus.FieldLogger) (*v1.Node, error)

GetNodeByIDs retrieves a node by name and validates its ID and provider ID.

func IsControlledBy

func IsControlledBy(p *v1.Pod, kind string) bool

func IsDaemonSetPod

func IsDaemonSetPod(p *v1.Pod) bool

func IsNodeIDProviderIDValid

func IsNodeIDProviderIDValid(node *v1.Node, nodeID, providerID string) error

IsNodeIDProviderIDValid checks if the node's ID and provider ID match the requested ones.

func IsNonEvictible

func IsNonEvictible(p *v1.Pod) bool

func IsStaticPod

func IsStaticPod(p *v1.Pod) bool

func PatchNode

func PatchNode(ctx context.Context, log logrus.FieldLogger, clientset kubernetes.Interface, node *v1.Node, changeFn func(*v1.Node)) error

PatchNode patches a node with the given change function.

func PatchNodeStatus

func PatchNodeStatus(ctx context.Context, log logrus.FieldLogger, clientset kubernetes.Interface, name string, patch []byte) error

PatchNodeStatus patches the status of a node.

Types

type Client

type Client interface {
	PatchNode(ctx context.Context, node *v1.Node, changeFn func(*v1.Node)) error
	PatchNodeStatus(ctx context.Context, name string, patch []byte) error
	EvictPod(ctx context.Context, pod v1.Pod, podEvictRetryDelay time.Duration, version schema.GroupVersion) error
	CordonNode(ctx context.Context, node *v1.Node) error
	GetNodeByIDs(ctx context.Context, nodeName, nodeID, providerID string) (*v1.Node, error)
	ExecuteBatchPodActions(
		ctx context.Context,
		pods []*v1.Pod,
		action func(context.Context, v1.Pod) error,
		actionName string,
	) ([]*v1.Pod, []PodActionFailure)
	DeletePod(ctx context.Context, options metav1.DeleteOptions, pod v1.Pod, podDeleteRetries int, podDeleteRetryDelay time.Duration) error
	Clientset() kubernetes.Interface
	Log() logrus.FieldLogger
}

func NewClient

func NewClient(clientset kubernetes.Interface, log logrus.FieldLogger) Client

NewClient creates a new K8s client with the given dependencies.

type PartitionResult

type PartitionResult struct {
	Evictable    []*v1.Pod
	NonEvictable []*v1.Pod
	CastPods     []*v1.Pod
}

func PartitionPodsForEviction

func PartitionPodsForEviction(pods []*v1.Pod, castNamespace string, skipDeletedTimeoutSeconds int) *PartitionResult

type PodActionFailure

type PodActionFailure struct {
	ActionName string
	Pod        *v1.Pod
	Err        error
}

func ExecuteBatchPodActions

func ExecuteBatchPodActions(
	ctx context.Context,
	log logrus.FieldLogger,
	pods []*v1.Pod,
	action func(context.Context, v1.Pod) error,
	actionName string,
) ([]*v1.Pod, []PodActionFailure)

ExecuteBatchPodActions executes the action for each pod in the list.

type PodFailedActionError

type PodFailedActionError struct {
	// Action holds context what was the code trying to do.
	Action string
	// Errors should hold an entry per pod, for which the action failed.
	Errors []error
}

func (*PodFailedActionError) Error

func (p *PodFailedActionError) Error() string

func (*PodFailedActionError) Unwrap

func (p *PodFailedActionError) Unwrap() []error

Directories

Path Synopsis
Package mock_k8s is a generated GoMock package.
Package mock_k8s is a generated GoMock package.

Jump to

Keyboard shortcuts

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