Skip to content

Commit 91afaf7

Browse files
authored
watch for all deployments in kube-system (#631)
wait for all deployments in kube-system
1 parent a89953e commit 91afaf7

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

cmd/embedded-cluster/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ var restoreCommand = &cli.Command{
693693
defer func() {
694694
for len(errCh) > 0 {
695695
err := <-errCh
696-
logrus.Error(fmt.Errorf("the Kubernetes Infrastructure failed to become ready: %w", err))
696+
logrus.Error(fmt.Errorf("infrastructure failed to become ready: %w", err))
697697
}
698698
}()
699699

pkg/addons/applier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (a *Applier) Outro(ctx context.Context) error {
6464
defer func() {
6565
for len(errCh) > 0 {
6666
err := <-errCh
67-
logrus.Error(fmt.Errorf("the Kubernetes Infrastructure failed to become ready: %w", err))
67+
logrus.Error(fmt.Errorf("infrastructure failed to become ready: %w", err))
6868
}
6969
}()
7070

pkg/kubeutils/kubeutils.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,35 @@ func IsDaemonsetReady(ctx context.Context, cli client.Client, ns, name string) (
287287
return false, nil
288288
}
289289

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.
291291
// if either of them fails to become healthy, an error is returned via the channel.
292292
func WaitForKubernetes(ctx context.Context, cli client.Client) <-chan error {
293-
errch := make(chan error, 2)
293+
errch := make(chan error, 1)
294294

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+
}
301308

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+
}
308319

309320
return errch
310321
}

0 commit comments

Comments
 (0)