@@ -277,8 +277,10 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
277
277
if err := validation .BundleMismatchWithPresetMetadata (startConfig .Preset , crcBundleMetadata ); err != nil {
278
278
return nil , err
279
279
}
280
+ var firstBoot bool
280
281
281
282
if ! exists {
283
+ firstBoot = true
282
284
telemetry .SetStartType (ctx , telemetry .CreationStartType )
283
285
284
286
// Ask early for pull secret if it hasn't been requested yet
@@ -315,6 +317,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
315
317
return nil , errors .Wrap (err , "Error creating machine" )
316
318
}
317
319
} else {
320
+ firstBoot = false
318
321
telemetry .SetStartType (ctx , telemetry .StartStartType )
319
322
}
320
323
@@ -426,6 +429,35 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
426
429
}
427
430
}
428
431
432
+ // setup the env file for units to detect the network-mode either user or systemd
433
+ // refactor into a helper `setSystemdEnvFileValues`
434
+ if client .useVSock () {
435
+ envs := "CRC_NETWORK_MODE_USER=1" + "\n " +
436
+ "CRC_DEBUG_TEST=1" + "\n "
437
+
438
+ if err := sshRunner .CopyDataPrivileged ([]byte (envs ), "/etc/systemd/system/crc-env" , 0644 ); err != nil {
439
+ return nil , errors .Wrap (err , "Unable to create the env file for CRC" )
440
+ }
441
+ } else {
442
+ envs := "CRC_NETWORK_MODE_USER=0" + "\n " +
443
+ "CRC_DEBUG_TEST=1" + "\n "
444
+
445
+ if err := sshRunner .CopyDataPrivileged ([]byte (envs ), "/etc/systemd/system/crc-env" , 0644 ); err != nil {
446
+ return nil , errors .Wrap (err , "Unable to create the env file for CRC" )
447
+ }
448
+ }
449
+
450
+ // copy the pull secret into /opt/crc/pull-secret in the instance
451
+ if firstBoot {
452
+ pullSecret , err := startConfig .PullSecret .Value ()
453
+ if err != nil {
454
+ return nil , err
455
+ }
456
+ if err := sshRunner .CopyDataPrivileged ([]byte (pullSecret ), "/opt/crc/pull-secret" , 0600 ); err != nil {
457
+ return nil , errors .Wrap (err , "Unable to send pull-secret to instance" )
458
+ }
459
+ }
460
+
429
461
// Add nameserver to VM if provided by User
430
462
if startConfig .NameServer != "" {
431
463
if err = addNameServerToInstance (sshRunner , startConfig .NameServer ); err != nil {
@@ -511,6 +543,11 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
511
543
}, nil
512
544
}
513
545
546
+ // Send the kubeadmin and developer new passwords to the VM
547
+ if err := cluster .UpdateKubeAdminUserPassword (ctx , sshRunner , startConfig .KubeAdminPassword ); err != nil {
548
+ return nil , errors .Wrap (err , "Failed to update kubeadmin user password" )
549
+ }
550
+
514
551
// Check the certs validity inside the vm
515
552
logging .Info ("Verifying validity of the kubelet certificates..." )
516
553
certsExpired , err := cluster .CheckCertsValidity (sshRunner )
@@ -543,10 +580,6 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
543
580
return nil , err
544
581
}
545
582
546
- if err := cluster .EnsurePullSecretPresentInTheCluster (ctx , ocConfig , startConfig .PullSecret ); err != nil {
547
- return nil , errors .Wrap (err , "Failed to update cluster pull secret" )
548
- }
549
-
550
583
if err := cluster .EnsureSSHKeyPresentInTheCluster (ctx , ocConfig , constants .GetPublicKeyPath ()); err != nil {
551
584
return nil , errors .Wrap (err , "Failed to update ssh public key to machine config" )
552
585
}
@@ -555,19 +588,17 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
555
588
return nil , errors .Wrap (err , "Failed to update pull secret on the disk" )
556
589
}
557
590
558
- if err := cluster .UpdateKubeAdminUserPassword (ctx , ocConfig , startConfig .KubeAdminPassword ); err != nil {
559
- return nil , errors .Wrap (err , "Failed to update kubeadmin user password" )
560
- }
561
-
562
591
if client .monitoringEnabled () {
563
592
logging .Info ("Enabling cluster monitoring operator..." )
564
593
if err := cluster .StartMonitoring (ocConfig ); err != nil {
565
594
return nil , errors .Wrap (err , "Cannot start monitoring stack" )
566
595
}
567
596
}
568
597
569
- if err := updateKubeconfig (ctx , ocConfig , sshRunner , vm .bundle .GetKubeConfigPath ()); err != nil {
570
- return nil , errors .Wrap (err , "Failed to update kubeconfig file" )
598
+ if firstBoot {
599
+ if err := updateKubeconfig (ctx , ocConfig , sshRunner , vm .bundle .GetKubeConfigPath ()); err != nil {
600
+ return nil , errors .Wrap (err , "Failed to update kubeconfig file" )
601
+ }
571
602
}
572
603
573
604
logging .Infof ("Starting %s instance... [waiting for the cluster to stabilize]" , startConfig .Preset )
0 commit comments