File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments