Skip to content

Commit d0bffb1

Browse files
committed
Fail with non-zero exit code when not ready
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 79efe2f commit d0bffb1

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

commands/ready.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
5151
return err
5252
}
5353

54+
if attempts < 1 {
55+
return fmt.Errorf("attempts must be greater than 0")
56+
}
57+
5458
var services stack.Services
5559
var gatewayAddress string
5660
var yamlGateway string
@@ -69,6 +73,7 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
6973
transport := GetDefaultCLITransport(tlsInsecure, &commandTimeout)
7074

7175
if len(args) == 0 {
76+
ready := false
7277

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

99105
time.Sleep(interval)
100106
}
107+
108+
if !ready {
109+
return fmt.Errorf("gateway: %s not ready after: %s", gatewayAddress, interval*time.Duration(attempts).Round(time.Second))
110+
}
111+
101112
} else {
102113
functionName := args[0]
103-
114+
ready := false
104115
cliAuth, err := proxy.NewCLIAuth(token, gatewayAddress)
105116
if err != nil {
106117
return err
@@ -118,16 +129,21 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
118129

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

124135
if function.AvailableReplicas > 0 {
125136
fmt.Printf("Function %s is ready\n", functionName)
137+
ready = true
126138
break
127139
}
128140
time.Sleep(interval)
129141
}
130142

143+
if !ready {
144+
return fmt.Errorf("function %s not ready after: %s", functionName, interval*time.Duration(attempts).Round(time.Second))
145+
}
146+
131147
}
132148

133149
return nil

0 commit comments

Comments
 (0)