Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PTEUDO-1422: Publish status events for state changes in database #377

Merged
merged 11 commits into from
Dec 19, 2024
110 changes: 110 additions & 0 deletions api/v1/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package v1

import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type ConditionType string

const (
// ConditionReady indicates the database is not just synced but available for user.
ConditionReady ConditionType = "Ready"

// ConditionSync indicates whether the db-controller is actively performing operations such as provisioning, deleting, or migrating.
// It is set to True when the state is fully synchronized with Crossplane/AWS/GCP
ConditionSync ConditionType = "Synced"

// ReasonAvailable indicates that the database is fully synchronized and ready for use.
ReasonAvailable = "Available"

// ReasonUnavailable indicates that the database is not available due to an issue during reconciliation.
ReasonUnavailable = "Unavailable"

// ReasonProvisioning indicates that the database is in the process of being created or provisioned.
ReasonProvisioning = "Provisioning"

// ReasonMigrating indicates that the database is undergoing migration to a new target state.
ReasonMigrating = "Migrating"

// ReasonDeleting indicates that the database is in the process of being deleted.
ReasonDeleting = "Deleting"

// ReasonConnectionIssue indicates that there is a connectivity issue with the database, such as being unable to establish a connection using the provisioned secrets.
ReasonConnectionIssue = "ConnectionIssue"

// ReasonNeedsMigrate indicates that the database requires migration due to versioning mismatches or other critical changes.
ReasonNeedsMigrate = "NeedsMigrate"
)

func CreateCondition(condType ConditionType, status metav1.ConditionStatus, reason, message string) metav1.Condition {
return metav1.Condition{
Type: string(condType),
Status: status,
Reason: reason,
Message: message,
}
}

func ProvisioningCondition() metav1.Condition {
return CreateCondition(
ConditionSync,
metav1.ConditionFalse,
ReasonProvisioning,
"Database provisioning is in progress",
)
}

func DeletingCondition() metav1.Condition {
return CreateCondition(
ConditionSync,
metav1.ConditionFalse,
ReasonDeleting,
"Database deletion is in progress",
)
}

func MigratingCondition() metav1.Condition {
return CreateCondition(
ConditionSync,
metav1.ConditionFalse,
ReasonMigrating,
"Database migration is underway",
)
}

func DatabaseReadyCondition() metav1.Condition {
return CreateCondition(
ConditionSync,
metav1.ConditionTrue,
ReasonAvailable,
"Database is provisioned.",
)
}

func ConnectionIssueCondition(err error) metav1.Condition {
return CreateCondition(
ConditionReady,
metav1.ConditionFalse,
ReasonConnectionIssue,
fmt.Sprintf("Database connection error: %v", err),
)
}

func ReconcileErrorCondition(err error) metav1.Condition {
return CreateCondition(
ConditionReady,
metav1.ConditionFalse,
ReasonUnavailable,
fmt.Sprintf("Reconciliation encountered an issue: %v", err),
)
}

func ReconcileSuccessCondition() metav1.Condition {
return CreateCondition(
ConditionReady,
metav1.ConditionTrue,
ReasonAvailable,
"Database successfully synchronized and ready for use",
)
}
1 change: 1 addition & 0 deletions api/v1/databaseclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ type DatabaseClaimConnectionInfo struct {
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type`
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".status.activeDB.dbversion"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status"
// +kubebuilder:printcolumn:name="Synced",type="string",JSONPath=".status.conditions[?(@.type==\"Synced\")].status"
// +kubebuilder:printcolumn:name="Status",type="string",priority=1,JSONPath=".status.conditions[?(@.type==\"Ready\")].message"
// +kubebuilder:printcolumn:name="Age",type="date",priority=1,JSONPath=`.metadata.creationTimestamp`
// +kubebuilder:printcolumn:name="MigrationState",type="string",priority=1,JSONPath=".status.migrationState"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ spec:
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- jsonPath: .status.conditions[?(@.type=="Synced")].status
name: Synced
type: string
- jsonPath: .status.conditions[?(@.type=="Ready")].message
name: Status
priority: 1
Expand Down
Loading
Loading