utils

package
v0.1.0-alpha.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertTypedToUnstructured

func ConvertTypedToUnstructured(typed interface{}) (map[string]interface{}, error)

ConvertTypedToUnstructured converts a typed object to an unstructured map. Useful for converting typed structs to Helm values maps.

func ConvertUnstructuredToTyped

func ConvertUnstructuredToTyped(u map[string]interface{}, typed interface{}) error

ConvertUnstructuredToTyped converts an unstructured map to a typed object

func CountReadyPods

func CountReadyPods(pods *v1.PodList) int

CountReadyPods counts the number of ready pods (Running + Ready condition)

func CreateKubernetesClients

func CreateKubernetesClients(restConfig *rest.Config) (dynamic.Interface, meta.RESTMapper, error)

CreateKubernetesClients creates the dynamic client and REST mapper.

func IsNodeReady

func IsNodeReady(node *v1.Node) bool

IsNodeReady checks if a node is in Ready state

func ListPods

func ListPods(ctx context.Context, clientset kubernetes.Interface, namespace string, labelSelector string) (*v1.PodList, error)

ListPods lists pods in a namespace with an optional label selector

func PollForCondition

func PollForCondition(ctx context.Context, timeout, interval time.Duration, condition func() (bool, error)) error

PollForCondition repeatedly evaluates a condition function at the specified interval until it returns true or the timeout is reached. Returns an error if the condition fails, returns an error, or the timeout expires.

func ScalePodCliqueScalingGroup

func ScalePodCliqueScalingGroup(ctx context.Context, restConfig *rest.Config, namespace, name string, replicas int, timeout, interval time.Duration) error

ScalePodCliqueScalingGroup scales a PodCliqueScalingGroup to the specified replica count It waits for the PCSG to exist before scaling

func ScalePodCliqueScalingGroupWithClient

func ScalePodCliqueScalingGroupWithClient(ctx context.Context, dynamicClient dynamic.Interface, namespace, name string, replicas int, timeout, interval time.Duration) error

ScalePodCliqueScalingGroupWithClient scales a PodCliqueScalingGroup using an existing dynamic client It waits for the PCSG to exist before scaling

func ScalePodCliqueSet

func ScalePodCliqueSet(ctx context.Context, restConfig *rest.Config, namespace, name string, replicas int) error

ScalePodCliqueSet scales a PodCliqueSet to the specified replica count

func ScalePodCliqueSetWithClient

func ScalePodCliqueSetWithClient(ctx context.Context, dynamicClient dynamic.Interface, namespace, name string, replicas int) error

ScalePodCliqueSetWithClient scales a PodCliqueSet using an existing dynamic client

func SetNodeSchedulable

func SetNodeSchedulable(ctx context.Context, clientset kubernetes.Interface, nodeName string, schedulable bool) error

SetNodeSchedulable sets a Kubernetes node to be unschedulable (cordoned) or schedulable (uncordoned). This function uses retry logic to handle optimistic concurrency conflicts that can occur when multiple controllers or processes are updating node objects concurrently.

func VerifyPodPhases

func VerifyPodPhases(pods *v1.PodList, expectedRunning, expectedPending int) error

VerifyPodPhases verifies that the pod counts match the expected values Pass -1 for any count you want to skip verification

func WaitAndGetReadyNode

func WaitAndGetReadyNode(ctx context.Context, clientset *kubernetes.Clientset, nodeName string, timeout time.Duration, logger *Logger) (node *v1.Node, err error)

WaitAndGetReadyNode waits for a specific node to become ready after container restart and returns the ready node

func WaitForPodCount

func WaitForPodCount(ctx context.Context, clientset kubernetes.Interface, namespace string, labelSelector string, expectedCount int, timeout time.Duration, interval time.Duration) (*v1.PodList, error)

WaitForPodCount waits for a specific number of pods to be created with the given label selector Returns the pod list once the expected count is reached

func WaitForPodCountAndPhases

func WaitForPodCountAndPhases(ctx context.Context, clientset kubernetes.Interface, namespace, labelSelector string, expectedTotal, expectedRunning, expectedPending int, timeout, interval time.Duration) error

WaitForPodCountAndPhases waits for pods to reach specific total count and phase counts Pass -1 for any count you want to skip verification

func WaitForPods

func WaitForPods(ctx context.Context, restConfig *rest.Config, namespaces []string, labelSelector string, expectedCount int, timeout time.Duration, interval time.Duration, logger *Logger) error

WaitForPods waits for pods to be ready in the specified namespaces labelSelector is optional (pass empty string for all pods), timeout of 0 defaults to 5 minutes, interval of 0 defaults to 5 seconds expectedCount is the expected number of pods (pass 0 to skip count validation)

func WaitForPodsInNamespace

func WaitForPodsInNamespace(ctx context.Context, namespace string, restConfig *rest.Config, expectedCount int, timeout time.Duration, interval time.Duration, logger *Logger) error

WaitForPodsInNamespace waits for all pods in a namespace to be ready expectedCount is the expected number of pods (pass 0 to skip count validation)

Types

type AppliedResource

type AppliedResource struct {
	Name      string
	Namespace string
	GVK       schema.GroupVersionKind
	GVR       schema.GroupVersionResource
}

AppliedResource holds information about an applied Kubernetes resource

func ApplyYAMLData

func ApplyYAMLData(ctx context.Context, yamlData []byte, namespace string, dynamicClient dynamic.Interface, restMapper meta.RESTMapper, logger *Logger) ([]AppliedResource, error)

ApplyYAMLData applies YAML data to Kubernetes.

func ApplyYAMLFile

func ApplyYAMLFile(ctx context.Context, yamlFilePath string, namespace string, restConfig *rest.Config, logger *Logger) ([]AppliedResource, error)

ApplyYAMLFile applies a YAML file containing Kubernetes resources namespace parameter is optional - pass empty string to use namespace from YAML

type LogLevel

type LogLevel int

LogLevel represents the logging verbosity level

const (
	// DebugLevel logs are typically voluminous, and are usually disabled in production.
	DebugLevel LogLevel = iota
	// InfoLevel is the default logging priority.
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual human review.
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly, it shouldn't generate any error-level logs.
	ErrorLevel
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger provides a logrus-compatible interface backed by logr

func NewTestLogger

func NewTestLogger(verbosity LogLevel) *Logger

NewTestLogger creates a new logger with the specified verbosity level

func NewTestLoggerWithOutput

func NewTestLoggerWithOutput(verbosity LogLevel, output io.Writer) *Logger

NewTestLoggerWithOutput creates a new logger with the specified verbosity level and output writer

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

Debug logs a debug message

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf logs a formatted debug message

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

Error logs an error message

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf logs a formatted error message

func (*Logger) GetLevel

func (l *Logger) GetLevel() LogLevel

GetLevel returns the current log level (always returns InfoLevel for now)

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

Info logs an info message

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof logs a formatted info message

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

Warn logs a warning message

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf logs a formatted warning message

func (*Logger) WriterLevel

func (l *Logger) WriterLevel(level LogLevel) io.Writer

WriterLevel returns an io.Writer that logs at the specified level This is used for compatibility with code that redirects command output to logger

type PodPhaseCount

type PodPhaseCount struct {
	Running int
	Pending int
	Failed  int
	Unknown int
	Total   int
}

PodPhaseCount holds counts of pods by phase

func CountPodsByPhase

func CountPodsByPhase(pods *v1.PodList) PodPhaseCount

CountPodsByPhase counts pods by their phase and returns a PodPhaseCount

Jump to

Keyboard shortcuts

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