Documentation
¶
Overview ¶
Package deployment provides domain types for deployment status tracking and drift detection. This package contains pure domain types (value objects and enums) that represent the core concepts of deployment monitoring without any external dependencies.
Domain types in this package:
- DeploymentStatus: Represents the current state of a deployment
- DriftDetection: Represents drift between expected and actual deployment state
These types are used throughout the drift monitoring subsystem to track deployment state and detect when deployments deviate from expected configurations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeploymentStatus ¶
type DeploymentStatus struct {
// State indicates the current deployment state (synced, deploying, failed, etc.)
State Status
// Health provides a human-readable health status from the deployment platform.
// Examples: "Healthy", "Progressing", "Degraded", "Missing"
Health string
// SyncStatus provides the synchronization status from the deployment platform.
// Examples: "Synced", "OutOfSync", "Unknown"
SyncStatus string
// RevisionSHA is the Git commit SHA that is currently deployed.
// This is used for drift detection by comparing against the expected SHA.
RevisionSHA string
// LastSyncTime is the timestamp of the last successful synchronization.
// Zero time indicates the deployment has never been synced.
LastSyncTime time.Time
}
DeploymentStatus represents the complete status of a deployment. It encapsulates all information needed to determine the health and sync state of a deployed application, including the deployed revision and timing information.
This is a value object - it is immutable and has no identity beyond its values.
func NewDeploymentStatus ¶
func NewDeploymentStatus(state Status, health, syncStatus, revisionSHA string, lastSyncTime time.Time) DeploymentStatus
NewDeploymentStatus creates a new DeploymentStatus with the specified values. This constructor ensures all required fields are provided and validates the state.
Parameters:
- state: The deployment state (must be valid)
- health: Human-readable health status
- syncStatus: Synchronization status
- revisionSHA: Git commit SHA that is deployed
- lastSyncTime: Timestamp of last successful sync
Returns a DeploymentStatus. If state is invalid, State is set to StatusUnknown.
func (DeploymentStatus) IsDrifted ¶
func (ds DeploymentStatus) IsDrifted() bool
IsDrifted returns true if the deployment has drifted from the expected state. Drift occurs when the deployed revision does not match what was expected from the merged PR.
func (DeploymentStatus) IsHealthy ¶
func (ds DeploymentStatus) IsHealthy() bool
IsHealthy returns true if the deployment is in a healthy state. A deployment is considered healthy if it is synced and not experiencing any health or synchronization issues.
func (DeploymentStatus) IsSynced ¶
func (ds DeploymentStatus) IsSynced() bool
IsSynced returns true if the deployment is synchronized with the desired state. This checks both the state and sync status to ensure the deployment has reached its target configuration.
func (DeploymentStatus) String ¶
func (ds DeploymentStatus) String() string
String returns a human-readable representation of the deployment status. This includes all key information needed to understand the deployment state.
type DriftDetection ¶
type DriftDetection struct {
// ExpectedSHA is the Git commit SHA that should be deployed.
// This typically comes from the merged PR's head commit.
ExpectedSHA string
// ActualSHA is the Git commit SHA that is actually deployed.
// This comes from the deployment platform (e.g., ArgoCD).
ActualSHA string
// DetectedAt is the timestamp when this drift was first detected.
// This is used to calculate drift age and track how long drift has persisted.
DetectedAt time.Time
// Severity indicates how critical this drift is.
// Critical drift requires immediate attention, while info-level drift
// may be acceptable in certain situations.
Severity DriftSeverity
}
DriftDetection represents detected drift between expected and actual deployment state. It captures information about when drift was detected, what the expected and actual states are, and how severe the drift is.
This is a value object - it is immutable and has no identity beyond its values. Drift is detected by comparing the deployed Git commit SHA against the expected SHA from a merged PR.
func NewDriftDetection ¶
func NewDriftDetection(expectedSHA, actualSHA string, detectedAt time.Time, severity DriftSeverity) DriftDetection
NewDriftDetection creates a new DriftDetection with the specified values. This constructor ensures all required fields are provided and validates the severity.
Parameters:
- expectedSHA: The Git commit SHA that should be deployed
- actualSHA: The Git commit SHA that is actually deployed
- detectedAt: Timestamp when drift was detected
- severity: The severity level of this drift
Returns a DriftDetection. If severity is invalid, it defaults to SeverityWarning.
func NewNoDrift ¶
func NewNoDrift(sha string) DriftDetection
NewNoDrift creates a DriftDetection representing no drift. This is used when the expected and actual SHAs match.
Parameters:
- sha: The Git commit SHA (same for both expected and actual)
Returns a DriftDetection with SeverityNone and matching SHAs.
func (DriftDetection) DriftAge ¶
func (dd DriftDetection) DriftAge() time.Duration
DriftAge returns the duration since drift was first detected. This is useful for determining how long a deployment has been out of sync and for escalating severity based on age.
Returns zero duration if DetectedAt is not set (zero time).
func (DriftDetection) HasDrift ¶
func (dd DriftDetection) HasDrift() bool
HasDrift returns true if there is drift between expected and actual state. Drift exists when the SHAs differ. Empty SHAs are considered non-drifted to handle cases where the deployment is not yet initialized.
func (DriftDetection) String ¶
func (dd DriftDetection) String() string
String returns a human-readable representation of the drift detection. This includes all key information needed to understand the drift state.
type DriftSeverity ¶
type DriftSeverity string
DriftSeverity indicates the severity level of detected drift. It provides a way to categorize drift by its impact on the deployment and helps prioritize remediation actions.
const ( // SeverityCritical indicates critical drift that requires immediate attention. // This typically means the deployed version is significantly different from // what was expected, potentially causing service disruption or security issues. SeverityCritical DriftSeverity = "critical" // SeverityWarning indicates moderate drift that should be addressed. // The deployment differs from expectations but is not causing immediate issues. // This might represent a minor version mismatch or configuration drift. SeverityWarning DriftSeverity = "warning" // SeverityInfo indicates informational drift notification. // This is used for minor deviations that don't require immediate action, // or for tracking drift that has been acknowledged but not yet resolved. SeverityInfo DriftSeverity = "info" // SeverityNone indicates no drift is present. // The deployed revision matches the expected revision exactly. SeverityNone DriftSeverity = "none" )
func AllSeverities ¶
func AllSeverities() []DriftSeverity
AllSeverities returns all drift severity levels. Used for validation and testing.
func DetermineSeverity ¶
func DetermineSeverity(expectedSHA, actualSHA string, detectedAt time.Time) DriftSeverity
DetermineSeverity calculates drift severity based on SHA difference and age. This implements business rules for escalating drift severity over time.
The severity escalation logic is:
- No drift (SHAs match) -> SeverityNone
- Drift detected, age < 5 minutes -> SeverityInfo
- Drift detected, age 5-15 minutes -> SeverityWarning
- Drift detected, age > 15 minutes -> SeverityCritical
Parameters:
- expectedSHA: The expected Git commit SHA
- actualSHA: The actual deployed Git commit SHA
- detectedAt: When the drift was first detected
Returns the appropriate DriftSeverity based on the drift state and age.
func (DriftSeverity) IsValid ¶
func (ds DriftSeverity) IsValid() bool
IsValid checks if the severity is a valid drift severity level.
func (DriftSeverity) String ¶
func (ds DriftSeverity) String() string
String returns the string representation of the severity.
type Status ¶
type Status string
Status represents the deployment state of an application in a cluster. It is used to track whether a deployment is healthy, synced, or experiencing issues.
const ( // StatusSynced indicates the deployment is synchronized with the desired state. // The application is deployed at the expected revision and is healthy. StatusSynced Status = "synced" // StatusDeploying indicates the deployment is currently in progress. // The application is being rolled out but has not yet reached the desired state. StatusDeploying Status = "deploying" // StatusFailed indicates the deployment has failed. // This could be due to image pull errors, resource constraints, or other failures. StatusFailed Status = "failed" // StatusUnhealthy indicates the deployment is unhealthy. // The application is deployed but health checks are failing. StatusUnhealthy Status = "unhealthy" // StatusDrifted indicates the deployment has drifted from the expected state. // The deployed revision does not match what was expected from the merged PR. StatusDrifted Status = "drifted" // StatusUnknown represents an unknown status (used for error handling). // This typically indicates the status could not be determined from the cluster. StatusUnknown Status = "unknown" )
func AllStatuses ¶
func AllStatuses() []Status
AllStatuses returns all valid deployment statuses. Used for validation and testing. StatusUnknown is intentionally excluded as it represents an invalid/error state.
func DetermineState ¶
DetermineState derives a deployment state from health and sync status strings. This function implements the business logic for mapping platform-specific status strings to our domain model's deployment states.
The mapping logic is as follows:
- Healthy + Synced -> StatusSynced
- Progressing -> StatusDeploying
- Degraded/Missing/Unknown health -> StatusUnhealthy
- OutOfSync -> StatusDrifted
- Any other combination -> StatusFailed
Parameters:
- health: Health status from the deployment platform (e.g., ArgoCD)
- syncStatus: Sync status from the deployment platform
Returns the appropriate Status for the given health and sync combination.