Skip to content

Commit

Permalink
replication: add new FailedPrecondition condition
Browse files Browse the repository at this point in the history
This commit adds new FailedPrecondition condition
to indicate the csi driver responded with
FailedPrecondition grpc code for EnableReplication
request.

Signed-off-by: Rakshith R <[email protected]>
  • Loading branch information
Rakshith-R committed Sep 12, 2024
1 parent bd88536 commit ab2f4c1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
5 changes: 5 additions & 0 deletions api/replication.storage/v1alpha1/volumereplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
ConditionCompleted = "Completed"
ConditionDegraded = "Degraded"
ConditionResyncing = "Resyncing"
ConditionValidated = "Validated"
)

// These are valid conditions.
Expand Down Expand Up @@ -60,6 +61,10 @@ const (
FailedToResync = "FailedToResync"
// NotResyncing condition represents the volume is not resyncing.
NotResyncing = "NotResyncing"
// PrerequisiteMet condition represents that the prerequisite is met.
PrerequisiteMet = "PrerequisiteMet"
// PrerequisiteNotMet condition represents that the prerequisite is not met.
PrerequisiteNotMet = "PrerequisiteNotMet"
)

// ReplicationState represents the replication operations to be performed on the volume.
Expand Down
34 changes: 34 additions & 0 deletions internal/controller/replication.storage/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,40 @@ func setFailedPromotionCondition(conditions *[]metav1.Condition, observedGenerat
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: v1alpha1.ConditionValidated,
Reason: v1alpha1.PrerequisiteMet,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
}

// sets conditions when volume promotion was failed due to failed validation.
func setFailedValidationCondition(conditions *[]metav1.Condition, observedGeneration int64) {
setStatusCondition(conditions, &metav1.Condition{
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToPromote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: v1alpha1.ConditionValidated,
Reason: v1alpha1.PrerequisiteNotMet,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
}

// sets conditions when volume is demoted and ready to use (resync completed).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
var (
volumePromotionKnownErrors = []codes.Code{codes.FailedPrecondition}
disableReplicationKnownErrors = []codes.Code{codes.NotFound}
enableReplicationKnownErrors = []codes.Code{codes.FailedPrecondition}
getReplicationInfoKnownErrors = []codes.Code{codes.NotFound}
)

Expand Down Expand Up @@ -322,7 +323,6 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
// enable replication only if its not primary
if err = r.enableReplication(vr); err != nil {
logger.Error(err, "failed to enable replication")
setFailureCondition(instance)
msg := replication.GetMessageFromError(err)
uErr := r.updateReplicationStatus(instance, logger, getCurrentReplicationState(instance), msg)
if uErr != nil {
Expand Down Expand Up @@ -741,13 +741,19 @@ func (r *VolumeReplicationReconciler) enableReplication(vr *volumeReplicationIns

resp := volumeReplication.Enable()

if resp.Error != nil {
vr.logger.Error(resp.Error, "failed to enable volume replication")
if resp.Error == nil {
return nil
}

return resp.Error
vr.logger.Error(resp.Error, "failed to enable volume replication")

if resp.HasKnownGRPCError(enableReplicationKnownErrors) {
setFailedValidationCondition(&vr.instance.Status.Conditions, vr.instance.Generation)
} else {
setFailedPromotionCondition(&vr.instance.Status.Conditions, vr.instance.Generation)
}

return nil
return resp.Error
}

// getVolumeReplicationInfo gets volume replication info.
Expand Down

0 comments on commit ab2f4c1

Please sign in to comment.