Skip to content

Commit

Permalink
Fail with non-zero exit code when not ready
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Apr 11, 2024
1 parent 79efe2f commit d0bffb1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions commands/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
return err
}

if attempts < 1 {
return fmt.Errorf("attempts must be greater than 0")
}

var services stack.Services
var gatewayAddress string
var yamlGateway string
Expand All @@ -69,6 +73,7 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
transport := GetDefaultCLITransport(tlsInsecure, &commandTimeout)

if len(args) == 0 {
ready := false

c := &http.Client{
Transport: transport,
Expand All @@ -93,14 +98,20 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
fmt.Printf("[%d/%d] Error reaching OpenFaaS gateway: %s\n", i+1, attempts, err.Error())
} else if res.StatusCode == http.StatusOK {
fmt.Printf("OpenFaaS gateway is ready\n")
ready = true
break
}

time.Sleep(interval)
}

if !ready {
return fmt.Errorf("gateway: %s not ready after: %s", gatewayAddress, interval*time.Duration(attempts).Round(time.Second))
}

} else {
functionName := args[0]

ready := false
cliAuth, err := proxy.NewCLIAuth(token, gatewayAddress)
if err != nil {
return err
Expand All @@ -118,16 +129,21 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {

function, err := cliClient.GetFunctionInfo(ctx, functionName, functionNamespace)
if err != nil {
return err
fmt.Printf("[%d/%d] Error getting function info: %s\n", i+1, attempts, err.Error())
}

if function.AvailableReplicas > 0 {
fmt.Printf("Function %s is ready\n", functionName)
ready = true
break
}
time.Sleep(interval)
}

if !ready {
return fmt.Errorf("function %s not ready after: %s", functionName, interval*time.Duration(attempts).Round(time.Second))
}

}

return nil
Expand Down

0 comments on commit d0bffb1

Please sign in to comment.