k8sutil

package
v0.0.0-...-f8812e7 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LabelKeyKurlshManaged is the metadata label key for kurl.sh managed resources
	LabelKeyKurlshManaged = "kurl.sh/managed"
	// LabelKeyKurlshVersion is the metadata label key for kurl.sh version
	LabelKeyKurlshVersion = "kurl.sh/version"
)

Variables

This section is empty.

Functions

func AppendKurlLabels

func AppendKurlLabels(labels map[string]string) map[string]string

AppendKurlLabels appends kurl.sh managed labels to the given map

func ExecContainer

func ExecContainer(ctx context.Context, opts ExecOptions, terminalSizeQueue remotecommand.TerminalSizeQueue) (int, error)

ExecContainer executes a remote execution against a pod. Returns exit code and error. The error will be non-nil if exit code is not 0.

func IsDeploymentReady

func IsDeploymentReady(dep appsv1.Deployment, desiredReplication int32) bool

IsDeploymentReady returns true if the provided deployment is ready and up-to-date.

func IsPodReady

func IsPodReady(pod corev1.Pod) bool

IsPodReady returns true if provided pod is ready.

func KubectlApply

func KubectlApply(ctx context.Context, cli client.Client, resources embed.FS, overlay string, opts ...plumber.Option) error

func KubectlDelete

func KubectlDelete(ctx context.Context, b []byte, args ...string) ([]byte, error)

func ListPodsBySelector

func ListPodsBySelector(ctx context.Context, clientset kubernetes.Interface, namespace string, selector string) (*corev1.PodList, error)

ListPodsBySelector returns a list of pods matching the provided selector.

func NodeInternalIP

func NodeInternalIP(node corev1.Node) (string, error)

NodeInternalIP returns the node internal ip address for the provided node.

func NodeInternalIPByNodeName

func NodeInternalIPByNodeName(nodes []corev1.Node, nodeName string) (string, error)

NodeInternalIPByNodeName returns the node internal ip address for the provided node name.

func PVCSForPVs

PVCSForPVs returns a pv to pvc mapping. the returned map is indexed by the pv name.

func PVSByStorageClass

func PVSByStorageClass(ctx context.Context, cli kubernetes.Interface, scname string) (map[string]corev1.PersistentVolume, error)

PVSByStorageClass returns a map of persistent volumes using the provided storage class name. returned pvs map is indexed by pv's name.

func PVSReservationPerNode

func PVSReservationPerNode(ctx context.Context, cli kubernetes.Interface, scname string) (map[string]int64, int64, error)

PVSReservationPerNode return the sum of space of all pvs being served per node. this function also returns sum of space in pvs that exist bur are not in attached to any pod.

func PodHasPVC

func PodHasPVC(pod corev1.Pod, pvcNamespace, pvcName string) bool

PodHasPVC returs true if provided pod has provided pvc among its volumes.

func RunJob

func RunJob(ctx context.Context, cli kubernetes.Interface, logger *log.Logger, job *batchv1.Job, timeout time.Duration) (map[string][]byte, map[string]corev1.ContainerState, error)

RunJob runs the provided job and waits until it finishes or the timeout is reached. returns the job's pod logs (indexed by container name) and the state of each of the containers (also indexed by container name).

func SyncExec

func SyncExec(coreClient corev1client.CoreV1Interface, clientConfig *restclient.Config, ns, pod, container string, command ...string) (int, string, string, error)

SyncExec returns exitcode, stdout, stderr. A non-zero exit code from the command is not considered an error.

func TolerationsForAllNodes

func TolerationsForAllNodes(ctx context.Context, cli kubernetes.Interface) ([]corev1.Toleration, error)

func TolerationsForNode

func TolerationsForNode(node corev1.Node) []corev1.Toleration

TolerationsForNode returns a list of tolerations that matches the provided node.

func WaitForDaemonsetRollout

func WaitForDaemonsetRollout(ctx context.Context, cli kubernetes.Interface, ds *appsv1.DaemonSet, timeout time.Duration) error

WaitForDaemonsetRollout waits for a daemonset to rollout.

func WaitForDeploymentReady

func WaitForDeploymentReady(ctx context.Context, clientset kubernetes.Interface, namespace, name string, desiredReplication int32) error

WaitForDeploymentReady polls every 5 seconds until either the provided deployment is ready and up-to-date or the context is closed.

func WaitForJob

func WaitForJob(ctx context.Context, cli kubernetes.Interface, job *batchv1.Job, timeout time.Duration) (bool, error)

WaitForJob waits for a job to finish. returns a boolean indicating if the job succeeded.

func WaitForPodReady

func WaitForPodReady(ctx context.Context, clientset kubernetes.Interface, namespace, name string) error

WaitForPodReady polls every 5 seconds until either the provided pof is ready or the context is closed.

Types

type ExecOptions

type ExecOptions struct {
	StreamOptions

	Command []string

	CoreClient corev1client.CoreV1Interface
	Config     *restclient.Config
}

type StreamOptions

type StreamOptions struct {
	Namespace     string
	PodName       string
	ContainerName string
	TTY           bool
	In            io.Reader
	Out           io.Writer
	Err           io.Writer
}

Jump to

Keyboard shortcuts

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