Skip to content

Commit

Permalink
Revert PhaseFromCondition changes
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <[email protected]>
  • Loading branch information
ArnobKumarSaha committed Jul 5, 2024
1 parent f8d22a3 commit f850112
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
25 changes: 13 additions & 12 deletions pkg/phase/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
esapi "kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"
"kubedb.dev/apimachinery/apis/kubedb"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

kmapi "kmodules.xyz/client-go/api/v1"
cutil "kmodules.xyz/client-go/conditions"
Expand Down Expand Up @@ -55,7 +56,7 @@ func DashboardPhaseFromCondition(conditions []kmapi.Condition) esapi.DashboardPh
return esapi.DashboardPhaseNotReady
}

func PhaseFromCondition(conditions []kmapi.Condition) dbapi.DatabasePhase {
func PhaseFromCondition(conditions []kmapi.Condition) olddbapi.DatabasePhase {
// Generally, the conditions should maintain the following chronological order
// For normal restore process:
// ProvisioningStarted --> ReplicaReady --> AcceptingConnection --> DataRestoreStarted --> DataRestored --> Ready --> Provisioned
Expand All @@ -71,26 +72,26 @@ func PhaseFromCondition(conditions []kmapi.Condition) dbapi.DatabasePhase {
// 6. Paused
// 7. HealthCheckPaused

var phase dbapi.DatabasePhase
var phase olddbapi.DatabasePhase

// ================================= Handling "HealthCheckPaused" condition ==========================
// If the condition is present and its "true", then the phase should be "Unknown".
// Skip if the database isn't provisioned yet.
if cutil.IsConditionTrue(conditions, kubedb.DatabaseHealthCheckPaused) {
return dbapi.DatabasePhaseUnknown
return olddbapi.DatabasePhaseUnknown
}

// ================================== Handling "ProvisioningStarted" condition ========================
// If the condition is present and its "true", then the phase should be "Provisioning".
if cutil.IsConditionTrue(conditions, kubedb.DatabaseProvisioningStarted) {
phase = dbapi.DatabasePhaseProvisioning
phase = olddbapi.DatabasePhaseProvisioning
}

// ================================== Handling "Halted" condition =======================================
// The "Halted" condition has higher priority, that's why it is placed at the top.
// If the condition is present and its "true", then the phase should be "Halted".
if cutil.IsConditionTrue(conditions, kubedb.DatabaseHalted) {
return dbapi.DatabasePhaseHalted
return olddbapi.DatabasePhaseHalted
}

// =================================== Handling "DataRestoreStarted" and "DataRestored" conditions ==================================================
Expand All @@ -106,38 +107,38 @@ func PhaseFromCondition(conditions []kmapi.Condition) dbapi.DatabasePhase {
// - Just return "Restoring" in future.
if cutil.HasCondition(conditions, kubedb.DatabaseDataRestored) {
if cutil.IsConditionFalse(conditions, kubedb.DatabaseDataRestored) {
return dbapi.DatabasePhaseNotReady
return olddbapi.DatabasePhaseNotReady
}
} else {
return dbapi.DatabasePhaseDataRestoring
return olddbapi.DatabasePhaseDataRestoring
}
}
if cutil.IsConditionFalse(conditions, kubedb.DatabaseDataRestored) {
return dbapi.DatabasePhaseNotReady
return olddbapi.DatabasePhaseNotReady
}

// ================================= Handling "AcceptingConnection" condition ==========================
// If the condition is present and its "false", then the phase should be "NotReady".
// Skip if the database isn't provisioned yet.
if cutil.IsConditionFalse(conditions, kubedb.DatabaseAcceptingConnection) && cutil.IsConditionTrue(conditions, kubedb.DatabaseProvisioned) {
return dbapi.DatabasePhaseNotReady
return olddbapi.DatabasePhaseNotReady
}

// ================================= Handling "ReplicaReady" condition ==========================
// If the condition is present and its "false", then the phase should be "Critical".
// Skip if the database isn't provisioned yet.
if cutil.IsConditionFalse(conditions, kubedb.DatabaseReplicaReady) && cutil.IsConditionTrue(conditions, kubedb.DatabaseProvisioned) {
return dbapi.DatabasePhaseCritical
return olddbapi.DatabasePhaseCritical
}

// ================================= Handling "Ready" condition ==========================
// Skip if the database isn't provisioned yet.
if cutil.IsConditionFalse(conditions, kubedb.DatabaseReady) && cutil.IsConditionTrue(conditions, kubedb.DatabaseProvisioned) {
return dbapi.DatabasePhaseCritical
return olddbapi.DatabasePhaseCritical
}
// Ready, if the database is provisioned and readinessProbe passed.
if cutil.IsConditionTrue(conditions, kubedb.DatabaseReady) && cutil.IsConditionTrue(conditions, kubedb.DatabaseProvisioned) {
return dbapi.DatabasePhaseReady
return olddbapi.DatabasePhaseReady
}

// ================================= Handling "Provisioned" and "Paused" conditions ==========================
Expand Down
28 changes: 14 additions & 14 deletions pkg/phase/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"kubedb.dev/apimachinery/apis/kubedb"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kmapi "kmodules.xyz/client-go/api/v1"
Expand All @@ -36,7 +36,7 @@ func TestPhaseForCondition(t *testing.T) {
testCases := []struct {
name string
conditions []kmapi.Condition
expectedPhase dbapi.DatabasePhase
expectedPhase olddbapi.DatabasePhase
}{
{
name: "No condition present yet",
Expand All @@ -51,7 +51,7 @@ func TestPhaseForCondition(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
expectedPhase: dbapi.DatabasePhaseProvisioning,
expectedPhase: olddbapi.DatabasePhaseProvisioning,
},
{
name: "Some replicas are not ready",
Expand All @@ -65,7 +65,7 @@ func TestPhaseForCondition(t *testing.T) {
Status: metav1.ConditionFalse,
},
},
expectedPhase: dbapi.DatabasePhaseProvisioning,
expectedPhase: olddbapi.DatabasePhaseProvisioning,
},
{
name: "All replicas are ready but no other conditions present yet",
Expand All @@ -79,7 +79,7 @@ func TestPhaseForCondition(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
expectedPhase: dbapi.DatabasePhaseProvisioning,
expectedPhase: olddbapi.DatabasePhaseProvisioning,
},
{
name: "Database is not accepting connection",
Expand All @@ -101,7 +101,7 @@ func TestPhaseForCondition(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
expectedPhase: dbapi.DatabasePhaseNotReady,
expectedPhase: olddbapi.DatabasePhaseNotReady,
},
{
name: "Database is accepting connection",
Expand All @@ -119,7 +119,7 @@ func TestPhaseForCondition(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
expectedPhase: dbapi.DatabasePhaseProvisioning,
expectedPhase: olddbapi.DatabasePhaseProvisioning,
},
{
name: "1st restore: didn't completed yet",
Expand All @@ -142,7 +142,7 @@ func TestPhaseForCondition(t *testing.T) {
LastTransitionTime: lastTransactionTime,
},
},
expectedPhase: dbapi.DatabasePhaseDataRestoring,
expectedPhase: olddbapi.DatabasePhaseDataRestoring,
},
{
name: "1st restore: completed successfully",
Expand All @@ -165,7 +165,7 @@ func TestPhaseForCondition(t *testing.T) {
LastTransitionTime: lastTransactionTimePlusOne,
},
},
expectedPhase: dbapi.DatabasePhaseProvisioning,
expectedPhase: olddbapi.DatabasePhaseProvisioning,
},
{
name: "1st restore: failed to complete",
Expand All @@ -188,7 +188,7 @@ func TestPhaseForCondition(t *testing.T) {
LastTransitionTime: lastTransactionTimePlusOne,
},
},
expectedPhase: dbapi.DatabasePhaseNotReady,
expectedPhase: olddbapi.DatabasePhaseNotReady,
},
{
name: "Database is not ready",
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestPhaseForCondition(t *testing.T) {
Status: metav1.ConditionFalse,
},
},
expectedPhase: dbapi.DatabasePhaseCritical,
expectedPhase: olddbapi.DatabasePhaseCritical,
},
{
name: "Database is ready",
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestPhaseForCondition(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
expectedPhase: dbapi.DatabasePhaseReady,
expectedPhase: olddbapi.DatabasePhaseReady,
},
{
name: "Database is ready but not accepting connection",
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestPhaseForCondition(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
expectedPhase: dbapi.DatabasePhaseNotReady,
expectedPhase: olddbapi.DatabasePhaseNotReady,
},
{
name: "With conditions that does not have effect on phase",
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestPhaseForCondition(t *testing.T) {
Status: metav1.ConditionTrue,
},
},
expectedPhase: dbapi.DatabasePhaseReady,
expectedPhase: olddbapi.DatabasePhaseReady,
},
}
for _, tc := range testCases {
Expand Down

0 comments on commit f850112

Please sign in to comment.