Skip to content

Commit

Permalink
neofs-cli: Add exit codes to healthchecks
Browse files Browse the repository at this point in the history
It was denied in #654 but is useful in general and for docker healthcheck in
particular.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Jul 19, 2023
1 parent ffbbac4 commit 2cb41e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Subnets support has been removed:

Docker images now contain a single executable file and SSL certificates only.

`neofs-cli control healthcheck` exit code is `0` only for "READY" state.

## [0.37.0] - 2023-06-15 - Sogado

### Added
Expand Down
17 changes: 15 additions & 2 deletions cmd/neofs-cli/modules/control/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package control

import (
"crypto/ecdsa"
"os"

rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
Expand Down Expand Up @@ -60,8 +61,14 @@ func healthCheck(cmd *cobra.Command, _ []string) {

verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

healthStatus := resp.GetBody().GetHealthStatus()

cmd.Printf("Network status: %s\n", resp.GetBody().GetNetmapStatus())
cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus())
cmd.Printf("Health status: %s\n", healthStatus)

if healthStatus != control.HealthStatus_READY {
os.Exit(1)
}
}

func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client) {
Expand All @@ -81,5 +88,11 @@ func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client)

verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus())
healthStatus := resp.GetBody().GetHealthStatus()

cmd.Printf("Health status: %s\n", healthStatus)

if healthStatus != ircontrol.HealthStatus_READY {
os.Exit(1)
}
}

0 comments on commit 2cb41e1

Please sign in to comment.