Skip to content

Commit f4f12f1

Browse files
committed
Fix the clusterstatus based on last operatorAction
1 parent fe6b18c commit f4f12f1

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

.bazelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
build --workspace_status_command hack/build/print-workspace-status.sh
2-
test --test_output=errors --test_timeout=-1,-1,-1,2400
2+
test --test_output=all --test_timeout=-1,-1,-1,3600

pkg/actor/validate_version.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,15 @@ func (v *versionChecker) Act(ctx context.Context, cluster *resource.Cluster, log
184184
}
185185
return errors.Wrapf(err, "failed to check the version of the crdb")
186186
}
187+
188+
// Tail only last two lines as one line contains version info and one line has newline character. It is much faster.
189+
podLines := int64(2)
187190
podLogOpts := corev1.PodLogOptions{
188191
Container: resource.JobContainerName,
192+
TailLines: &podLines,
189193
}
190-
//get pod for the job we created
191194

195+
//get pod for the job we created
192196
pods, err := v.clientset.CoreV1().Pods(job.Namespace).List(ctx, metav1.ListOptions{
193197
LabelSelector: labels.Set(job.Spec.Selector.MatchLabels).AsSelector().String(),
194198
})
@@ -231,11 +235,12 @@ func (v *versionChecker) Act(ctx context.Context, cluster *resource.Cluster, log
231235
}
232236
output := buf.String()
233237

238+
log.Info("Logs of version checker pod", "log", output)
234239
// This is the value from Build Tag taken from the container
235240
calVersion = strings.Replace(output, "\n", "", -1)
236-
// if no image is retrieved we exit
241+
// if no logs are found we will retry later to fetch the logs
237242
if calVersion == "" {
238-
err := PermanentErr{Err: errors.New("failed to check the version of the cluster")}
243+
err := NotReadyErr{Err: errors.New("failed to check the version of the cluster")}
239244
log.Error(err, "crdb version not found")
240245
return err
241246
}

pkg/clusterstatus/clusterstatus.go

+9-15
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,19 @@ func SetClusterStatusOnFirstReconcile(status *api.CrdbClusterStatus) {
3131
status.ClusterStatus = api.ActionStatus(api.Starting).String()
3232
}
3333

34-
// TODO: Do we need to check for all OperatorActions or for just the 0th element in SetClusterStatus func
35-
// nolint
34+
// SetClusterStatus will set the status of the cluster based on the status of the operator actions
35+
// operatorActions are not always appended, rather any particular action type is replaced if its status changes.
36+
// The status of the cluster is set to the status of the last operator action based on lastTransitionTime.
3637
func SetClusterStatus(status *api.CrdbClusterStatus) {
3738
InitOperatorActionsIfNeeded(status, metav1.Now())
38-
for _, a := range status.OperatorActions {
39-
if a.Status == api.ActionStatus(api.Failed).String() {
40-
status.ClusterStatus = api.ActionStatus(api.Failed).String()
41-
return
39+
for i := range status.OperatorActions {
40+
if i == 0 || status.OperatorActions[i-1].LastTransitionTime.Before(&status.OperatorActions[i].LastTransitionTime) {
41+
status.ClusterStatus = status.OperatorActions[i].Status
4242
}
43-
44-
if a.Status == api.ActionStatus(api.Unknown).String() {
45-
status.ClusterStatus = api.ActionStatus(api.Unknown).String()
46-
return
47-
}
48-
49-
status.ClusterStatus = api.ActionStatus(api.Finished).String()
50-
return
5143
}
52-
status.ClusterStatus = api.ActionStatus(api.Finished).String()
44+
if status.ClusterStatus == "" {
45+
status.ClusterStatus = api.ActionStatus(api.Starting).String()
46+
}
5347
}
5448

5549
func InitOperatorActionsIfNeeded(status *api.CrdbClusterStatus, now metav1.Time) {

0 commit comments

Comments
 (0)