driftpipeline

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DriftResult

type DriftResult struct {
	// Status is the detected drift status
	Status DriftStatus

	// DeployedSHA is the commit SHA currently deployed
	DeployedSHA string

	// ExpectedSHA is the commit SHA from the PR
	ExpectedSHA string

	// Health is the ArgoCD application health status
	Health string

	// SyncStatus is the ArgoCD application sync status
	SyncStatus string

	// Message provides additional context about the result
	Message string

	// Error contains any error that occurred during detection
	Error error
}

DriftResult represents the result of drift detection for a PR.

type DriftStatus

type DriftStatus string

DriftStatus represents the deployment status of a merged PR.

const (
	// DriftStatusDeploying indicates deployment is in progress
	DriftStatusDeploying DriftStatus = "deploying"

	// DriftStatusSynced indicates deployment is complete and synchronized
	DriftStatusSynced DriftStatus = "synced"

	// DriftStatusDrifted indicates deployment has drifted from expected state
	DriftStatusDrifted DriftStatus = "drifted"

	// DriftStatusUnhealthy indicates application is unhealthy after deployment
	DriftStatusUnhealthy DriftStatus = "unhealthy"

	// DriftStatusFailed indicates deployment failed
	DriftStatusFailed DriftStatus = "failed"
)

func (DriftStatus) String

func (ds DriftStatus) String() string

String returns the string representation of the drift status.

func (DriftStatus) ToState

func (ds DriftStatus) ToState() labels.State

ToState converts a DriftStatus to the corresponding labels.State.

type DriftWorkItem

type DriftWorkItem struct {
	// PR is the merged pull request to monitor
	PR github.PullRequest

	// Cluster is the name of the ArgoCD cluster to check
	Cluster string

	// Application is the ArgoCD application name mapped from the PR
	Application string

	// Priority for processing (0 = lowest)
	Priority int

	// CreatedAt is when this work item was created
	CreatedAt time.Time

	// Metadata for additional context
	Metadata map[string]string
}

DriftWorkItem represents a work item for drift detection. Each item tracks a merged PR's deployment status in a specific cluster.

type GitHubClient

type GitHubClient interface {
	// ListPRs retrieves pull requests from a repository
	ListPRs(ctx context.Context, repo github.Repository) ([]github.PullRequest, error)

	// GetPR retrieves a specific pull request
	GetPR(ctx context.Context, repo github.Repository, number int) (*github.PullRequest, error)
}

GitHubClient defines the GitHub operations needed by the drift pipeline.

type LabelManager

type LabelManager interface {
	// GetCurrentState determines the current state of a PR from its labels
	GetCurrentState(pr github.PullRequest) labels.State

	// ApplyState applies a state to a PR by updating its labels
	ApplyState(ctx context.Context, pr github.PullRequest, state labels.State) error

	// TransitionState performs a validated state transition
	TransitionState(ctx context.Context, pr github.PullRequest, toState labels.State) error
}

LabelManager defines the label management operations needed by the drift pipeline.

type Logger

type Logger interface {
	// Sugar returns a sugared logger interface for key-value logging
	Sugar() *zap.SugaredLogger
}

Logger defines the logging interface used by the drift pipeline. This uses structured logging with key-value pairs for compatibility with pkg/logger.

type Mapper

type Mapper interface {
	// GetApplicationName maps a PR to its ArgoCD application name
	GetApplicationName(pr github.PullRequest, cluster string) string
}

Mapper defines the PR to ArgoCD application mapping interface.

func NewMapper

func NewMapper() Mapper

NewMapper creates a new PR to ArgoCD application name mapper.

type Monitor

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

Monitor checks ArgoCD application status and evaluates drift.

func NewMonitor

func NewMonitor(argoCDClients map[string]applications.Service, logger Logger) *Monitor

NewMonitor creates a new ArgoCD status monitor.

func (*Monitor) CheckDrift

func (m *Monitor) CheckDrift(ctx context.Context, pr github.PullRequest, cluster, appName string) DriftResult

CheckDrift checks if a PR's deployment has drifted from the expected state. It queries the ArgoCD application for the given cluster and compares: - Deployed commit SHA vs PR head SHA - Application health status - Application sync status

Returns a DriftResult indicating the drift status and details.

type Pipeline

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

Pipeline orchestrates drift detection for merged PRs across ArgoCD clusters. It periodically discovers merged PRs and schedules drift detection work items.

func New

func New(cfg PipelineConfig) (*Pipeline, error)

New creates a new drift detection pipeline.

func (*Pipeline) DiscoverMergedPRs

func (p *Pipeline) DiscoverMergedPRs(ctx context.Context, org string, repos []string) ([]github.PullRequest, error)

DiscoverMergedPRs discovers PRs that are in the merged state and need drift monitoring. It returns a list of PRs across all configured repositories.

func (*Pipeline) Run

func (p *Pipeline) Run(ctx context.Context) error

Run starts the drift detection pipeline. It runs a reconciliation loop that discovers merged PRs and checks their drift status. This method blocks until the pipeline is stopped.

func (*Pipeline) Stop

func (p *Pipeline) Stop()

Stop gracefully stops the drift detection pipeline.

type PipelineConfig

type PipelineConfig struct {
	// ArgoCDClients map cluster names to ArgoCD application services
	ArgoCDClients map[string]applications.Service

	// GitHubClient for PR operations
	GitHubClient GitHubClient

	// LabelManager for updating PR labels
	LabelManager LabelManager

	// Mapper for PR → ArgoCD app name mapping
	Mapper Mapper

	// Logger for structured logging
	Logger Logger

	// ReconcileInterval is how often to check for drift (default: 60s)
	ReconcileInterval time.Duration

	// WorkerCount is the number of concurrent drift detection workers (default: 5)
	WorkerCount int
}

PipelineConfig configures the drift detection pipeline.

type ProcessResult

type ProcessResult struct {
	// Success indicates whether processing completed without errors
	Success bool

	// DriftResult contains the drift detection result
	DriftResult DriftResult

	// NewState is the label state to apply to the PR
	NewState labels.State

	// Duration is how long processing took
	Duration time.Duration

	// Error contains any error that occurred during processing
	Error error
}

ProcessResult represents the result of processing a drift work item.

type Processor

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

Processor handles individual drift detection work items. It checks ArgoCD status and updates PR labels based on drift status.

func NewProcessor

func NewProcessor(cfg ProcessorConfig) *Processor

NewProcessor creates a new drift detection processor.

func (*Processor) Process

func (p *Processor) Process(ctx context.Context, item DriftWorkItem) ProcessResult

Process handles a single drift detection work item. It: 1. Checks ArgoCD application status 2. Evaluates drift based on status 3. Updates PR labels to reflect drift status

Returns a ProcessResult indicating success/failure and new state.

type ProcessorConfig

type ProcessorConfig struct {
	Monitor      *Monitor
	LabelManager LabelManager
	Logger       Logger
}

ProcessorConfig configures the drift processor.

type SugaredLogger

type SugaredLogger interface {
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
}

SugaredLogger defines the sugared logging interface for key-value pairs. This matches the zap.SugaredLogger interface methods we use.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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