Skip to content

Commit 2cecf17

Browse files
committed
capi provider interface: add bootstrap delete hook
Adds a hook to execute provider-specific behvavior during bootstrap destroy. This hook should be used to handle any bootstrap resources that are not deleted in the default behavior of deleting the capi machine. The intended first use case of this is to delete aws security rules for ssh to the bootstrap node. This use case does not have any relationship to the machine deletion; so I have opted for the simplest execution of running this command serially before the call to destroy the capi machine. If needed, this command could be run post machine destroy or even to run concurrently.
1 parent 785fd16 commit 2cecf17

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,17 @@ func (i *InfraProvider) DestroyBootstrap(ctx context.Context, dir string) error
378378
}
379379
}
380380

381+
if p, ok := i.impl.(BootstrapDestroyer); ok {
382+
bootstrapDestoryInput := BootstrapDestroyInput{
383+
Client: sys.Client(),
384+
Metadata: *metadata,
385+
}
386+
387+
if err = p.DestroyBootstrap(ctx, bootstrapDestoryInput); err != nil {
388+
return fmt.Errorf("failed during the destroy bootstrap hook: %w", err)
389+
}
390+
}
391+
381392
machineName := capiutils.GenerateBoostrapMachineName(metadata.InfraID)
382393
machineNamespace := capiutils.Namespace
383394
if err := sys.Client().Delete(ctx, &clusterv1.Machine{

pkg/infrastructure/clusterapi/types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/openshift/installer/pkg/asset/machines"
1111
"github.com/openshift/installer/pkg/asset/manifests"
1212
"github.com/openshift/installer/pkg/asset/rhcos"
13+
"github.com/openshift/installer/pkg/types"
1314
)
1415

1516
// Provider is the base interface that cloud platforms
@@ -87,3 +88,15 @@ type PostProvisionInput struct {
8788
InstallConfig *installconfig.InstallConfig
8889
InfraID string
8990
}
91+
92+
// BootstrapDestroyer allows platform-specific behavior when
93+
// destroying bootstrap resources.
94+
type BootstrapDestroyer interface {
95+
DestroyBootstrap(ctx context.Context, in BootstrapDestroyInput) error
96+
}
97+
98+
// BootstrapDestroyInput collects args passed to the DestroyBootstrap hook.
99+
type BootstrapDestroyInput struct {
100+
Client client.Client
101+
Metadata types.ClusterMetadata
102+
}

0 commit comments

Comments
 (0)