@@ -51,6 +51,10 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
51
51
return err
52
52
}
53
53
54
+ if attempts < 1 {
55
+ return fmt .Errorf ("attempts must be greater than 0" )
56
+ }
57
+
54
58
var services stack.Services
55
59
var gatewayAddress string
56
60
var yamlGateway string
@@ -69,6 +73,7 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
69
73
transport := GetDefaultCLITransport (tlsInsecure , & commandTimeout )
70
74
71
75
if len (args ) == 0 {
76
+ ready := false
72
77
73
78
c := & http.Client {
74
79
Transport : transport ,
@@ -93,14 +98,20 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
93
98
fmt .Printf ("[%d/%d] Error reaching OpenFaaS gateway: %s\n " , i + 1 , attempts , err .Error ())
94
99
} else if res .StatusCode == http .StatusOK {
95
100
fmt .Printf ("OpenFaaS gateway is ready\n " )
101
+ ready = true
96
102
break
97
103
}
98
104
99
105
time .Sleep (interval )
100
106
}
107
+
108
+ if ! ready {
109
+ return fmt .Errorf ("gateway: %s not ready after: %s" , gatewayAddress , interval * time .Duration (attempts ).Round (time .Second ))
110
+ }
111
+
101
112
} else {
102
113
functionName := args [0 ]
103
-
114
+ ready := false
104
115
cliAuth , err := proxy .NewCLIAuth (token , gatewayAddress )
105
116
if err != nil {
106
117
return err
@@ -118,16 +129,21 @@ func runReadyCmd(cmd *cobra.Command, args []string) error {
118
129
119
130
function , err := cliClient .GetFunctionInfo (ctx , functionName , functionNamespace )
120
131
if err != nil {
121
- return err
132
+ fmt . Printf ( "[%d/%d] Error getting function info: %s \n " , i + 1 , attempts , err . Error ())
122
133
}
123
134
124
135
if function .AvailableReplicas > 0 {
125
136
fmt .Printf ("Function %s is ready\n " , functionName )
137
+ ready = true
126
138
break
127
139
}
128
140
time .Sleep (interval )
129
141
}
130
142
143
+ if ! ready {
144
+ return fmt .Errorf ("function %s not ready after: %s" , functionName , interval * time .Duration (attempts ).Round (time .Second ))
145
+ }
146
+
131
147
}
132
148
133
149
return nil
0 commit comments