@@ -138,6 +138,16 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
138138 // Grab the client.
139139 cl := capiSystem .Client ()
140140
141+ // If we're skipping bootstrap destroy, shutdown the local control plane.
142+ // Otherwise, we will shut it down after bootstrap destroy.
143+ // This has to execute as the last defer in the stack since previous defers might still need the local controlplane.
144+ if oi , ok := os .LookupEnv ("OPENSHIFT_INSTALL_PRESERVE_BOOTSTRAP" ); ok && oi != "" {
145+ defer func () {
146+ logrus .Warn ("OPENSHIFT_INSTALL_PRESERVE_BOOTSTRAP is set, shutting down local control plane." )
147+ clusterapi .System ().Teardown ()
148+ }()
149+ }
150+
141151 // Make sure to always return generated manifests, even if errors happened
142152 defer func (ctx context.Context , cl client.Client ) {
143153 var errs []error
@@ -347,13 +357,6 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
347357
348358 logrus .Infof ("Cluster API resources have been created. Waiting for cluster to become ready..." )
349359
350- // If we're skipping bootstrap destroy, shutdown the local control plane.
351- // Otherwise, we will shut it down after bootstrap destroy.
352- if oi , ok := os .LookupEnv ("OPENSHIFT_INSTALL_PRESERVE_BOOTSTRAP" ); ok && oi != "" {
353- logrus .Warn ("OPENSHIFT_INSTALL_PRESERVE_BOOTSTRAP is set, shutting down local control plane." )
354- clusterapi .System ().Teardown ()
355- }
356-
357360 return fileList , nil
358361}
359362
0 commit comments