@@ -28,7 +28,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
2828 return err
2929 }
3030
31- uuid , err := getBiosUUID (ctx , instance )
31+ uuid , err := getBiosUUIDFromVM (ctx , instance )
3232 if err != nil {
3333 return err
3434 }
@@ -73,23 +73,11 @@ func (s *Service) Delete(ctx context.Context) error {
7373func (s * Service ) createOrGetInstance (ctx context.Context ) (* proxmox.VirtualMachine , error ) {
7474 log := log .FromContext (ctx )
7575
76- log .Info ("Getting bootstrap data for machine" )
77- bootstrapData , err := s .scope .GetBootstrapData ()
78- if err != nil {
79- log .Error (err , "Error getting bootstrap data for machine" )
80- return nil , errors .Wrap (err , "failed to retrieve bootstrap data" )
81- }
82-
83- if s .scope .GetBiosUUID () == nil {
84- log .Info ("ProxmoxMachine doesn't have bios UUID. instance will be created" )
85- return s .createInstance (ctx , bootstrapData )
86- }
87-
8876 instance , err := s .getInstance (ctx )
8977 if err != nil {
9078 if rest .IsNotFound (err ) {
9179 log .Info ("instance wasn't found. new instance will be created" )
92- return s .createInstance (ctx , bootstrapData )
80+ return s .createInstance (ctx )
9381 }
9482 log .Error (err , "failed to get instance" )
9583 return nil , err
@@ -98,10 +86,13 @@ func (s *Service) createOrGetInstance(ctx context.Context) (*proxmox.VirtualMach
9886 return instance , nil
9987}
10088
89+ // getInstance get vm from providerID
10190func (s * Service ) getInstance (ctx context.Context ) (* proxmox.VirtualMachine , error ) {
10291 log := log .FromContext (ctx )
92+
10393 biosUUID := s .scope .GetBiosUUID ()
10494 if biosUUID == nil {
95+ log .Info ("instance does not have providerID yet" )
10596 return nil , rest .NotFoundErr
10697 }
10798
@@ -114,10 +105,11 @@ func (s *Service) getInstance(ctx context.Context) (*proxmox.VirtualMachine, err
114105 log .Error (err , "failed to get instance from bios UUID" )
115106 return nil , err
116107 }
108+
117109 return vm , nil
118110}
119111
120- func getBiosUUID (ctx context.Context , vm * proxmox.VirtualMachine ) (* string , error ) {
112+ func getBiosUUIDFromVM (ctx context.Context , vm * proxmox.VirtualMachine ) (* string , error ) {
121113 log := log .FromContext (ctx )
122114 config , err := vm .GetConfig (ctx )
123115 if err != nil {
@@ -133,7 +125,7 @@ func getBiosUUID(ctx context.Context, vm *proxmox.VirtualMachine) (*string, erro
133125 return pointer .String (uuid ), nil
134126}
135127
136- func (s * Service ) createInstance (ctx context.Context , bootstrap string ) (* proxmox.VirtualMachine , error ) {
128+ func (s * Service ) createInstance (ctx context.Context ) (* proxmox.VirtualMachine , error ) {
137129 log := log .FromContext (ctx )
138130
139131 // qemu
@@ -145,7 +137,7 @@ func (s *Service) createInstance(ctx context.Context, bootstrap string) (*proxmo
145137 log .Info (fmt .Sprintf ("reconciled qemu: node=%s,vmid=%d" , instance .Node , vmid ))
146138
147139 // cloud init
148- if err := s .reconcileCloudInit (ctx , bootstrap ); err != nil {
140+ if err := s .reconcileCloudInit (ctx ); err != nil {
149141 return nil , err
150142 }
151143
@@ -191,9 +183,7 @@ func ensureStoppedOrPaused(ctx context.Context, instance proxmox.VirtualMachine)
191183 log .Error (err , "failed to stop instance process" )
192184 return err
193185 }
194- case api .ProcessStatusPaused :
195- return nil
196- case api .ProcessStatusStopped :
186+ case api .ProcessStatusPaused , api .ProcessStatusStopped :
197187 return nil
198188 default :
199189 return errors .Errorf ("unexpected status : %s" , instance .VM .Status )
0 commit comments