pod

package
v0.8.1 Latest Latest
Warning

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

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

Documentation

Overview

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

This package consolidates common functionality used by both the snapshot agent (pkg/k8s/agent) and validation agent (pkg/validator/agent):

  • Job lifecycle: WaitForJobCompletion
  • Pod logs: StreamLogs, GetPodLogs
  • Pod readiness: WaitForPodReady
  • 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)

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

// Get pod logs as string
logs, err := pod.GetPodLogs(ctx, client, namespace, podName)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPodLogs

func GetPodLogs(ctx context.Context, client kubernetes.Interface, namespace, podName 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.

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 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.

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.

This function uses the Kubernetes watch API for efficient monitoring instead of polling.

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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