-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Conversation
pkg/databaseclaim/claimstatus.go
Outdated
// reflect the error that occurred. It returns the error that | ||
// should be returned by the Reconcile function. | ||
func manageError(ctx context.Context, cli client.Client, claim *v1.DatabaseClaim, inErr error) (ctrl.Result, error) { | ||
func (m *StatusManager) SetErrorStatus(ctx context.Context, dbClaim *v1.DatabaseClaim, inErr error) (reconcile.Result, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change the method name to SetError since the struct already has the Status (StatusManager).
m.SetStatusCondition(ctx, dbClaim, ReconcileErrorCondition(inErr)) | ||
var wrappedErr *managedErr | ||
if existingErr, isManaged := inErr.(*managedErr); isManaged { | ||
logr.Error(existingErr, "manageError called multiple times for the same error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point, this could be promoted to a panic. So we can identify and fix the duplidate error calls happening
pkg/databaseclaim/claimstatus.go
Outdated
//if object is getting deleted then call requeue immediately | ||
if !dbClaim.ObjectMeta.DeletionTimestamp.IsZero() { | ||
return ctrl.Result{Requeue: true}, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you check for deleted state before updating the status?
I think you could move claimstatus out of the pkg/databaseclaim package. |
pkg/databaseclaim/condition.go
Outdated
ConditionReady ConditionType = "Ready" | ||
ConditionProvisioning ConditionType = "Provisioning" | ||
ConditionDeleting ConditionType = "Deleting" | ||
ConditionMigrating ConditionType = "Migrating" | ||
PasswordRotation ConditionType = "PasswordRotation" | ||
ConditionConnectionIssue ConditionType = "ConnectionFailed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would collapse these to something similiar to Crossplane ConditionReady
, ConditionSync
. All of these other condition states could be part of those 2.
ConditionSync would indicate if db-controller is performing any operation provisioning, deleting, migrating. It is True when all state is synced to Crossplane/AWS (requires checking Crossplane CR status). I would also consider that implicit versioning errors in the sync field as NeedsMigrate
. That may require a separate ticket and be out of scope for this one.
Ready indicates the database is not just synced but available for user. User credentials are created and within rotation period. If credentials are expired, then ready should be false.
Status | ConditionReady | ConditionSync |
---|---|---|
Ready | True | True |
Provisioning | True | False |
Deleting | True | False |
Migrating | True | False |
ConnectionIssue | False | True |
} | ||
|
||
func (m *StatusManager) SetStatusCondition(ctx context.Context, dbClaim *v1.DatabaseClaim, condition metav1.Condition) { | ||
logf := log.FromContext(ctx).WithValues("databaseclaim", dbClaim.Name) | ||
|
||
condition.LastTransitionTime = metav1.Now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LastTransitionTime
is set already when you create the condition:
db-controller/api/v1/condition.go
Lines 42 to 51 in 76cf740
func CreateCondition(condType ConditionType, status metav1.ConditionStatus, reason, message string) metav1.Condition { | |
now := metav1.NewTime(time.Now()) | |
return metav1.Condition{ | |
Type: string(condType), | |
Status: status, | |
Reason: reason, | |
Message: message, | |
LastTransitionTime: now, | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed from the create condition as it makes more sense to keep it here, closer to the update operation.
Summary of changes
DatabaseClaimStatus
condition list by adding more conditions.Demo
DB claim