pod

package
v0.11.1 Latest Latest
Warning

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

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

Documentation

Overview

Package pod provides shared utilities for Kubernetes Job and Pod operations.

This package consolidates common functionality used by the snapshot agent (pkg/k8s/agent) and validator Job orchestrator (pkg/validator/job):

  • Job lifecycle: WaitForJobCompletion
  • Pod phase: WaitForPodSucceeded, WaitForPodReady
  • Pod logs: StreamLogs, GetPodLogs
  • ConfigMap URIs: ParseConfigMapURI

All functions use structured error handling (pkg/errors) and respect context deadlines for proper timeout management.

Example usage:

// Wait for job completion
err := pod.WaitForJobCompletion(ctx, client, namespace, jobName, timeout)

// Wait for pod to succeed
err := pod.WaitForPodSucceeded(ctx, client, namespace, podName, timeout)

// Stream pod logs to writer (empty container = first container)
err := pod.StreamLogs(ctx, client, namespace, podName, "", os.Stdout)

// Get pod logs as string with specific container
logs, err := pod.GetPodLogs(ctx, client, namespace, podName, "my-container")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPodLogs

func GetPodLogs(ctx context.Context, client kubernetes.Interface, namespace, podName, containerName string) (string, error)

GetPodLogs retrieves all logs from a pod as a string. This function is suitable for completed pods or when you need the full log history. When containerName is empty, Kubernetes defaults to the first container.

func ParseConfigMapURI

func ParseConfigMapURI(uri string) (namespace, name string, err error)

ParseConfigMapURI parses a ConfigMap URI in the format "cm://namespace/name" and returns the namespace and name components.

Returns error if URI format is invalid.

func StreamLogs

func StreamLogs(ctx context.Context, client kubernetes.Interface, namespace, podName, containerName string, logWriter io.Writer) error

StreamLogs streams pod logs to the provided writer in real-time. Logs are written line-by-line as they are received from the pod. When containerName is empty, Kubernetes defaults to the first container.

func WaitForJobCompletion

func WaitForJobCompletion(ctx context.Context, client kubernetes.Interface, namespace, name string, timeout time.Duration) error

WaitForJobCompletion waits for a Kubernetes Job to complete successfully or fail. Returns nil if job completes successfully, error if job fails or context deadline exceeded.

Performs an initial Get to catch already-complete Jobs, then uses the watch API for efficient monitoring.

func WaitForPodReady

func WaitForPodReady(ctx context.Context, client kubernetes.Interface, namespace, name string, timeout time.Duration) error

WaitForPodReady waits for a pod to become ready within the specified timeout. Returns nil if pod becomes ready, error if timeout or pod fails.

func WaitForPodSucceeded added in v0.8.2

func WaitForPodSucceeded(ctx context.Context, client kubernetes.Interface, namespace, name string, timeout time.Duration) error

WaitForPodSucceeded waits for a pod to reach the Succeeded phase. Returns nil on PodSucceeded, error on PodFailed, error on timeout. Performs an initial Get to catch already-terminal pods, then uses the watch API for efficient monitoring.

Types

This section is empty.

Jump to

Keyboard shortcuts

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