Skip to content

Commit

Permalink
update the volumereplication condition
Browse files Browse the repository at this point in the history
this commit updates the volumereplication conditions to
include descriptive message for every
operations

Signed-off-by: yati1998 <[email protected]>
  • Loading branch information
yati1998 committed Nov 7, 2024
1 parent ed2c2a5 commit 4d2c3f7
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 30 deletions.
22 changes: 22 additions & 0 deletions api/replication.storage/v1alpha1/volumereplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ const (
ConditionValidated = "Validated"
)

// These are valid messages for various conditions and states of volume replication.
const (
MessagePromoted = "is promoted to primary and replicating to secondary"
MessageHealthy = "is healthy"
MessageNotResyncing = "is not resyncing"
MessageValidated = "is validated and met all prerequisites"
MessageFailedPromoted = "failed to promote"
MessageFailedDemoted = "failed to demote"
MessageFailedPreCondition = "failed to meet prerequisite"
MessageDemoted = "is demoted to secondary"
MessageDegraded = "is degraded"
MessageResyncTriggered = "is resyncing changes from primary to secondary"
MessageResyncFailed = "failed to resync"
)

type Source string

const (
Volume Source = "volume"
VolumeGroup Source = "volume group"
)

// These are valid conditions.

const (
Expand Down
61 changes: 53 additions & 8 deletions internal/controller/replication.storage/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,42 @@ limitations under the License.
package controller

import (
"fmt"
"time"

"github.com/csi-addons/kubernetes-csi-addons/api/replication.storage/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func getSource(dataSource string) v1alpha1.Source {
if dataSource == pvcDataSource {
return v1alpha1.Volume
} else if dataSource == volumeGroupReplicationDataSource {
return v1alpha1.VolumeGroup
} else {
return ""
}
}

// sets conditions when volume was promoted successfully.
func setPromotedCondition(conditions *[]metav1.Condition, observedGeneration int64) {
func setPromotedCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource string) {
source := getSource(dataSource)
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessagePromoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Promoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageHealthy),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Healthy,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Expand All @@ -46,26 +61,31 @@ func setPromotedCondition(conditions *[]metav1.Condition, observedGeneration int
}

// sets conditions when volume promotion was failed.
func setFailedPromotionCondition(conditions *[]metav1.Condition, observedGeneration int64) {
func setFailedPromotionCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource, completedMessage, degradedDetailedMessage string) {
source := getSource(dataSource)
setStatusCondition(conditions, &metav1.Condition{
Message: completedMessage,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToPromote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s: %s", source, v1alpha1.MessageFailedPromoted, degradedDetailedMessage),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageValidated),
Type: v1alpha1.ConditionValidated,
Reason: v1alpha1.PrerequisiteMet,
ObservedGeneration: observedGeneration,
Expand All @@ -74,26 +94,31 @@ func setFailedPromotionCondition(conditions *[]metav1.Condition, observedGenerat
}

// sets conditions when volume promotion was failed due to failed validation.
func setFailedValidationCondition(conditions *[]metav1.Condition, observedGeneration int64) {
func setFailedValidationCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource, degradedMessage, validationDetailedMessage string) {
source := getSource(dataSource)
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageFailedPromoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToPromote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: degradedMessage,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s: %s", v1alpha1.MessageFailedPreCondition, validationDetailedMessage),
Type: v1alpha1.ConditionValidated,
Reason: v1alpha1.PrerequisiteNotMet,
ObservedGeneration: observedGeneration,
Expand All @@ -102,14 +127,17 @@ func setFailedValidationCondition(conditions *[]metav1.Condition, observedGenera
}

// sets conditions when volume is demoted and ready to use (resync completed).
func setNotDegradedCondition(conditions *[]metav1.Condition, observedGeneration int64) {
func setNotDegradedCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource string) {
source := getSource(dataSource)
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDemoted),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Healthy,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Expand All @@ -118,20 +146,24 @@ func setNotDegradedCondition(conditions *[]metav1.Condition, observedGeneration
}

// sets conditions when volume was demoted successfully.
func setDemotedCondition(conditions *[]metav1.Condition, observedGeneration int64) {
func setDemotedCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource string) {
source := getSource(dataSource)
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDemoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Demoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDegraded),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.VolumeDegraded,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Expand All @@ -140,20 +172,24 @@ func setDemotedCondition(conditions *[]metav1.Condition, observedGeneration int6
}

// sets conditions when volume demotion was failed.
func setFailedDemotionCondition(conditions *[]metav1.Condition, observedGeneration int64) {
func setFailedDemotionCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource, completedMessage, degradedDetailedMessage string) {
source := getSource(dataSource)
setStatusCondition(conditions, &metav1.Condition{
Message: completedMessage,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToDemote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s: %s", source, v1alpha1.MessageFailedDemoted, degradedDetailedMessage),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Expand All @@ -162,20 +198,24 @@ func setFailedDemotionCondition(conditions *[]metav1.Condition, observedGenerati
}

// sets conditions when volume resync was triggered successfully.
func setResyncCondition(conditions *[]metav1.Condition, observedGeneration int64) {
func setResyncCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource string) {
source := getSource(dataSource)
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDemoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Demoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDegraded),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.VolumeDegraded,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageResyncTriggered),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.ResyncTriggered,
ObservedGeneration: observedGeneration,
Expand All @@ -184,20 +224,24 @@ func setResyncCondition(conditions *[]metav1.Condition, observedGeneration int64
}

// sets conditions when volume resync failed.
func setFailedResyncCondition(conditions *[]metav1.Condition, observedGeneration int64) {
func setFailedResyncCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource, completedMessage, degradedDetailedMessage string) {
source := getSource(dataSource)
setStatusCondition(conditions, &metav1.Condition{
Message: completedMessage,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToResync,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s: %s", source, v1alpha1.MessageResyncFailed, degradedDetailedMessage),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.FailedToResync,
ObservedGeneration: observedGeneration,
Expand All @@ -223,6 +267,7 @@ func setStatusCondition(existingConditions *[]metav1.Condition, newCondition *me
existingCondition.LastTransitionTime = metav1.NewTime(time.Now())
}

existingCondition.Message = newCondition.Message
existingCondition.Reason = newCondition.Reason
existingCondition.ObservedGeneration = newCondition.ObservedGeneration
}
Expand Down
Loading

0 comments on commit 4d2c3f7

Please sign in to comment.