Skip to content

Commit 0b7606f

Browse files
authored
feat: wait for coredns and metrics-server (#621)
* wait for coredns and metrics-server * update message * review comments
1 parent 38f05bb commit 0b7606f

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

pkg/addons/applier.go

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ package addons
66
import (
77
"context"
88
"fmt"
9-
"time"
10-
119
"github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
1210
k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
1311
embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster-kinds/apis/v1beta1"
1412
"github.com/replicatedhq/embedded-cluster-kinds/types"
1513
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
1614
"github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
1715
"github.com/sirupsen/logrus"
18-
corev1 "k8s.io/api/core/v1"
1916
"sigs.k8s.io/controller-runtime/pkg/client"
2017

2118
"github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole"
@@ -62,6 +59,12 @@ func (a *Applier) Outro(ctx context.Context) error {
6259
if err != nil {
6360
return fmt.Errorf("unable to load addons: %w", err)
6461
}
62+
63+
err = a.waitForKubernetes(ctx, kcli)
64+
if err != nil {
65+
return fmt.Errorf("unable to wait for kubernetes: %w", err)
66+
}
67+
6568
for _, addon := range addons {
6669
if err := addon.Outro(ctx, kcli); err != nil {
6770
return err
@@ -319,37 +322,29 @@ func (a *Applier) Versions(additionalCharts []v1beta1.Chart) (map[string]string,
319322
return versions, nil
320323
}
321324

322-
// waitForKubernetes waits until we manage to make a successful connection to the
323-
// Kubernetes API server.
324-
func (a *Applier) waitForKubernetes(ctx context.Context) error {
325+
// waitForKubernetes waits for coredns and metrics-server to be ready in kube-system.
326+
func (a *Applier) waitForKubernetes(ctx context.Context, cli client.Client) error {
325327
loading := spinner.Start()
326-
defer func() {
327-
loading.Closef("Kubernetes API server is ready")
328-
}()
329-
kcli, err := kubeutils.KubeClient()
328+
loading.Infof("Waiting for Kubernetes System Infrastructure to be ready 0/2")
329+
330+
err := kubeutils.WaitForDeployment(ctx, cli, "kube-system", "coredns")
330331
if err != nil {
331-
return fmt.Errorf("unable to create kubernetes client: %w", err)
332-
}
333-
ticker := time.NewTicker(3 * time.Second)
334-
defer ticker.Stop()
335-
counter := 1
336-
loading.Infof("1/n Waiting for Kubernetes API server to be ready")
337-
for {
338-
select {
339-
case <-ticker.C:
340-
case <-ctx.Done():
341-
return ctx.Err()
342-
}
343-
counter++
344-
if err := kcli.List(ctx, &corev1.NamespaceList{}); err != nil {
345-
loading.Infof(
346-
"%d/n Waiting for Kubernetes API server to be ready.",
347-
counter,
348-
)
349-
continue
350-
}
351-
return nil
332+
loading.Errorf("CoreDNS failed to become healthy, check your /etc/resolv.conf configuration")
333+
loading.CloseWithError()
334+
return fmt.Errorf("unable to wait for CoreDNS: %w", err)
335+
}
336+
337+
loading.Infof("Waiting for Kubernetes System Infrastructure to be ready 1/2")
338+
339+
err = kubeutils.WaitForDeployment(ctx, cli, "kube-system", "metrics-server")
340+
if err != nil {
341+
loading.Errorf("Metrics Server failed to become healthy - this may be a firewall or network issue.")
342+
loading.CloseWithError()
343+
return fmt.Errorf("unable to wait for Metrics Server: %w", err)
352344
}
345+
346+
loading.Closef("Kubernetes System Infrastructure ready")
347+
return nil
353348
}
354349

355350
func spinForInstallation(ctx context.Context, cli client.Client) error {

0 commit comments

Comments
 (0)