Skip to content

Commit 4c464bd

Browse files
committed
OCPBUGS-35852: capi: shutdown local controlplane as the last step
If OPENSHIFT_INSTALL_PRESERVE_BOOTSTRAP is set, we need to make sure the local controlplane shutdown happens as the last step in the defer stack chain, so previous steps that need to access it don't fail. ``` 06-20 15:26:51.219 level=warning msg=OPENSHIFT_INSTALL_PRESERVE_BOOTSTRAP is set, shutting down local control plane. 06-20 15:26:51.219 level=info msg=Shutting down local Cluster API control plane... 06-20 15:26:51.473 level=info msg=Stopped controller: Cluster API 06-20 15:26:51.473 level=info msg=Stopped controller: aws infrastructure provider 06-20 15:26:52.830 level=info msg=Local Cluster API system has completed operations 06-20 15:26:52.830 level=debug msg=Collecting applied cluster api manifests... 06-20 15:26:52.831 level=error msg=failed to fetch Cluster: failed to generate asset "Cluster": failed to create cluster: [failed to get manifest openshift-cluster-api-guests: Get "https://127.0.0.1:46555/api/v1/namespaces/openshift-cluster-api-guests": dial tcp 127.0.0.1:46555: connect: connection refused[...] ```
1 parent 251f3a2 commit 4c464bd

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)