k8s

package
v0.0.0-...-c9a9482 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package k8s provides a client for interacting with Kubernetes. It provides methods for listing, cordoning, draining, and deleting nodes, as well as setting and getting node annotations and labels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a Kubernetes client wrapper.

func NewClient

func NewClient(config *rest.Config) (*Client, error)

NewClient creates a new Kubernetes client using the provided rest.Config and returns a Client. If no config is provided, it will try to use in-cluster config, and if that fails, it will fallback to a kubeconfig file. At the moment, it does not apply client-side rate limiting.

func (*Client) CordonNode

func (c *Client) CordonNode(ctx context.Context, nodeName string) error

CordonNode cordon the node with the provided name. Since no out of the box method is provided by the client-go library, we need to patch the node object to set the spec.unschedulable field to true.

func (*Client) DeleteNode

func (c *Client) DeleteNode(ctx context.Context, nodeName string) error

DeleteNode deletes the node with the provided name.

func (*Client) DeletePod

func (c *Client) DeletePod(ctx context.Context, podName, namespace string) error

DeletePod deletes the pod with the provided name and namespace.

func (*Client) DrainNode

func (c *Client) DrainNode(ctx context.Context, nodeName string) error

DrainNode drains the node with the provided name. It evicts all the pods running on the node, except for the ones in the kube-system namespace. It uses the Eviction API to evict the pods.

func (*Client) GetNodeAnnotation

func (c *Client) GetNodeAnnotation(ctx context.Context, nodeName, key string) (string, error)

GetNodeAnnotation returns the value of the annotation with the provided key on the node with the provided name.

func (*Client) GetNodeLabel

func (c *Client) GetNodeLabel(ctx context.Context, nodeName, key string) (string, error)

GetNodeLabel returns the value of the label with the provided key on the node with the provided name.

func (*Client) GetNodeZone

func (c *Client) GetNodeZone(ctx context.Context, nodeName string) (string, error)

GetNodeZone returns the zone of the node with the provided name. It first tries to get the zone from the "topology.kubernetes.io/zone" label, and if that fails, it tries to get it from the "failure-domain.beta.kubernetes.io/zone" label.

func (*Client) GetNodes

func (c *Client) GetNodes(ctx context.Context) ([]string, error)

GetNodes returns a list of node names in the Kubernetes cluster where the client points to.

func (*Client) HasNodeAnnotation

func (c *Client) HasNodeAnnotation(ctx context.Context, nodeName, key string) (bool, error)

HasNodeAnnotation checks if the node with the provided name has the annotation with the provided key.

func (*Client) HasNodeLabel

func (c *Client) HasNodeLabel(ctx context.Context, nodeName, key string) (bool, error)

HasNodeLabel checks if the node with the provided name has the label with the provided key.

func (*Client) SetNodeAnnotation

func (c *Client) SetNodeAnnotation(ctx context.Context, nodeName, key, value string) error

SetNodeAnnotation sets the provided key-value pair as an annotation on the node with the provided name. It uses the Patch API to update the node's annotations.

Jump to

Keyboard shortcuts

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