common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package common provides shared utilities and types for CRD controllers. This package contains helper functions for condition management, status updates, and other cross-cutting concerns used by multiple controllers.

Index

Constants

View Source
const (
	// ConditionTypeReady indicates the resource is ready for use.
	// Status=True means the resource has successfully completed all initialization.
	// This is the primary condition that most users care about.
	ConditionTypeReady = "Ready"

	// ConditionTypeQualified indicates the PR has passed qualification checks.
	// Only applies to PullRequestTracker.
	ConditionTypeQualified = "Qualified"

	// ConditionTypeMerged indicates the PR has been merged.
	// Only applies to PullRequestTracker.
	ConditionTypeMerged = "Merged"

	// ConditionTypeSynced indicates the deployment is synchronized.
	// Applies to both PullRequestTracker (post-merge) and DriftMonitor.
	ConditionTypeSynced = "Synced"

	// ConditionTypeDrifted indicates the deployment has drifted from expected state.
	// Only applies to DriftMonitor.
	ConditionTypeDrifted = "Drifted"

	// ConditionTypeUnhealthy indicates the application is unhealthy.
	// Only applies to DriftMonitor.
	ConditionTypeUnhealthy = "Unhealthy"
)

Common condition types used across multiple CRDs. These provide a standard vocabulary for expressing the state of resources.

View Source
const (
	// ReasonDiscovered indicates the resource was discovered.
	ReasonDiscovered = "Discovered"

	// ReasonQualificationPassed indicates qualification checks passed.
	ReasonQualificationPassed = "QualificationPassed"

	// ReasonQualificationFailed indicates qualification checks failed.
	ReasonQualificationFailed = "QualificationFailed"

	// ReasonMergeSucceeded indicates the PR was successfully merged.
	ReasonMergeSucceeded = "MergeSucceeded"

	// ReasonMergeFailed indicates the PR merge failed.
	ReasonMergeFailed = "MergeFailed"

	// ReasonDeploymentSynced indicates the deployment is synchronized.
	ReasonDeploymentSynced = "DeploymentSynced"

	// ReasonDeploymentDrifted indicates the deployment has drifted.
	ReasonDeploymentDrifted = "DeploymentDrifted"

	// ReasonDeploymentUnhealthy indicates the deployment is unhealthy.
	ReasonDeploymentUnhealthy = "DeploymentUnhealthy"

	// ReasonReconciling indicates the resource is being reconciled.
	ReasonReconciling = "Reconciling"

	// ReasonReconciliationError indicates an error during reconciliation.
	ReasonReconciliationError = "ReconciliationError"

	// ReasonGitHubAPIError indicates a GitHub API error occurred.
	ReasonGitHubAPIError = "GitHubAPIError"

	// ReasonArgoCDAPIError indicates an ArgoCD API error occurred.
	ReasonArgoCDAPIError = "ArgoCDAPIError"
)

Common condition reasons. These provide standardized reasons for condition transitions.

Variables

This section is empty.

Functions

func GetCondition

func GetCondition(conditions []metav1.Condition, conditionType string) *metav1.Condition

GetCondition retrieves a condition by type from the conditions list. Returns nil if the condition is not found.

Parameters:

  • conditions: The conditions slice to search
  • conditionType: The type of condition to find

Returns the condition if found, nil otherwise.

func IsConditionFalse

func IsConditionFalse(conditions []metav1.Condition, conditionType string) bool

IsConditionFalse checks if a specific condition is present and has status False.

Parameters:

  • conditions: The conditions slice to check
  • conditionType: The type of condition to check

Returns true if the condition exists and has status False, false otherwise.

func IsConditionTrue

func IsConditionTrue(conditions []metav1.Condition, conditionType string) bool

IsConditionTrue checks if a specific condition is present and has status True.

Parameters:

  • conditions: The conditions slice to check
  • conditionType: The type of condition to check

Returns true if the condition exists and has status True, false otherwise.

func RemoveCondition

func RemoveCondition(conditions []metav1.Condition, conditionType string) []metav1.Condition

RemoveCondition removes a condition by type from the conditions list. Returns the updated conditions slice.

Parameters:

  • conditions: The existing conditions slice
  • conditionType: The type of condition to remove

Returns the conditions slice with the specified condition removed.

func SetCondition

func SetCondition(
	conditions []metav1.Condition,
	conditionType string,
	status metav1.ConditionStatus,
	reason string,
	message string,
	observedGeneration int64,
) []metav1.Condition

SetCondition adds or updates a condition in the conditions list. If a condition with the same type already exists, it is updated. Otherwise, a new condition is appended.

This function follows Kubernetes conventions:

  • LastTransitionTime is only updated when Status changes
  • ObservedGeneration tracks which generation was observed

Parameters:

  • conditions: The existing conditions slice (may be nil)
  • conditionType: The type of condition to set
  • status: The status of the condition (True, False, Unknown)
  • reason: A camel-case reason for the condition's status
  • message: A human-readable message describing the condition
  • observedGeneration: The generation of the resource being observed

Returns the updated conditions slice.

func SetReadyCondition

func SetReadyCondition(
	conditions []metav1.Condition,
	ready bool,
	reason string,
	message string,
	observedGeneration int64,
) []metav1.Condition

SetReadyCondition is a convenience function to set the Ready condition. This is the most commonly used condition across all resources.

Parameters:

  • conditions: The existing conditions slice
  • ready: Whether the resource is ready (true) or not (false)
  • reason: The reason for the ready status
  • message: A human-readable message
  • observedGeneration: The observed generation

Returns the updated conditions slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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