@@ -60,48 +60,48 @@ func getCrcBundleInfo(preset crcPreset.Preset, bundleName, bundlePath string, en
6060 return bundle .Use (bundleName )
6161}
6262
63- func (client * client ) updateVMConfig (startConfig types.StartConfig , vm * virtualMachine ) error {
63+ func (client * client ) updateVMConfig (startConfig types.StartConfig , vm VirtualMachine ) error {
6464 /* Memory */
6565 logging .Debugf ("Updating CRC VM configuration" )
66- if err := setMemory (vm .Host , startConfig .Memory ); err != nil {
66+ if err := setMemory (vm .GetHost () , startConfig .Memory ); err != nil {
6767 logging .Debugf ("Failed to update CRC VM configuration: %v" , err )
6868 if err == drivers .ErrNotImplemented {
6969 logging .Warn ("Memory configuration change has been ignored as the machine driver does not support it" )
7070 } else {
7171 return err
7272 }
7373 }
74- if err := setVcpus (vm .Host , startConfig .CPUs ); err != nil {
74+ if err := setVcpus (vm .GetHost () , startConfig .CPUs ); err != nil {
7575 logging .Debugf ("Failed to update CRC VM configuration: %v" , err )
7676 if err == drivers .ErrNotImplemented {
7777 logging .Warn ("CPU configuration change has been ignored as the machine driver does not support it" )
7878 } else {
7979 return err
8080 }
8181 }
82- if err := vm .api .Save (vm .Host ); err != nil {
82+ if err := vm .API () .Save (vm .GetHost () ); err != nil {
8383 return err
8484 }
8585
8686 /* Disk size */
8787 if startConfig .DiskSize != constants .DefaultDiskSize {
88- if err := setDiskSize (vm .Host , startConfig .DiskSize ); err != nil {
88+ if err := setDiskSize (vm .GetHost () , startConfig .DiskSize ); err != nil {
8989 logging .Debugf ("Failed to update CRC disk configuration: %v" , err )
9090 if err == drivers .ErrNotImplemented {
9191 logging .Warn ("Disk size configuration change has been ignored as the machine driver does not support it" )
9292 } else {
9393 return err
9494 }
9595 }
96- if err := vm .api .Save (vm .Host ); err != nil {
96+ if err := vm .API () .Save (vm .GetHost () ); err != nil {
9797 return err
9898 }
9999 }
100100
101101 // we want to set the shared dir password on-the-fly to be used
102102 // we do not want this value to be persisted to disk
103103 if startConfig .SharedDirPassword != "" {
104- if err := setSharedDirPassword (vm .Host , startConfig .SharedDirPassword ); err != nil {
104+ if err := setSharedDirPassword (vm .GetHost () , startConfig .SharedDirPassword ); err != nil {
105105 return fmt .Errorf ("Failed to set shared dir password: %w" , err )
106106 }
107107 }
@@ -206,9 +206,9 @@ func growLVForMicroshift(sshRunner *crcssh.Runner, lvFullName string, rootPart s
206206 return nil
207207}
208208
209- func configureSharedDirs (vm * virtualMachine , sshRunner * crcssh.Runner ) error {
209+ func configureSharedDirs (vm VirtualMachine , sshRunner * crcssh.Runner ) error {
210210 logging .Debugf ("Configuring shared directories" )
211- sharedDirs , err := vm .Driver .GetSharedDirs ()
211+ sharedDirs , err := vm .Driver () .GetSharedDirs ()
212212 if err != nil {
213213 // the libvirt machine driver uses net/rpc, which wraps errors
214214 // in rpc.ServerError, but without using golang 1.13 error
@@ -334,7 +334,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
334334 }
335335 defer vm .Close ()
336336
337- currentBundleName := vm .bundle .GetBundleName ()
337+ currentBundleName := vm .Bundle () .GetBundleName ()
338338 if currentBundleName != bundleName {
339339 logging .Debugf ("Bundle '%s' was requested, but the existing VM is using '%s'" ,
340340 bundleName , currentBundleName )
@@ -347,8 +347,8 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
347347 return nil , errors .Wrap (err , "Error getting the machine state" )
348348 }
349349 if vmState == state .Running {
350- logging .Infof ("A CRC VM for %s %s is already running" , startConfig .Preset .ForDisplay (), vm .bundle .GetVersion ())
351- clusterConfig , err := getClusterConfig (vm .bundle )
350+ logging .Infof ("A CRC VM for %s %s is already running" , startConfig .Preset .ForDisplay (), vm .Bundle () .GetVersion ())
351+ clusterConfig , err := getClusterConfig (vm .Bundle () )
352352 if err != nil {
353353 return nil , errors .Wrap (err , "Cannot create cluster configuration" )
354354 }
@@ -365,7 +365,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
365365 return nil , err
366366 }
367367
368- logging .Infof ("Starting CRC VM for %s %s..." , startConfig .Preset , vm .bundle .GetVersion ())
368+ logging .Infof ("Starting CRC VM for %s %s..." , startConfig .Preset , vm .Bundle () .GetVersion ())
369369
370370 if client .useVSock () {
371371 if err := exposePorts (startConfig .Preset , startConfig .IngressHTTPPort , startConfig .IngressHTTPSPort ); err != nil {
@@ -457,7 +457,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
457457 return nil , errors .Wrap (err , "Failed to change permissions to root podman socket" )
458458 }
459459
460- proxyConfig , err := getProxyConfig (vm .bundle )
460+ proxyConfig , err := getProxyConfig (vm .Bundle () )
461461 if err != nil {
462462 return nil , errors .Wrap (err , "Error getting proxy configuration" )
463463 }
@@ -472,7 +472,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
472472 SSHRunner : sshRunner ,
473473 IP : instanceIP ,
474474 // TODO: should be more finegrained
475- BundleMetadata : * vm .bundle ,
475+ BundleMetadata : * vm .Bundle () ,
476476 NetworkMode : client .networkMode (),
477477 }
478478
@@ -502,7 +502,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
502502 logging .Warn (fmt .Sprintf ("Failed to query DNS from host: %v" , err ))
503503 }
504504
505- if vm .bundle .IsMicroshift () {
505+ if vm .Bundle () .IsMicroshift () {
506506 // **************************
507507 // END OF MICROSHIFT START CODE
508508 // **************************
@@ -547,7 +547,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
547547 ocConfig := oc .UseOCWithSSH (sshRunner )
548548
549549 if err := cluster .ApproveCSRAndWaitForCertsRenewal (ctx , sshRunner , ocConfig , certsExpired [cluster .KubeletClientCert ], certsExpired [cluster .KubeletServerCert ], certsExpired [cluster .AggregatorClientCert ]); err != nil {
550- logBundleDate (vm .bundle )
550+ logBundleDate (vm .Bundle () )
551551 return nil , errors .Wrap (err , "Failed to renew TLS certificates: please check if a newer CRC release is available" )
552552 }
553553
@@ -596,7 +596,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
596596 }
597597 }
598598
599- if err := updateKubeconfig (ctx , ocConfig , sshRunner , vm .bundle .GetKubeConfigPath ()); err != nil {
599+ if err := updateKubeconfig (ctx , ocConfig , sshRunner , vm .Bundle () .GetKubeConfigPath ()); err != nil {
600600 return nil , errors .Wrap (err , "Failed to update kubeconfig file" )
601601 }
602602
@@ -607,7 +607,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
607607
608608 waitForProxyPropagation (ctx , ocConfig , proxyConfig )
609609
610- clusterConfig , err := getClusterConfig (vm .bundle )
610+ clusterConfig , err := getClusterConfig (vm .Bundle () )
611611 if err != nil {
612612 return nil , errors .Wrap (err , "Cannot get cluster configuration" )
613613 }
@@ -625,7 +625,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
625625}
626626
627627func (client * client ) IsRunning () (bool , error ) {
628- vm , err := loadVirtualMachine ( client .name , client .useVSock ())
628+ vm , err := loadVirtualMachineLazily ( client . virtualMachine , client .name , client .useVSock ())
629629 if err != nil {
630630 return false , errors .Wrap (err , "Cannot load machine" )
631631 }
@@ -694,17 +694,17 @@ func createHost(machineConfig config.MachineConfig, preset crcPreset.Preset) err
694694 return nil
695695}
696696
697- func startHost (ctx context.Context , vm * virtualMachine ) error {
698- if err := vm .Driver .Start (); err != nil {
697+ func startHost (ctx context.Context , vm VirtualMachine ) error {
698+ if err := vm .Driver () .Start (); err != nil {
699699 return fmt .Errorf ("Error in driver during machine start: %s" , err )
700700 }
701701
702- if err := vm .api .Save (vm .Host ); err != nil {
702+ if err := vm .API () .Save (vm .GetHost () ); err != nil {
703703 return fmt .Errorf ("Error saving virtual machine to store after attempting creation: %s" , err )
704704 }
705705
706706 logging .Debug ("Waiting for machine to be running, this may take a few minutes..." )
707- if err := crcerrors .Retry (ctx , 3 * time .Minute , host .MachineInState (vm .Driver , libmachinestate .Running ), 3 * time .Second ); err != nil {
707+ if err := crcerrors .Retry (ctx , 3 * time .Minute , host .MachineInState (vm .Driver () , libmachinestate .Running ), 3 * time .Second ); err != nil {
708708 return fmt .Errorf ("Error waiting for machine to be running: %s" , err )
709709 }
710710
0 commit comments