Skip to content

Commit 5bfd670

Browse files
authored
Wait for k0s and node to be ready before proceeding (#1900)
1 parent 682ad3c commit 5bfd670

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

cmd/installer/cli/install.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,16 @@ func installAndStartCluster(ctx context.Context, networkInterface string, airgap
626626
if err := k0s.Install(networkInterface); err != nil {
627627
return nil, fmt.Errorf("install cluster: %w", err)
628628
}
629+
629630
loading.Infof("Waiting for %s node to be ready", runtimeconfig.BinaryName())
631+
630632
logrus.Debugf("waiting for k0s to be ready")
631633
if err := waitForK0s(); err != nil {
634+
return nil, fmt.Errorf("wait for k0s: %w", err)
635+
}
636+
637+
logrus.Debugf("waiting for node to be ready")
638+
if err := waitForNode(ctx); err != nil {
632639
return nil, fmt.Errorf("wait for node: %w", err)
633640
}
634641

@@ -947,6 +954,21 @@ func waitForK0s() error {
947954
}
948955
}
949956

957+
func waitForNode(ctx context.Context) error {
958+
kcli, err := kubeutils.KubeClient()
959+
if err != nil {
960+
return fmt.Errorf("create kube client: %w", err)
961+
}
962+
hostname, err := os.Hostname()
963+
if err != nil {
964+
return fmt.Errorf("get hostname: %w", err)
965+
}
966+
if err := kubeutils.WaitForControllerNode(ctx, kcli, hostname); err != nil {
967+
return fmt.Errorf("wait for node: %w", err)
968+
}
969+
return nil
970+
}
971+
950972
func recordInstallation(ctx context.Context, kcli client.Client, flags InstallCmdFlags, k0sCfg *k0sv1beta1.ClusterConfig, disasterRecoveryEnabled bool) (*ecv1beta1.Installation, error) {
951973
// ensure that the embedded-cluster namespace exists
952974
if err := createECNamespace(ctx, kcli); err != nil {

cmd/installer/cli/join.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *kotsadm
206206
return fmt.Errorf("unable to get hostname: %w", err)
207207
}
208208

209-
if err := waitForNode(ctx, kcli, hostname); err != nil {
209+
if err := waitForNodeToJoin(ctx, kcli, hostname); err != nil {
210210
return fmt.Errorf("unable to wait for node: %w", err)
211211
}
212212

@@ -465,7 +465,7 @@ func runK0sInstallCommand(networkInterface string, fullcmd string) error {
465465
return nil
466466
}
467467

468-
func waitForNode(ctx context.Context, kcli client.Client, hostname string) error {
468+
func waitForNodeToJoin(ctx context.Context, kcli client.Client, hostname string) error {
469469
loading := spinner.Start()
470470
defer loading.Close()
471471
loading.Infof("Waiting for node to join the cluster")

0 commit comments

Comments
 (0)