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

replication: move conditions to api #650

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
37 changes: 37 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,43 @@ 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"
)

// 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"
)

// ReplicationState represents the replication operations to be performed on the volume.
// +kubebuilder:validation:Enum=primary;secondary;resync
type ReplicationState string
Expand Down
101 changes: 41 additions & 60 deletions internal/controller/replication.storage/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,27 @@ package controller
import (
"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"
)

const (
Success = "Success"
Promoted = "Promoted"
Demoted = "Demoted"
FailedToPromote = "FailedToPromote"
FailedToDemote = "FailedToDemote"
Error = "Error"
VolumeDegraded = "VolumeDegraded"
Healthy = "Healthy"
ResyncTriggered = "ResyncTriggered"
FailedToResync = "FailedToResync"
NotResyncing = "NotResyncing"
)

// sets conditions when volume was promoted successfully.
func setPromotedCondition(conditions *[]metav1.Condition, observedGeneration int64) {
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionCompleted,
Reason: Promoted,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Promoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Healthy,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Healthy,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: NotResyncing,
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
Expand All @@ -67,20 +48,20 @@ func setPromotedCondition(conditions *[]metav1.Condition, observedGeneration int
// sets conditions when volume promotion was failed.
func setFailedPromotionCondition(conditions *[]metav1.Condition, observedGeneration int64) {
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionCompleted,
Reason: FailedToPromote,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToPromote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Error,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: NotResyncing,
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
Expand All @@ -89,14 +70,14 @@ func setFailedPromotionCondition(conditions *[]metav1.Condition, observedGenerat
// sets conditions when volume is demoted and ready to use (resync completed).
func setNotDegradedCondition(conditions *[]metav1.Condition, observedGeneration int64) {
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Healthy,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Healthy,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: NotResyncing,
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
Expand All @@ -105,20 +86,20 @@ func setNotDegradedCondition(conditions *[]metav1.Condition, observedGeneration
// sets conditions when volume was demoted successfully.
func setDemotedCondition(conditions *[]metav1.Condition, observedGeneration int64) {
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionCompleted,
Reason: Demoted,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Demoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: VolumeDegraded,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.VolumeDegraded,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: NotResyncing,
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
Expand All @@ -127,20 +108,20 @@ func setDemotedCondition(conditions *[]metav1.Condition, observedGeneration int6
// sets conditions when volume demotion was failed.
func setFailedDemotionCondition(conditions *[]metav1.Condition, observedGeneration int64) {
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionCompleted,
Reason: FailedToDemote,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToDemote,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Error,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: NotResyncing,
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.NotResyncing,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
Expand All @@ -149,20 +130,20 @@ func setFailedDemotionCondition(conditions *[]metav1.Condition, observedGenerati
// sets conditions when volume resync was triggered successfully.
func setResyncCondition(conditions *[]metav1.Condition, observedGeneration int64) {
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionCompleted,
Reason: Demoted,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.Demoted,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: VolumeDegraded,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.VolumeDegraded,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: ResyncTriggered,
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.ResyncTriggered,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
Expand All @@ -171,20 +152,20 @@ func setResyncCondition(conditions *[]metav1.Condition, observedGeneration int64
// sets conditions when volume resync failed.
func setFailedResyncCondition(conditions *[]metav1.Condition, observedGeneration int64) {
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionCompleted,
Reason: FailedToResync,
Type: v1alpha1.ConditionCompleted,
Reason: v1alpha1.FailedToResync,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionDegraded,
Reason: Error,
Type: v1alpha1.ConditionDegraded,
Reason: v1alpha1.Error,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionTrue,
})
setStatusCondition(conditions, &metav1.Condition{
Type: ConditionResyncing,
Reason: FailedToResync,
Type: v1alpha1.ConditionResyncing,
Reason: v1alpha1.FailedToResync,
ObservedGeneration: observedGeneration,
Status: metav1.ConditionFalse,
})
Expand Down
Loading