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:
- Query ArgoCD for deployment status
- Compare deployed SHA with expected SHA from TrackerRef
- Update CRD status and conditions based on drift detection
- 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 ¶
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:
- Fetch the DriftMonitor resource
- Get the referenced PullRequestTracker for expected SHA
- Query ArgoCD for current deployment status
- Compare deployed SHA with expected SHA
- Update CRD status and conditions based on drift analysis
- 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.