@@ -6,16 +6,13 @@ package addons
6
6
import (
7
7
"context"
8
8
"fmt"
9
- "time"
10
-
11
9
"github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
12
10
k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
13
11
embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster-kinds/apis/v1beta1"
14
12
"github.com/replicatedhq/embedded-cluster-kinds/types"
15
13
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
16
14
"github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
17
15
"github.com/sirupsen/logrus"
18
- corev1 "k8s.io/api/core/v1"
19
16
"sigs.k8s.io/controller-runtime/pkg/client"
20
17
21
18
"github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole"
@@ -62,6 +59,12 @@ func (a *Applier) Outro(ctx context.Context) error {
62
59
if err != nil {
63
60
return fmt .Errorf ("unable to load addons: %w" , err )
64
61
}
62
+
63
+ err = a .waitForKubernetes (ctx , kcli )
64
+ if err != nil {
65
+ return fmt .Errorf ("unable to wait for kubernetes: %w" , err )
66
+ }
67
+
65
68
for _ , addon := range addons {
66
69
if err := addon .Outro (ctx , kcli ); err != nil {
67
70
return err
@@ -319,37 +322,29 @@ func (a *Applier) Versions(additionalCharts []v1beta1.Chart) (map[string]string,
319
322
return versions , nil
320
323
}
321
324
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 {
325
327
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" )
330
331
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 )
352
344
}
345
+
346
+ loading .Closef ("Kubernetes System Infrastructure ready" )
347
+ return nil
353
348
}
354
349
355
350
func spinForInstallation (ctx context.Context , cli client.Client ) error {
0 commit comments