Skip to content

Commit a03afe9

Browse files
committed
infra/capi: handle bootstrap destroy
Implements basic logic for handling bootstrap destroy through the CAPI infra provider. Further bootstrap destroy logic, including platform-specific implementations, may be needed to ensure proper destruction of all bootstrap resources.
1 parent df255e4 commit a03afe9

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

pkg/destroy/bootstrap/bootstrap.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@ import (
99

1010
"github.com/pkg/errors"
1111
"github.com/sirupsen/logrus"
12-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
14-
"sigs.k8s.io/controller-runtime/pkg/client"
1512

1613
configv1 "github.com/openshift/api/config/v1"
1714
"github.com/openshift/installer/pkg/asset/cluster/metadata"
1815
openstackasset "github.com/openshift/installer/pkg/asset/cluster/openstack"
19-
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
20-
"github.com/openshift/installer/pkg/clusterapi"
2116
osp "github.com/openshift/installer/pkg/destroy/openstack"
2217
infra "github.com/openshift/installer/pkg/infrastructure/platform"
2318
ibmcloudtfvars "github.com/openshift/installer/pkg/tfvars/ibmcloud"
24-
"github.com/openshift/installer/pkg/types"
2519
typesazure "github.com/openshift/installer/pkg/types/azure"
2620
"github.com/openshift/installer/pkg/types/featuregates"
2721
ibmcloudtypes "github.com/openshift/installer/pkg/types/ibmcloud"
@@ -35,10 +29,6 @@ func Destroy(ctx context.Context, dir string) (err error) {
3529
return err
3630
}
3731

38-
if sys := clusterapi.System(); sys.State() == clusterapi.SystemStateRunning {
39-
return destroyBoostrapMachine(ctx, sys.Client(), metadata)
40-
}
41-
4232
platform := metadata.Platform()
4333
if platform == "" {
4434
return errors.New("no platform configured in metadata")
@@ -92,15 +82,3 @@ func Destroy(ctx context.Context, dir string) (err error) {
9282

9383
return nil
9484
}
95-
96-
func destroyBoostrapMachine(ctx context.Context, c client.Client, metadata *types.ClusterMetadata) error {
97-
if err := c.Delete(ctx, &clusterv1.Machine{
98-
ObjectMeta: metav1.ObjectMeta{
99-
Name: capiutils.GenerateBoostrapMachineName(metadata.InfraID),
100-
Namespace: capiutils.Namespace,
101-
},
102-
}); client.IgnoreNotFound(err) != nil {
103-
return fmt.Errorf("failed to delete bootstrap machine: %w", err)
104-
}
105-
return nil
106-
}

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func (i *InfraProvider) Provision(dir string, parents asset.Parents) ([]*asset.F
8888
// TODO(vincepri): The context should be passed down from the caller,
8989
// although today the Asset interface doesn't allow it, refactor once it does.
9090
ctx, cancel := context.WithCancel(signals.SetupSignalHandler())
91-
defer cancel()
9291
go func() {
9392
<-ctx.Done()
9493
cancel()
@@ -323,6 +322,9 @@ func (i *InfraProvider) DestroyBootstrap(dir string) error {
323322
return fmt.Errorf("failed to delete bootstrap machine: %w", err)
324323
}
325324
}
325+
logrus.Infof("Finished destroying bootstrap resources")
326+
clusterapi.System().Teardown()
327+
326328
return nil
327329
}
328330

0 commit comments

Comments
 (0)