k8sutil

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package k8sutil provides various wrappers over Kubernetes tooling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterContainerLinuxNodes

func FilterContainerLinuxNodes(nodes []corev1.Node) []corev1.Node

FilterContainerLinuxNodes filters a list of nodes and returns nodes with a Flatcar Container Linux OSImage, as reported by the node's /etc/os-release.

func FilterNodesByAnnotation

func FilterNodesByAnnotation(list []corev1.Node, sel fields.Selector) []corev1.Node

FilterNodesByAnnotation takes a node list and a field selector, and returns a node list that matches the field selector.

func FilterNodesByRequirement

func FilterNodesByRequirement(nodes []corev1.Node, req *labels.Requirement) []corev1.Node

FilterNodesByRequirement filters a list of nodes and returns nodes matching the given label requirement.

func FilterPods

func FilterPods(pods []corev1.Pod, filter func(*corev1.Pod) bool) []corev1.Pod

FilterPods filters given list of pods using given function.

func GetClient

func GetClient(path string) (*kubernetes.Clientset, error)

GetClient returns a Kubernetes client (clientset) from the kubeconfig path or from the in-cluster service account environment.

func GetNodeRetry

func GetNodeRetry(ctx context.Context, nc NodeGetter, node string) (*corev1.Node, error)

GetNodeRetry gets a node object, retrying up to DefaultBackoff number of times if it fails.

func NewRequirementOrDie

func NewRequirementOrDie(key string, op selection.Operator, vals []string) *labels.Requirement

NewRequirementOrDie wraps a call to NewRequirement and panics if the Requirement cannot be created. It is intended for use in variable initializations only.

func SetNodeAnnotations

func SetNodeAnnotations(ctx context.Context, nc NodeUpdater, node string, m map[string]string) error

SetNodeAnnotations sets all keys in m to their respective values in node's annotations.

func SetNodeAnnotationsLabels

func SetNodeAnnotationsLabels(
	ctx context.Context, nc NodeUpdater, nodeName string, annotations, labels map[string]string,
) error

SetNodeAnnotationsLabels sets all keys in a and l to their values in node's annotations and labels, respectively.

func SetNodeLabels

func SetNodeLabels(ctx context.Context, nc NodeUpdater, node string, m map[string]string) error

SetNodeLabels sets all keys in m to their respective values in node's labels.

func Unschedulable

func Unschedulable(ctx context.Context, nc NodeUpdater, node string, sched bool) error

Unschedulable marks node as schedulable or unschedulable according to sched.

func UpdateNodeRetry

func UpdateNodeRetry(ctx context.Context, nodeUpdater NodeUpdater, nodeName string, updateF UpdateNode) error

UpdateNodeRetry calls f to update a node object in Kubernetes. It will attempt to update the node by applying f to it up to DefaultBackoff number of times. Given update function will be called each time since the node object will likely have changed if a retry is necessary.

Types

type NodeGetter added in v0.9.0

type NodeGetter interface {
	Get(ctx context.Context, name string, opts metav1.GetOptions) (*corev1.Node, error)
}

NodeGetter is a subset of corev1client.NodeInterface used by this package for getting node objects.

type NodeUpdater added in v0.9.0

type NodeUpdater interface {
	NodeGetter

	Update(ctx context.Context, node *corev1.Node, opts metav1.UpdateOptions) (*corev1.Node, error)
}

NodeUpdater is a subset of corev1client.NodeInterface used by this package for updating nodes.

type UpdateNode added in v0.9.0

type UpdateNode func(*corev1.Node)

UpdateNode is a function updating properties of received node object.

Jump to

Keyboard shortcuts

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