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