Skip to content
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

DFBUGS-850: Reflect cephrbd image health in VR and VRG status #236

Open
wants to merge 3 commits into
base: release-4.17
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions api/replication.storage/v1alpha1/volumereplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,70 @@ const (
VolumeReplicationNameAnnotation = "replication.storage.openshift.io/volume-replication-name"
)

// These are valid condition statuses.
// "ConditionCompleted" means the condition is fulfilled.
// "ConditionDegraded" means the condition is not fulfilled.
// "ConditionResyncing" means the condition is resyncing.
const (
ConditionCompleted = "Completed"
ConditionDegraded = "Degraded"
ConditionResyncing = "Resyncing"
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 (
// Success condition represents the successful completion of the operation.
Success = "Success"
// Promoted condition represents the successful promotion of the volume.
Promoted = "Promoted"
// Demoted condition represents the successful demotion of the volume.
Demoted = "Demoted"
// FailedToPromote condition represents the failure to promote the volume.
FailedToPromote = "FailedToPromote"
// FailedToDemote condition represents the failure to demote the volume.
FailedToDemote = "FailedToDemote"
// Error condition represents the error in the operation.
Error = "Error"
// VolumeDegraded condition represents the volume is degraded.
VolumeDegraded = "VolumeDegraded"
// Healthy condition represents the volume is healthy.
Healthy = "Healthy"
// ResyncTriggered condition represents the resync operation is triggered.
ResyncTriggered = "ResyncTriggered"
// FailedToResync condition represents the failure to resync the volume.
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.
// +kubebuilder:validation:Enum=primary;secondary;resync
type ReplicationState string
Expand Down
185 changes: 103 additions & 82 deletions internal/controller/replication.storage/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,213 +17,233 @@ 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"
)

const (
ConditionCompleted = "Completed"
ConditionDegraded = "Degraded"
ConditionResyncing = "Resyncing"
ConditionValidated = "Validated"
)

const (
Success = "Success"
Promoted = "Promoted"
Demoted = "Demoted"
FailedToPromote = "FailedToPromote"
FailedToDemote = "FailedToDemote"
Error = "Error"
VolumeDegraded = "VolumeDegraded"
Healthy = "Healthy"
ResyncTriggered = "ResyncTriggered"
FailedToResync = "FailedToResync"
NotResyncing = "NotResyncing"
// PrerequisiteMet condition represents that the prerequisite is met.
PrerequisiteMet = "PrerequisiteMet"
// PrerequisiteNotMet condition represents that the prerequisite is not met.
PrerequisiteNotMet = "PrerequisiteNotMet"
)
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{
Type: ConditionCompleted,
Reason: Promoted,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessagePromoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Promoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Healthy,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageHealthy),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Healthy,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: NotResyncing,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
}

// 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{
Type: ConditionCompleted,
Reason: FailedToPromote,
Message: completedMessage,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToPromote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Error,
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{
Type: ConditionResyncing,
Reason: NotResyncing,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionValidated,
Reason: PrerequisiteMet,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageValidated),
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) {
func setFailedValidationCondition(conditions *[]metav1.Condition, observedGeneration int64, dataSource, degradedMessage, validationDetailedMessage string) {
source := getSource(dataSource)
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionCompleted,
Reason: FailedToPromote,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageFailedPromoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToPromote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Error,
Message: degradedMessage,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: NotResyncing,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionValidated,
Reason: PrerequisiteNotMet,
Message: fmt.Sprintf("%s: %s", v1alpha1.MessageFailedPreCondition, validationDetailedMessage),
Type: v1alpha1.ConditionValidated,
Reason: v1alpha1.PrerequisiteNotMet,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
}

// 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{
Type: ConditionDegraded,
Reason: Healthy,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDemoted),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Healthy,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: NotResyncing,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
}

// 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{
Type: ConditionCompleted,
Reason: Demoted,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDemoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Demoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: VolumeDegraded,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDegraded),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.VolumeDegraded,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: NotResyncing,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
}

// 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{
Type: ConditionCompleted,
Reason: FailedToDemote,
Message: completedMessage,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToDemote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Error,
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{
Type: ConditionResyncing,
Reason: NotResyncing,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
}

// 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{
Type: ConditionCompleted,
Reason: Demoted,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDemoted),
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Demoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: VolumeDegraded,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageDegraded),
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.VolumeDegraded,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: ResyncTriggered,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageResyncTriggered),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.ResyncTriggered,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
}

// 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{
Type: ConditionCompleted,
Reason: FailedToResync,
Message: completedMessage,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToResync,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Error,
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{
Type: ConditionResyncing,
Reason: FailedToResync,
Message: fmt.Sprintf("%s %s", source, v1alpha1.MessageNotResyncing),
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.FailedToResync,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
Expand All @@ -247,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
Loading