driftmonitor

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: 15 Imported by: 0

Documentation

Overview

Package driftmonitor provides the Kubernetes controller for DriftMonitor resources. This controller reconciles DriftMonitor CRDs by checking ArgoCD deployment status and detecting drift between expected and actual deployment states.

The controller implements the hexagonal architecture pattern:

  • Domain logic is in internal/domain/deployment
  • ArgoCD integration is via ports (ArgoCDClient interface)
  • State is persisted in Kubernetes CRDs

Reconciliation logic:

  1. Query ArgoCD for deployment status
  2. Compare deployed SHA with expected SHA from TrackerRef
  3. Update CRD status and conditions based on drift detection
  4. Handle ArgoCD API errors gracefully with backoff

The controller coordinates with DriftMonitor resources created by the drift pipeline to provide Kubernetes-native drift monitoring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgoCDClient

type ArgoCDClient interface {
	// GetApplicationStatus retrieves the deployment status of an application
	// from ArgoCD for drift detection and health monitoring.
	GetApplicationStatus(ctx context.Context, cluster, application string) (*deployment.DeploymentStatus, error)
}

ArgoCDClient defines the interface for ArgoCD operations needed by the controller. This interface abstracts ArgoCD API calls and allows for testing with mocks.

type DriftResult

type DriftResult struct {
	Synced  bool
	Message string
	Status  deployment.Status
}

DriftResult encapsulates the result of drift analysis.

type Logger

type Logger interface {
	Info(msg string, keysAndValues ...interface{})
	Error(err error, msg string, keysAndValues ...interface{})
	V(level int) Logger
}

Logger defines the logging interface used by the controller.

type Reconciler

type Reconciler struct {
	client.Client
	Scheme       *runtime.Scheme
	ArgoCDClient ArgoCDClient
	Logger       Logger
}

Reconciler reconciles a DriftMonitor object. It implements the controller-runtime reconcile.Reconciler interface.

func NewReconciler

func NewReconciler(
	client client.Client,
	scheme *runtime.Scheme,
	argoCDClient ArgoCDClient,
	logger Logger,
) *Reconciler

NewReconciler creates a new DriftMonitor reconciler.

Parameters:

  • client: Kubernetes client for CRD operations
  • scheme: Runtime scheme for type registration
  • argoCDClient: ArgoCD API client interface
  • logger: Logging interface

Returns a configured Reconciler ready for use with controller-runtime.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile implements the main reconciliation logic for DriftMonitor resources. It is called by the controller-runtime framework whenever a DriftMonitor resource is created, updated, or periodically re-queued.

Reconciliation steps:

  1. Fetch the DriftMonitor resource
  2. Get the referenced PullRequestTracker for expected SHA
  3. Query ArgoCD for current deployment status
  4. Compare deployed SHA with expected SHA
  5. Update CRD status and conditions based on drift analysis
  6. Schedule next check based on drift status

Returns:

  • Result: Controls re-queuing behavior (shorter interval for drifted deployments)
  • Error: Causes exponential backoff retry if non-nil

func (*Reconciler) SetupWithManager

func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager sets up the controller with the Manager. This configures the controller to watch DriftMonitor resources and sets up any required RBAC permissions.

Jump to

Keyboard shortcuts

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