@@ -128,7 +128,7 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *kotsadm
128
128
// both controller and worker nodes will have 'worker' in the join command
129
129
isWorker := ! strings .Contains (jcmd .K0sJoinCommand , "controller" )
130
130
if ! isWorker {
131
- logrus .Warnf ("Do not join another node until this join is complete." )
131
+ logrus .Warn ("Do not join another node until this join is complete." )
132
132
}
133
133
134
134
if err := runJoinVerifyAndPrompt (name , flags , jcmd ); err != nil {
@@ -149,46 +149,57 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *kotsadm
149
149
}
150
150
151
151
logrus .Debugf ("installing and joining cluster" )
152
+ loading := spinner .Start ()
153
+ loading .Infof ("Installing node" )
152
154
if err := installAndJoinCluster (ctx , jcmd , name , flags , isWorker ); err != nil {
155
+ loading .Errorf ("Failed to install node" )
156
+ loading .CloseWithError ()
153
157
return err
154
158
}
155
159
156
160
kcli , err := kubeutils .KubeClient ()
157
161
if err != nil {
162
+ loading .Errorf ("Failed to install node" )
163
+ loading .CloseWithError ()
158
164
return fmt .Errorf ("unable to get kube client: %w" , err )
159
165
}
160
166
161
167
hostname , err := os .Hostname ()
162
168
if err != nil {
169
+ loading .Errorf ("Failed to install node" )
170
+ loading .CloseWithError ()
163
171
return fmt .Errorf ("unable to get hostname: %w" , err )
164
172
}
165
173
166
174
logrus .Debugf ("waiting for node to join cluster" )
175
+ loading .Infof ("Waiting for node" )
167
176
if err := waitForNodeToJoin (ctx , kcli , hostname , isWorker ); err != nil {
177
+ loading .Errorf ("Failed to wait for node" )
178
+ loading .CloseWithError ()
168
179
return fmt .Errorf ("unable to wait for node: %w" , err )
169
180
}
170
181
182
+ loading .Closef ("Node is ready" )
171
183
if isWorker {
172
184
logrus .Debugf ("worker node join finished" )
173
185
return nil
174
186
}
175
187
176
- airgapChartsPath := ""
177
- if flags .isAirgap {
178
- airgapChartsPath = runtimeconfig .EmbeddedClusterChartsSubDir ()
179
- }
180
-
181
- hcli , err := helm .NewClient (helm.HelmOptions {
182
- KubeConfig : runtimeconfig .PathToKubeConfig (),
183
- K0sVersion : versions .K0sVersion ,
184
- AirgapPath : airgapChartsPath ,
185
- })
186
- if err != nil {
187
- return fmt .Errorf ("unable to create helm client: %w" , err )
188
- }
189
- defer hcli .Close ()
190
-
191
188
if flags .enableHighAvailability {
189
+ airgapChartsPath := ""
190
+ if flags .isAirgap {
191
+ airgapChartsPath = runtimeconfig .EmbeddedClusterChartsSubDir ()
192
+ }
193
+
194
+ hcli , err := helm .NewClient (helm.HelmOptions {
195
+ KubeConfig : runtimeconfig .PathToKubeConfig (),
196
+ K0sVersion : versions .K0sVersion ,
197
+ AirgapPath : airgapChartsPath ,
198
+ })
199
+ if err != nil {
200
+ return fmt .Errorf ("unable to create helm client: %w" , err )
201
+ }
202
+ defer hcli .Close ()
192
203
if err := maybeEnableHA (ctx , kcli , hcli , flags .isAirgap , cidrCfg .ServiceCIDR , jcmd .InstallationSpec .Proxy , jcmd .InstallationSpec .Config ); err != nil {
193
204
return fmt .Errorf ("unable to enable high availability: %w" , err )
194
205
}
@@ -252,9 +263,17 @@ func runJoinVerifyAndPrompt(name string, flags JoinCmdFlags, jcmd *kotsadm.JoinC
252
263
return nil
253
264
}
254
265
255
- func initializeJoin (ctx context.Context , name string , flags JoinCmdFlags , jcmd * kotsadm.JoinCommandResponse ) (* CIDRConfig , error ) {
266
+ func initializeJoin (ctx context.Context , name string , flags JoinCmdFlags , jcmd * kotsadm.JoinCommandResponse ) (cidrCfg * CIDRConfig , err error ) {
256
267
spinner := spinner .Start ()
257
268
spinner .Infof ("Initializing" )
269
+ defer func () {
270
+ if err != nil {
271
+ spinner .Errorf ("Initialization failed" )
272
+ spinner .CloseWithError ()
273
+ } else {
274
+ spinner .Closef ("Initialization complete" )
275
+ }
276
+ }()
258
277
259
278
// set the umask to 022 so that we can create files/directories with 755 permissions
260
279
// this does not return an error - it returns the previous umask
@@ -268,8 +287,6 @@ func initializeJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *
268
287
269
288
logrus .Debugf ("materializing %s binaries" , name )
270
289
if err := materializeFiles (flags .airgapBundle ); err != nil {
271
- spinner .Errorf ("Initialization failed" )
272
- spinner .CloseWithError ()
273
290
return nil , err
274
291
}
275
292
@@ -285,15 +302,11 @@ func initializeJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *
285
302
286
303
logrus .Debugf ("configuring network manager" )
287
304
if err := configureNetworkManager (ctx ); err != nil {
288
- spinner .Errorf ("Initialization failed" )
289
- spinner .CloseWithError ()
290
305
return nil , fmt .Errorf ("unable to configure network manager: %w" , err )
291
306
}
292
307
293
- cidrCfg , err : = getJoinCIDRConfig (jcmd )
308
+ cidrCfg , err = getJoinCIDRConfig (jcmd )
294
309
if err != nil {
295
- spinner .Errorf ("Initialization failed" )
296
- spinner .CloseWithError ()
297
310
return nil , fmt .Errorf ("unable to get join CIDR config: %w" , err )
298
311
}
299
312
@@ -302,9 +315,6 @@ func initializeJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *
302
315
logrus .Debugf ("unable to configure firewalld: %v" , err )
303
316
}
304
317
305
- spinner .Infof ("Initialization complete" )
306
- spinner .Close ()
307
-
308
318
return cidrCfg , nil
309
319
}
310
320
@@ -431,9 +441,6 @@ func applyNetworkConfiguration(networkInterface string, jcmd *kotsadm.JoinComman
431
441
432
442
// startAndWaitForK0s starts the k0s service and waits for the node to be ready.
433
443
func startAndWaitForK0s (ctx context.Context , name string , jcmd * kotsadm.JoinCommandResponse ) error {
434
- loading := spinner .Start ()
435
- defer loading .Close ()
436
- loading .Infof ("Installing node" )
437
444
logrus .Debugf ("starting %s service" , name )
438
445
if _ , err := helpers .RunCommand (runtimeconfig .K0sBinaryPath (), "start" ); err != nil {
439
446
return fmt .Errorf ("unable to start service: %w" , err )
@@ -444,7 +451,6 @@ func startAndWaitForK0s(ctx context.Context, name string, jcmd *kotsadm.JoinComm
444
451
return fmt .Errorf ("unable to wait for node: %w" , err )
445
452
}
446
453
447
- loading .Infof ("Node installed" )
448
454
return nil
449
455
}
450
456
@@ -503,13 +509,9 @@ func runK0sInstallCommand(networkInterface string, fullcmd string) error {
503
509
}
504
510
505
511
func waitForNodeToJoin (ctx context.Context , kcli client.Client , hostname string , isWorker bool ) error {
506
- loading := spinner .Start ()
507
- defer loading .Close ()
508
- loading .Infof ("Waiting for node" )
509
512
if err := kubeutils .WaitForNode (ctx , kcli , hostname , isWorker ); err != nil {
510
513
return fmt .Errorf ("unable to wait for node: %w" , err )
511
514
}
512
- loading .Infof ("Node is ready" )
513
515
return nil
514
516
}
515
517
0 commit comments