@@ -132,7 +132,7 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
132132 // Run the CAPI system.
133133 timer .StartTimer (infrastructureStage )
134134 capiSystem := clusterapi .System ()
135- if err := capiSystem .Run (ctx , installConfig ); err != nil {
135+ if err := capiSystem .Run (ctx ); err != nil {
136136 return fileList , fmt .Errorf ("failed to run cluster api system: %w" , err )
137137 }
138138
@@ -362,49 +362,54 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
362362}
363363
364364// DestroyBootstrap destroys the temporary bootstrap resources.
365- func (i * InfraProvider ) DestroyBootstrap (dir string ) error {
365+ func (i * InfraProvider ) DestroyBootstrap (ctx context. Context , dir string ) error {
366366 metadata , err := metadata .Load (dir )
367367 if err != nil {
368368 return err
369369 }
370370
371- // TODO(padillon): start system if not running
372- if sys := clusterapi .System (); sys .State () == clusterapi .SystemStateRunning {
373- machineName := capiutils .GenerateBoostrapMachineName (metadata .InfraID )
374- machineNamespace := capiutils .Namespace
375- if err := sys .Client ().Delete (context .TODO (), & clusterv1.Machine {
376- ObjectMeta : metav1.ObjectMeta {
377- Name : machineName ,
378- Namespace : machineNamespace ,
379- },
380- }); err != nil {
381- return fmt .Errorf ("failed to delete bootstrap machine: %w" , err )
371+ sys := clusterapi .System ()
372+ if sys .State () != clusterapi .SystemStateRunning {
373+ if err := sys .Run (ctx ); err != nil {
374+ return fmt .Errorf ("failed to run capi system: %w" , err )
382375 }
376+ }
383377
384- machineDeletionTimeout := 2 * time .Minute
385- logrus .Infof ("Waiting up to %v for bootstrap machine deletion %s/%s..." , machineDeletionTimeout , machineNamespace , machineName )
386- machineContext , cancel := context .WithTimeout (context .TODO (), machineDeletionTimeout )
387- wait .Until (func () {
388- err := sys .Client ().Get (context .TODO (), client.ObjectKey {
389- Name : machineName ,
390- Namespace : machineNamespace ,
391- }, & clusterv1.Machine {})
392- if err != nil {
393- if apierrors .IsNotFound (err ) {
394- logrus .Debugf ("Machine deleted: %s" , machineName )
395- cancel ()
396- } else {
397- logrus .Debugf ("Error when deleting bootstrap machine: %s" , err )
398- }
399- }
400- }, 2 * time .Second , machineContext .Done ())
378+ machineName := capiutils .GenerateBoostrapMachineName (metadata .InfraID )
379+ machineNamespace := capiutils .Namespace
380+ if err := sys .Client ().Delete (ctx , & clusterv1.Machine {
381+ ObjectMeta : metav1.ObjectMeta {
382+ Name : machineName ,
383+ Namespace : machineNamespace ,
384+ },
385+ }); err != nil {
386+ return fmt .Errorf ("failed to delete bootstrap machine: %w" , err )
387+ }
401388
402- err = machineContext .Err ()
403- if err != nil && ! errors .Is (err , context .Canceled ) {
404- logrus .Infof ("Timeout deleting bootstrap machine: %s" , err )
389+ machineDeletionTimeout := 5 * time .Minute
390+ logrus .Infof ("Waiting up to %v for bootstrap machine deletion %s/%s..." , machineDeletionTimeout , machineNamespace , machineName )
391+ ctx , cancel := context .WithTimeout (ctx , machineDeletionTimeout )
392+ wait .UntilWithContext (ctx , func (context.Context ) {
393+ err := sys .Client ().Get (ctx , client.ObjectKey {
394+ Name : machineName ,
395+ Namespace : machineNamespace ,
396+ }, & clusterv1.Machine {})
397+ if err != nil {
398+ if apierrors .IsNotFound (err ) {
399+ logrus .Debugf ("Machine deleted: %s" , machineName )
400+ cancel ()
401+ } else {
402+ logrus .Debugf ("Error when deleting bootstrap machine: %s" , err )
403+ }
405404 }
405+ }, 2 * time .Second )
406+
407+ err = ctx .Err ()
408+ if err != nil && ! errors .Is (err , context .Canceled ) {
409+ logrus .Warnf ("Timeout deleting bootstrap machine: %s" , err )
410+ } else {
411+ logrus .Infof ("Finished destroying bootstrap resources" )
406412 }
407- logrus .Infof ("Finished destroying bootstrap resources" )
408413 clusterapi .System ().Teardown ()
409414
410415 return nil
0 commit comments