readiness

package
v5.41.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package readiness provides Kubernetes resource readiness polling utilities.

This package offers reusable utilities for waiting until Kubernetes resources become ready. It supports deployments, daemonsets, nodes, and the API server, and provides a generic polling mechanism that can be extended.

Key features:

  • Generic polling mechanism (PollForReadiness)
  • Deployment readiness polling (WaitForDeploymentReady)
  • DaemonSet readiness polling (WaitForDaemonSetReady)
  • Node readiness polling (WaitForNodeReady)
  • API server readiness and stability polling (WaitForAPIServerReady, WaitForAPIServerStable)
  • Multi-resource coordination (WaitForMultipleResources)

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeoutExceeded = errors.New("timeout exceeded")

ErrTimeoutExceeded is returned when a timeout is exceeded.

Functions

func PollForReadiness

func PollForReadiness(
	ctx context.Context,
	deadline time.Duration,
	poll func(context.Context) (bool, error),
) error

PollForReadiness polls a check function until ready or timeout.

This function repeatedly calls the provided poll function at regular intervals until either:

  • The poll function returns (true, nil) indicating readiness
  • The deadline is exceeded
  • The poll function returns an error

The poll function should return (false, nil) to continue polling, (true, nil) when the resource is ready, or (false, error) on errors.

Returns an error if polling times out or if the poll function returns an error.

func WaitForAPIServerReady

func WaitForAPIServerReady(
	ctx context.Context,
	clientset kubernetes.Interface,
	deadline time.Duration,
) error

WaitForAPIServerReady waits for the Kubernetes API server to be ready and stable.

This function polls the API server by performing a ServerVersion request until it responds consistently without errors. This is useful after cluster bootstrap when the API server may be unstable due to initial startup.

The function uses the configured polling interval and will timeout after the specified deadline.

Parameters:

  • ctx: Context for cancellation
  • clientset: Kubernetes client interface
  • deadline: Maximum time to wait for API server readiness

Returns an error if the API server is not ready within the deadline.

func WaitForAPIServerStable

func WaitForAPIServerStable(
	ctx context.Context,
	clientset kubernetes.Interface,
	deadline time.Duration,
	requiredSuccesses int,
) error

WaitForAPIServerStable waits for the Kubernetes API server to respond consistently.

Unlike WaitForAPIServerReady which returns on the first successful response, this function requires multiple consecutive successful responses to ensure the API server is truly stable. This is particularly useful for Talos where the API server may respond once but then fail with connection resets.

Parameters:

  • ctx: Context for cancellation
  • clientset: Kubernetes client interface
  • deadline: Maximum time to wait for API server stability
  • requiredSuccesses: Number of consecutive successful responses required

Returns an error if the API server is not stable within the deadline.

func WaitForDaemonSetReady

func WaitForDaemonSetReady(
	ctx context.Context,
	clientset kubernetes.Interface,
	namespace, name string,
	deadline time.Duration,
) error

WaitForDaemonSetReady waits for a DaemonSet to be ready.

This function polls the specified DaemonSet until it is ready or the deadline is reached. A DaemonSet is considered ready when:

  • At least one pod is scheduled
  • No pods are unavailable
  • All pods have been updated to the current specification

The function tolerates NotFound errors and continues polling. Other API errors are returned immediately.

Returns an error if the DaemonSet is not ready within the deadline or if an API error occurs.

func WaitForDeploymentReady

func WaitForDeploymentReady(
	ctx context.Context,
	clientset kubernetes.Interface,
	namespace, name string,
	deadline time.Duration,
) error

WaitForDeploymentReady waits for a Deployment to be ready.

This function polls the specified Deployment until it is ready or the deadline is reached. A Deployment is considered ready when:

  • It has at least one replica
  • All replicas have been updated
  • All replicas are available

The function tolerates NotFound errors and continues polling. Other API errors are returned immediately.

Returns an error if the Deployment is not ready within the deadline or if an API error occurs.

func WaitForMultipleResources

func WaitForMultipleResources(
	ctx context.Context,
	clientset kubernetes.Interface,
	checks []Check,
	timeout time.Duration,
) error

WaitForMultipleResources waits for multiple Kubernetes resources to be ready.

This function checks each resource in sequence, allocating remaining timeout proportionally. If any resource fails to become ready within the allocated time, the function returns an error.

The timeout parameter is shared across all resources, so each subsequent resource gets less time to become ready. Resources are checked in the order they appear in the checks slice.

Returns ErrTimeoutExceeded if the timeout is reached before a resource is checked. Returns an error if any resource fails to become ready.

func WaitForNodeReady

func WaitForNodeReady(
	ctx context.Context,
	clientset kubernetes.Interface,
	deadline time.Duration,
) error

WaitForNodeReady polls until at least one node has condition Ready=True. This is used after CNI installation to ensure the network layer is functional before proceeding to install post-CNI components.

Types

type Check

type Check struct {
	// Type specifies the kind of Kubernetes resource to check for readiness.
	// Valid values are "deployment" or "daemonset".
	Type string
	// Namespace is the Kubernetes namespace where the resource resides.
	Namespace string
	// Name is the name of the resource to check for readiness.
	Name string
}

Check defines a check to perform for a Kubernetes resource.

Jump to

Keyboard shortcuts

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