Skip to content

Commit 0f99e86

Browse files
author
Peng Zhou
committed
tidy code
1 parent f15942a commit 0f99e86

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

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

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

0 commit comments

Comments
 (0)