Skip to content

Commit d2782de

Browse files
committed
capi bootstrap destroy: add standalone support
Restarts the CAPI control plane if it is not running when bootstrap destroy is called. This allows support for the standalone `openshift install destroy bootstrap` command.
1 parent a85db0b commit d2782de

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -368,42 +368,47 @@ func (i *InfraProvider) DestroyBootstrap(ctx context.Context, dir string) error
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 := 2 * 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.Infof("Timeout deleting bootstrap machine: %s", err)
406410
}
411+
407412
logrus.Infof("Finished destroying bootstrap resources")
408413
clusterapi.System().Teardown()
409414

0 commit comments

Comments
 (0)