wait

package
v0.0.0-...-b4a5b58 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: BSD-2-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const PollInterval = 5 * time.Second

PollInterval is the delay between polling cycles.

Variables

View Source
var SetClient = F.Curry2(func(c kubernetes.Interface, p Params) WithClient {
	return WithClient{Params: p, Client: c}
})

SetClient is a curried setter used with IOE.Bind to inject the K8s client.

View Source
var SetPollReady = F.Curry2(func(deadline time.Time, c WithClient) PollContext {
	return PollContext{
		WithClient: c,
		Deadline:   deadline,
		State:      JobPending,
		Condition:  O.None[JobState](),
	}
})

SetPollReady is a curried setter used with IOE.Let to attach the deadline. The Logger is preserved from Params.

Functions

func CreateK8sClient

func CreateK8sClient(p Params) IOE.IOEither[error, kubernetes.Interface]

CreateK8sClient builds a Kubernetes client from the kubeconfig path in Params. Falls back to in-cluster config when Kubeconfig is empty.

func FetchJob

func FetchJob(ctx PollContext) IOE.IOEither[error, PollContext]

FetchJob retrieves the named Job from Kubernetes and stores it in ctx.Job.

func FetchPods

func FetchPods(ctx PollContext) IOE.IOEither[error, *corev1.PodList]

FetchPods lists pods belonging to the named Job.

func FindStuckReason

func FindStuckReason(pods *corev1.PodList) O.Option[string]

FindStuckReason scans all pods and all containers for a known stuck reason. Returns Some(reason) on first match, None if all containers are healthy.

func JobAction

func JobAction(c *cli.Context) error

JobAction is the urfave/cli v2 action for the wait-job subcommand.

Pipeline (8 steps):

  1. Build Params from CLI flags
  2. Inject Kubernetes client (Bind)
  3. Compute deadline and attach logger (Let)
  4. Run polling loop (returns PollContext with final State)
  5. Extract JobState from PollContext
  6. Execute IOEither effect → Either
  7. Validate terminal state (Complete → ok, else → error)
  8. Fold Either → error

Types

type JobState

type JobState string

JobState represents the observed state of a Kubernetes Job.

const (
	JobPending  JobState = "Pending"
	JobComplete JobState = "Complete"
	JobFailed   JobState = "Failed"
	JobStuck    JobState = "Stuck"
)

func ClassifyPodState

func ClassifyPodState(pods *corev1.PodList) JobState

ClassifyPodState returns JobStuck if any container is stuck, otherwise JobPending.

type Params

type Params struct {
	Name       string
	Namespace  string
	Timeout    time.Duration
	Kubeconfig string
	Logger     *slog.Logger
}

Params holds CLI-supplied parameters for the wait-job command.

type PollContext

type PollContext struct {
	WithClient
	Deadline  time.Time
	Job       *batchv1.Job
	Condition O.Option[JobState]
	State     JobState
}

PollContext is the fully-enriched context used throughout the polling loop.

func ExtractJobCondition

func ExtractJobCondition(ctx PollContext) PollContext

ExtractJobCondition reads ctx.Job, extracts the first terminal condition, and stores it in ctx.Condition.

type WithClient

type WithClient struct {
	Params
	Client kubernetes.Interface
}

WithClient enriches Params with an injected Kubernetes client.

Jump to

Keyboard shortcuts

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