-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PTEUDO-1422: Publish status events for state changes in database (#377)
* PTEUDO-1422: refactor claim status to add conditions * PTEUDO-1422: add wip * PTEUDO-1422: refactor claim status and conditions * fix post migration error handling * fix panic log condition * PTEUDO-1422: rename condition type * PTEUDO-1422: rename func * PTEUDO-1422: keep only two condition status * PTEUDO-1422: fix new db status * PTEUDO-1422: remove timestamp from create condition * PTEUDO-1422: add sync to db claim crd
- Loading branch information
Showing
7 changed files
with
731 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.