Skip to content

Commit 23b77ca

Browse files
Merge pull request openshift#8639 from r4f4/capi-preserve-bootstrap-defer-shutdown
OCPBUGS-35852: capi: shutdown local controlplane as the last step
2 parents 6ad0741 + 4c464bd commit 23b77ca

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)