From 3296fc64a97d5c8842949913c3c223178cc26948 Mon Sep 17 00:00:00 2001 From: Nizamudeen Date: Wed, 4 Mar 2020 18:57:07 +0530 Subject: [PATCH] ceph: Follow up for adding the state variable Changed back the status.State to the exact way it was implemented on the ceph cluster. Added the States as a Constant and used that constant to call the status.State. Signed-off-by: Nizamudeen --- pkg/apis/ceph.rook.io/v1/types.go | 13 +++++++++- pkg/operator/ceph/config/conditions.go | 34 +++++++++++++++----------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go index 0ebc8470f71e..a0f3d194a4b3 100755 --- a/pkg/apis/ceph.rook.io/v1/types.go +++ b/pkg/apis/ceph.rook.io/v1/types.go @@ -142,7 +142,7 @@ type MonitoringSpec struct { } type ClusterStatus struct { - State string `json:"state,omitempty"` + State ClusterState `json:"state,omitempty"` Phase ConditionType `json:"phase,omitempty"` Message string `json:"message,omitempty"` Conditions []Condition `json:"conditions,omitempty"` @@ -193,6 +193,17 @@ const ( DefaultFailureDomain = "host" ) +type ClusterState string + +const ( + ClusterStateCreating ClusterState = "Creating" + ClusterStateCreated ClusterState = "Created" + ClusterStateUpdating ClusterState = "Updating" + ClusterStateConnecting ClusterState = "Connecting" + ClusterStateConnected ClusterState = "Connected" + ClusterStateError ClusterState = "Error" +) + type MonSpec struct { Count int `json:"count,omitempty"` AllowMultiplePerNode bool `json:"allowMultiplePerNode,omitempty"` diff --git a/pkg/operator/ceph/config/conditions.go b/pkg/operator/ceph/config/conditions.go index c817727a9b08..f5c682296d57 100644 --- a/pkg/operator/ceph/config/conditions.go +++ b/pkg/operator/ceph/config/conditions.go @@ -94,21 +94,27 @@ func setCondition(context *clusterd.Context, namespace, name string, newConditio // 2. We can't change the enum values of the State since that is also // a breaking change. Therefore, we translate new phases to the original // State values -func translatePhasetoState(phase cephv1.ConditionType) string { - if phase == cephv1.ConditionProgressing { - return "Creating" - } else if phase == cephv1.ConditionReady { - return "Created" - } else if phase == cephv1.ConditionUpgrading || phase == cephv1.ConditionUpdating { - return "Updating" - } else if phase == cephv1.ConditionFailure || phase == cephv1.ConditionIgnored { - return "Error" - } else if phase == cephv1.ConditionConnected { - return "Connected" - } else if phase == cephv1.ConditionConnecting { - return "Connecting" +func translatePhasetoState(phase cephv1.ConditionType) cephv1.ClusterState { + switch phase { + case cephv1.ConditionConnecting: + return cephv1.ClusterStateConnecting + case cephv1.ConditionConnected: + return cephv1.ClusterStateConnected + case cephv1.ConditionFailure: + return cephv1.ClusterStateError + case cephv1.ConditionIgnored: + return cephv1.ClusterStateError + case cephv1.ConditionProgressing: + return cephv1.ClusterStateCreating + case cephv1.ConditionReady: + return cephv1.ClusterStateCreated + case cephv1.ConditionUpgrading: + return cephv1.ClusterStateUpdating + case cephv1.ConditionUpdating: + return cephv1.ClusterStateUpdating + default: + return "" } - return "" } // Updating the status of Progressing, Updating or Upgrading to False once cluster is Ready