@@ -40,7 +40,11 @@ func WaitForNamespace(ctx context.Context, cli client.Client, ns string) error {
40
40
return ready , nil
41
41
},
42
42
); err != nil {
43
- return fmt .Errorf ("timed out waiting for namespace %s: %v" , ns , lasterr )
43
+ if lasterr != nil {
44
+ return fmt .Errorf ("timed out waiting for namespace %s: %v" , ns , lasterr )
45
+ } else {
46
+ return fmt .Errorf ("timed out waiting for namespace %s" , ns )
47
+ }
44
48
}
45
49
return nil
46
50
@@ -60,7 +64,11 @@ func WaitForDeployment(ctx context.Context, cli client.Client, ns, name string)
60
64
return ready , nil
61
65
},
62
66
); err != nil {
63
- return fmt .Errorf ("timed out waiting for %s to deploy: %v" , name , lasterr )
67
+ if lasterr != nil {
68
+ return fmt .Errorf ("timed out waiting for %s to deploy: %v" , name , lasterr )
69
+ } else {
70
+ return fmt .Errorf ("timed out waiting for %s to deploy" , name )
71
+ }
64
72
}
65
73
return nil
66
74
}
@@ -79,7 +87,11 @@ func WaitForDaemonset(ctx context.Context, cli client.Client, ns, name string) e
79
87
return ready , nil
80
88
},
81
89
); err != nil {
82
- return fmt .Errorf ("timed out waiting for %s to deploy: %v" , name , lasterr )
90
+ if lasterr != nil {
91
+ return fmt .Errorf ("timed out waiting for %s to deploy: %v" , name , lasterr )
92
+ } else {
93
+ return fmt .Errorf ("timed out waiting for %s to deploy" , name )
94
+ }
83
95
}
84
96
return nil
85
97
}
@@ -98,7 +110,11 @@ func WaitForService(ctx context.Context, cli client.Client, ns, name string) err
98
110
return svc .Spec .ClusterIP != "" , nil
99
111
},
100
112
); err != nil {
101
- return fmt .Errorf ("timed out waiting for service %s to have an IP: %v" , name , lasterr )
113
+ if lasterr != nil {
114
+ return fmt .Errorf ("timed out waiting for service %s to have an IP: %v" , name , lasterr )
115
+ } else {
116
+ return fmt .Errorf ("timed out waiting for service %s to have an IP" , name )
117
+ }
102
118
}
103
119
return nil
104
120
}
@@ -153,7 +169,11 @@ func WaitForInstallation(ctx context.Context, cli client.Client, writer *spinner
153
169
},
154
170
); err != nil {
155
171
if wait .Interrupted (err ) {
156
- return fmt .Errorf ("timed out waiting for the installation to finish: %v" , lasterr )
172
+ if lasterr != nil {
173
+ return fmt .Errorf ("timed out waiting for the installation to finish: %v" , lasterr )
174
+ } else {
175
+ return fmt .Errorf ("timed out waiting for the installation to finish" )
176
+ }
157
177
}
158
178
return fmt .Errorf ("error waiting for installation: %v" , err )
159
179
}
@@ -211,7 +231,11 @@ func WaitForNodes(ctx context.Context, cli client.Client) error {
211
231
return readynodes == len (nodes .Items ), nil
212
232
},
213
233
); err != nil {
214
- return fmt .Errorf ("timed out waiting for nodes to be ready: %v" , lasterr )
234
+ if lasterr != nil {
235
+ return fmt .Errorf ("timed out waiting for nodes to be ready: %v" , lasterr )
236
+ } else {
237
+ return fmt .Errorf ("timed out waiting for nodes to be ready" )
238
+ }
215
239
}
216
240
return nil
217
241
}
@@ -262,3 +286,25 @@ func IsDaemonsetReady(ctx context.Context, cli client.Client, ns, name string) (
262
286
}
263
287
return false , nil
264
288
}
289
+
290
+ // WaitForKubernetes waits for coredns and metrics-server to be ready in kube-system, and returns an error channel.
291
+ // if either of them fails to become healthy, an error is returned via the channel.
292
+ func WaitForKubernetes (ctx context.Context , cli client.Client ) <- chan error {
293
+ errch := make (chan error , 2 )
294
+
295
+ go func () {
296
+ err := WaitForDeployment (ctx , cli , "kube-system" , "coredns" )
297
+ if err != nil {
298
+ errch <- fmt .Errorf ("CoreDNS failed to become healthy: %w" , err )
299
+ }
300
+ }()
301
+
302
+ go func () {
303
+ err := WaitForDeployment (ctx , cli , "kube-system" , "metrics-server" )
304
+ if err != nil {
305
+ errch <- fmt .Errorf ("Metrics Server failed to become healthy: %w" , err )
306
+ }
307
+ }()
308
+
309
+ return errch
310
+ }
0 commit comments