Skip to content

Commit 6d094b3

Browse files
Merge pull request #7864 from vincepri/clean-shutdown
CORS-2852: cmd/create: allow clean shutdown of resources
2 parents c231825 + cb71047 commit 6d094b3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

cmd/openshift-install/create.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ var (
124124
// FIXME: add longer descriptions for our commands with examples for better UX.
125125
// Long: "",
126126
PostRun: func(_ *cobra.Command, _ []string) {
127-
ctx, cancel := context.WithCancel(context.Background())
127+
// Setup a context that is canceled when the user presses Ctrl+C,
128+
// or SIGTERM and SIGINT are received, this allows for a clean shutdown.
129+
ctx, cancel := context.WithCancel(context.TODO())
128130
defer cancel()
129131
logrus.RegisterExitHandler(cancel)
130132

pkg/asset/cluster/cluster.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1616
utilkubeconfig "sigs.k8s.io/cluster-api/util/kubeconfig"
1717
"sigs.k8s.io/controller-runtime/pkg/client"
18+
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
1819

1920
"github.com/openshift/installer/pkg/asset"
2021
"github.com/openshift/installer/pkg/asset/cluster/aws"
@@ -98,7 +99,16 @@ func (c *Cluster) Generate(parents asset.Parents) (err error) {
9899

99100
// Check if we're using Cluster API.
100101
if capiutils.IsEnabled(installConfig) {
101-
return c.provisionWithClusterAPI(context.TODO(), parents, installConfig, clusterID)
102+
// TODO(vincepri): The context should be passed down from the caller,
103+
// although today the Asset interface doesn't allow it, refactor once it does.
104+
ctx, cancel := context.WithCancel(signals.SetupSignalHandler())
105+
go func() {
106+
<-ctx.Done()
107+
cancel()
108+
clusterapi.System().Teardown()
109+
}()
110+
111+
return c.provisionWithClusterAPI(ctx, parents, installConfig, clusterID)
102112
}
103113

104114
// Otherwise, use the normal path.

0 commit comments

Comments
 (0)