@@ -287,24 +287,35 @@ func IsDaemonsetReady(ctx context.Context, cli client.Client, ns, name string) (
287
287
return false , nil
288
288
}
289
289
290
- // WaitForKubernetes waits for coredns and metrics-server to be ready in kube-system, and returns an error channel.
290
+ // WaitForKubernetes waits for all deployments to be ready in kube-system, and returns an error channel.
291
291
// if either of them fails to become healthy, an error is returned via the channel.
292
292
func WaitForKubernetes (ctx context.Context , cli client.Client ) <- chan error {
293
- errch := make (chan error , 2 )
293
+ errch := make (chan error , 1 )
294
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
- }()
295
+ // wait until there is at least one deployment in kube-system
296
+ backoff := wait.Backoff {Steps : 60 , Duration : time .Second , Factor : 1.0 , Jitter : 0.1 }
297
+ deps := appsv1.DeploymentList {}
298
+ if err := wait .ExponentialBackoffWithContext (
299
+ ctx , backoff , func (ctx context.Context ) (bool , error ) {
300
+ if err := cli .List (ctx , & deps , client .InNamespace ("kube-system" )); err != nil {
301
+ return false , nil
302
+ }
303
+ return len (deps .Items ) >= 3 , nil // coredns, metrics-server, and calico-kube-controllers
304
+ }); err != nil {
305
+ errch <- fmt .Errorf ("timed out waiting for deployments in kube-system: %w" , err )
306
+ return errch
307
+ }
301
308
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
- }()
309
+ errch = make (chan error , len (deps .Items ))
310
+
311
+ for _ , dep := range deps .Items {
312
+ go func (depName string ) {
313
+ err := WaitForDeployment (ctx , cli , "kube-system" , depName )
314
+ if err != nil {
315
+ errch <- fmt .Errorf ("%s failed to become healthy: %w" , depName , err )
316
+ }
317
+ }(dep .Name )
318
+ }
308
319
309
320
return errch
310
321
}
0 commit comments