Skip to content

Commit

Permalink
ready: Do not quit when the target server is offline or any other error
Browse files Browse the repository at this point in the history
Ready makes sense to not quit in any case, until the target server is
fully initialized
  • Loading branch information
Anis Elleuch committed Dec 7, 2023
1 parent d920e2b commit a2eaad2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/vulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21.4
go-version: 1.21.5
check-latest: true
- name: Get official govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest
Expand Down
29 changes: 11 additions & 18 deletions cmd/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ type readyMessage struct {
MaintenanceMode bool `json:"maintenanceMode"`
WriteQuorum int `json:"writeQuorum"`
HealingDrives int `json:"healingDrives"`

Err error `json:"error"`
}

func (r readyMessage) String() string {
if r.Healthy {
switch {
case r.Healthy:
return color.GreenString("The cluster is ready")
case r.Err != nil:
return color.RedString("The cluster is unreachable: " + r.Err.Error())
default:
return color.RedString("The cluster is not ready")
}
return color.RedString("The cluster is not ready")
}

// JSON jsonified ready result
Expand Down Expand Up @@ -116,38 +122,25 @@ func mainReady(cliCtx *cli.Context) error {
Maintenance: maintenance,
}

healthResult, hErr := anonClient.Healthy(ctx, healthOpts)
fatalIf(probe.NewError(hErr).Trace(aliasedURL), "Couldn't get the health status for `"+aliasedURL+"`.")

if healthResult.Healthy {
printMsg(readyMessage{
Healthy: healthResult.Healthy,
MaintenanceMode: healthResult.MaintenanceMode,
WriteQuorum: healthResult.WriteQuorum,
HealingDrives: healthResult.HealingDrives,
})
return nil
}

timer := time.NewTimer(healthCheckInterval)
timer := time.NewTimer(0)
defer timer.Stop()

for {
select {
case <-ctx.Done():
return nil
case <-timer.C:
healthResult, hErr := anonClient.Healthy(ctx, healthOpts)
fatalIf(probe.NewError(hErr).Trace(aliasedURL), "Couldn't get the health status for `"+aliasedURL+"`.")
printMsg(readyMessage{
Healthy: healthResult.Healthy,
MaintenanceMode: healthResult.MaintenanceMode,
WriteQuorum: healthResult.WriteQuorum,
HealingDrives: healthResult.HealingDrives,
Err: hErr,
})
if healthResult.Healthy {
return nil
}

timer.Reset(healthCheckInterval)
}
}
Expand Down

0 comments on commit a2eaad2

Please sign in to comment.