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 ¶
- func GetPodLogs(ctx context.Context, client kubernetes.Interface, namespace, podName string) (string, error)
- func ParseConfigMapURI(uri string) (namespace, name string, err error)
- func StreamLogs(ctx context.Context, client kubernetes.Interface, namespace, podName string, ...) error
- func WaitForJobCompletion(ctx context.Context, client kubernetes.Interface, namespace, name string, ...) error
- func WaitForPodReady(ctx context.Context, client kubernetes.Interface, namespace, name string, ...) error
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 ¶
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.