Skip to content

Commit c9cf1d3

Browse files
author
Peng Zhou
committed
tidy code
1 parent 8f9c974 commit c9cf1d3

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

pkg/k8sutil/statefulset.go

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -89,40 +89,40 @@ func (oc *OperatorContext) ReconcileStatefulset() (reconcile.Result, error) {
8989
logger.Error(err, "Cannot create standalone statefulSet for MarkLogic")
9090
return result.Error(err).Output()
9191
}
92-
// patchClient := client.MergeFrom(oc.MarklogicGroup.DeepCopy())
93-
// updated := false
94-
// if currentSts.Status.ReadyReplicas == 0 || currentSts.Status.ReadyReplicas != currentSts.Status.Replicas {
95-
// logger.Info("MarkLogic statefulSet is not ready, setting condition and requeue")
96-
// condition := metav1.Condition{
97-
// Type: "Ready",
98-
// Status: metav1.ConditionFalse,
99-
// Reason: "MarkLogicGroupStatefulSetNotReady",
100-
// Message: "MarkLogicGroup statefulSet is not ready",
101-
// }
102-
// updated = oc.setCondition(&condition)
103-
// if updated {
104-
// err := oc.Client.Status().Patch(oc.Ctx, oc.MarklogicGroup, patchClient)
105-
// if err != nil {
106-
// oc.ReqLogger.Error(err, "error updating the MarkLogic Operator Internal status")
107-
// }
108-
// }
109-
// return result.Done().Output()
110-
// } else {
111-
// logger.Info("MarkLogic statefulSet is ready, setting condition")
112-
// condition := metav1.Condition{
113-
// Type: "Ready",
114-
// Status: metav1.ConditionTrue,
115-
// Reason: "MarkLogicGroupStatefulSetReady",
116-
// Message: "MarkLogicGroup statefulSet is ready",
117-
// }
118-
// updated = oc.setCondition(&condition)
119-
// }
120-
// if updated {
121-
// err := oc.Client.Status().Patch(oc.Ctx, oc.MarklogicGroup, patchClient)
122-
// if err != nil {
123-
// oc.ReqLogger.Error(err, "error updating the MarkLogic Operator Internal status")
124-
// }
125-
// }
92+
patchClient := client.MergeFrom(oc.MarklogicGroup.DeepCopy())
93+
updated := false
94+
if currentSts.Status.ReadyReplicas == 0 || currentSts.Status.ReadyReplicas != currentSts.Status.Replicas {
95+
logger.Info("MarkLogic statefulSet is not ready, setting condition and requeue")
96+
condition := metav1.Condition{
97+
Type: "Ready",
98+
Status: metav1.ConditionFalse,
99+
Reason: "MarkLogicGroupStatefulSetNotReady",
100+
Message: "MarkLogicGroup statefulSet is not ready",
101+
}
102+
updated = oc.setCondition(&condition)
103+
if updated {
104+
err := oc.Client.Status().Patch(oc.Ctx, oc.MarklogicGroup, patchClient)
105+
if err != nil {
106+
oc.ReqLogger.Error(err, "error updating the MarkLogic Operator Internal status")
107+
}
108+
}
109+
return result.Done().Output()
110+
} else {
111+
logger.Info("MarkLogic statefulSet is ready, setting condition")
112+
condition := metav1.Condition{
113+
Type: "Ready",
114+
Status: metav1.ConditionTrue,
115+
Reason: "MarkLogicGroupStatefulSetReady",
116+
Message: "MarkLogicGroup statefulSet is ready",
117+
}
118+
updated = oc.setCondition(&condition)
119+
}
120+
if updated {
121+
err := oc.Client.Status().Patch(oc.Ctx, oc.MarklogicGroup, patchClient)
122+
if err != nil {
123+
oc.ReqLogger.Error(err, "error updating the MarkLogic Operator Internal status")
124+
}
125+
}
126126

127127
patchDiff, err := patch.DefaultPatchMaker.Calculate(currentSts, statefulSetDef,
128128
patch.IgnoreStatusFields(),
@@ -145,15 +145,15 @@ func (oc *OperatorContext) ReconcileStatefulset() (reconcile.Result, error) {
145145
} else {
146146
logger.Info("MarkLogic statefulSet spec is the same as the current spec, no update needed")
147147
}
148-
// logger.Info("Operator Status:", "Stage", cr.Status.Stage)
149-
// if cr.Status.Stage == "STS_CREATED" {
150-
// logger.Info("MarkLogic statefulSet created successfully, waiting for pods to be ready")
151-
// pods, err := GetPodsForStatefulSet(cr.Namespace, cr.Spec.Name)
152-
// if err != nil {
153-
// logger.Error(err, "Error getting pods for statefulset")
154-
// }
155-
// logger.Info("Pods in statefulSet: ", "Pods", pods)
156-
// }
148+
logger.Info("Operator Status:", "Stage", cr.Status.Stage)
149+
if cr.Status.Stage == "STS_CREATED" {
150+
logger.Info("MarkLogic statefulSet created successfully, waiting for pods to be ready")
151+
pods, err := GetPodsForStatefulSet(cr.Namespace, cr.Spec.Name)
152+
if err != nil {
153+
logger.Error(err, "Error getting pods for statefulset")
154+
}
155+
logger.Info("Pods in statefulSet: ", "Pods", pods)
156+
}
157157

158158
return result.Done().Output()
159159
}

0 commit comments

Comments
 (0)