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 6, 2024
1 parent ed2c2a5 commit 9295b11
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 29 deletions.
15 changes: 15 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,21 @@ 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 volume"
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"
)

// These are valid conditions.

const (
Expand Down
43 changes: 35 additions & 8 deletions internal/controller/replication.storage/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,31 @@ 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"
)

// sets conditions when volume was promoted successfully.
func setPromotedCondition(conditions *[]metav1.Condition, observedGeneration int64) {
func setPromotedCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource string) {
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessagePromoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Promoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageHealthy),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Healthy,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Expand All @@ -46,26 +50,30 @@ 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, message, messageFromDriver, dataSource string) {
setStatusCondition(conditions, &metav1.Condition{
Message: message,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToPromote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s: %s", v1alpha1.MessageFailedPromoted, dataSource, messageFromDriver),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageValidated),
Type: v1alpha1.ConditionValidated,
Reason: v1alpha1.PrerequisiteMet,
ObservedGeneration: observedGeneration,
Expand All @@ -74,26 +82,30 @@ 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, message, messageFromDriver, dataSource string) {
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", v1alpha1.MessageFailedPromoted, dataSource),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToPromote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: message,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s: %s", v1alpha1.MessageFailedPreCondition, messageFromDriver),
Type: v1alpha1.ConditionValidated,
Reason: v1alpha1.PrerequisiteNotMet,
ObservedGeneration: observedGeneration,
Expand All @@ -102,14 +114,16 @@ 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) {
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageDemoted),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Healthy,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Expand All @@ -118,20 +132,23 @@ 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) {
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageDemoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Demoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageDegraded),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.VolumeDegraded,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Expand All @@ -140,20 +157,23 @@ 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, message, messageFromDriver, dataSource string) {
setStatusCondition(conditions, &metav1.Condition{
Message: message,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToDemote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s: %s", v1alpha1.MessageFailedDemoted, dataSource, messageFromDriver),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Expand All @@ -162,20 +182,23 @@ 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) {
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageDemoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Demoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageDegraded),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.VolumeDegraded,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageResyncTriggered),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.ResyncTriggered,
ObservedGeneration: observedGeneration,
Expand All @@ -184,20 +207,23 @@ 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, message, messageFromDriver, dataSource string) {
setStatusCondition(conditions, &metav1.Condition{
Message: message,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToResync,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s: %s", v1alpha1.MessageResyncFailed, dataSource, messageFromDriver),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Message: fmt.Sprintf("%s %s", dataSource, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.FailedToResync,
ObservedGeneration: observedGeneration,
Expand All @@ -223,6 +249,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 9295b11

Please sign in to comment.