Skip to content

Commit cd3e65f

Browse files
jangel97adrianriobo
authored andcommitted
feat(context): complete end-to-end context propagation for SIGINT/SIGTERM cancellation
This refactor removes all hard-coded context.Background() / context.TODO() calls and ensures the CLI's cancellable context (cmd.Context()) flows through every layer of MAPT: • CLI -> ContextArgs -> mc.Init() -> Providers -> Actions -> Data layer • AWS: AMI queries, region/zone discovery, S3 ops, Spot pricing, host waiters • Azure: compute selectors, image discovery, ResourceGraph queries • Pulumi: stack create/update/destroy, previews, refresh, output retrieval Key changes: - Add `Context` to ContextArgs and centralize fallback handling in mc.Init() - Update Provider interface so Init(ctx) receives the real execution context - Rename parameters for clarity (e.g., ca -> contextArgs) - Replace all Background()/TODO() calls with propagated context - Fix async loops and pagers to derive from parent context - Ensure cancellations interrupt in-flight SDK calls and Pulumi operations No functional logic changes besides enabling proper cancellation. This ensures Ctrl+C properly cancels in-flight operations while supporting library consumers who need custom context management. Signed-off-by: Jose Angel Morena <[email protected]>
1 parent cb86071 commit cd3e65f

File tree

64 files changed

+372
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+372
-294
lines changed

cmd/mapt/cmd/aws/hosts/fedora.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func getFedoraCreate() *cobra.Command {
4848
}
4949
return fedora.Create(
5050
&maptContext.ContextArgs{
51+
Context: cmd.Context(),
5152
ProjectName: viper.GetString(params.ProjectName),
5253
BackedURL: viper.GetString(params.BackedURL),
5354
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -91,6 +92,7 @@ func getFedoraDestroy() *cobra.Command {
9192
return err
9293
}
9394
return fedora.Destroy(&maptContext.ContextArgs{
95+
Context: cmd.Context(),
9496
ProjectName: viper.GetString(params.ProjectName),
9597
BackedURL: viper.GetString(params.BackedURL),
9698
Debug: viper.IsSet(params.Debug),

cmd/mapt/cmd/aws/hosts/mac.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func getMacRequest() *cobra.Command {
4141
}
4242
return mac.Request(
4343
&maptContext.ContextArgs{
44+
Context: cmd.Context(),
4445
ProjectName: viper.GetString(params.ProjectName),
4546
BackedURL: viper.GetString(params.BackedURL),
4647
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -81,6 +82,7 @@ func getMacRelease() *cobra.Command {
8182
}
8283
return mac.Release(
8384
&maptContext.ContextArgs{
85+
Context: cmd.Context(),
8486
Debug: viper.IsSet(params.Debug),
8587
DebugLevel: viper.GetUint(params.DebugLevel),
8688
},
@@ -107,6 +109,7 @@ func getMacDestroy() *cobra.Command {
107109
}
108110
return mac.Destroy(
109111
&maptContext.ContextArgs{
112+
Context: cmd.Context(),
110113
Debug: viper.IsSet(params.Debug),
111114
DebugLevel: viper.GetUint(params.DebugLevel),
112115
KeepState: viper.IsSet(params.KeepState),

cmd/mapt/cmd/aws/hosts/rhel.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func getRHELCreate() *cobra.Command {
4444
}
4545
return rhel.Create(
4646
&maptContext.ContextArgs{
47+
Context: cmd.Context(),
4748
ProjectName: viper.GetString(params.ProjectName),
4849
BackedURL: viper.GetString(params.BackedURL),
4950
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -94,6 +95,7 @@ func getRHELDestroy() *cobra.Command {
9495
return err
9596
}
9697
return rhel.Destroy(&maptContext.ContextArgs{
98+
Context: cmd.Context(),
9799
ProjectName: viper.GetString(params.ProjectName),
98100
BackedURL: viper.GetString(params.BackedURL),
99101
Debug: viper.IsSet(params.Debug),

cmd/mapt/cmd/aws/hosts/rhelai.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func getRHELAICreate() *cobra.Command {
4444
}
4545
return rhelai.Create(
4646
&maptContext.ContextArgs{
47+
Context: cmd.Context(),
4748
ProjectName: viper.GetString(params.ProjectName),
4849
BackedURL: viper.GetString(params.BackedURL),
4950
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -86,6 +87,7 @@ func getRHELAIDestroy() *cobra.Command {
8687
return err
8788
}
8889
return rhelai.Destroy(&maptContext.ContextArgs{
90+
Context: cmd.Context(),
8991
ProjectName: viper.GetString(params.ProjectName),
9092
BackedURL: viper.GetString(params.BackedURL),
9193
Debug: viper.IsSet(params.Debug),

cmd/mapt/cmd/aws/hosts/windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func getWindowsCreate() *cobra.Command {
5757
}
5858
return windows.Create(
5959
&maptContext.ContextArgs{
60+
Context: cmd.Context(),
6061
ProjectName: viper.GetString(params.ProjectName),
6162
BackedURL: viper.GetString(params.BackedURL),
6263
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -105,6 +106,7 @@ func getWindowsDestroy() *cobra.Command {
105106
return err
106107
}
107108
return windows.Destroy(&maptContext.ContextArgs{
109+
Context: cmd.Context(),
108110
ProjectName: viper.GetString(params.ProjectName),
109111
BackedURL: viper.GetString(params.BackedURL),
110112
Debug: viper.IsSet(params.Debug),

cmd/mapt/cmd/aws/services/eks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func getCreateEKS() *cobra.Command {
6060

6161
return awsEKS.Create(
6262
&maptContext.ContextArgs{
63+
Context: cmd.Context(),
6364
ProjectName: viper.GetString(params.ProjectName),
6465
BackedURL: viper.GetString(params.BackedURL),
6566
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -107,6 +108,7 @@ func getDestroyEKS() *cobra.Command {
107108
}
108109
return awsEKS.Destroy(
109110
&maptContext.ContextArgs{
111+
Context: cmd.Context(),
110112
ProjectName: viper.GetString(params.ProjectName),
111113
BackedURL: viper.GetString(params.BackedURL),
112114
Debug: viper.IsSet(params.Debug),

cmd/mapt/cmd/aws/services/kind.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func createKind() *cobra.Command {
5353

5454
if _, err := kind.Create(
5555
&maptContext.ContextArgs{
56+
Context: cmd.Context(),
5657
ProjectName: viper.GetString(params.ProjectName),
5758
BackedURL: viper.GetString(params.BackedURL),
5859
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -94,6 +95,7 @@ func destroyKind() *cobra.Command {
9495
return err
9596
}
9697
return kind.Destroy(&maptContext.ContextArgs{
98+
Context: cmd.Context(),
9799
ProjectName: viper.GetString(params.ProjectName),
98100
BackedURL: viper.GetString(params.BackedURL),
99101
Debug: viper.IsSet(params.Debug),

cmd/mapt/cmd/aws/services/mac-pool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func createMP() *cobra.Command {
5858
}
5959
return macpool.Create(
6060
&maptContext.ContextArgs{
61+
Context: cmd.Context(),
6162
ProjectName: viper.GetString(params.ProjectName),
6263
BackedURL: viper.GetString(params.BackedURL),
6364
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -98,6 +99,7 @@ func destroyMP() *cobra.Command {
9899
return err
99100
}
100101
return macpool.Destroy(&maptContext.ContextArgs{
102+
Context: cmd.Context(),
101103
ProjectName: viper.GetString(params.ProjectName),
102104
BackedURL: viper.GetString(params.BackedURL),
103105
Debug: viper.IsSet(params.Debug),
@@ -123,6 +125,7 @@ func houseKeep() *cobra.Command {
123125
}
124126
return macpool.HouseKeeper(
125127
&maptContext.ContextArgs{
128+
Context: cmd.Context(),
126129
ProjectName: viper.GetString(params.ProjectName),
127130
BackedURL: viper.GetString(params.BackedURL),
128131
Serverless: viper.IsSet(params.Serverless),
@@ -163,6 +166,7 @@ func request() *cobra.Command {
163166
}
164167
return macpool.Request(
165168
&maptContext.ContextArgs{
169+
Context: cmd.Context(),
166170
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
167171
Debug: viper.IsSet(params.Debug),
168172
DebugLevel: viper.GetUint(params.DebugLevel),
@@ -201,6 +205,7 @@ func release() *cobra.Command {
201205
}
202206
return macpool.Release(
203207
&maptContext.ContextArgs{
208+
Context: cmd.Context(),
204209
Debug: viper.IsSet(params.Debug),
205210
DebugLevel: viper.GetUint(params.DebugLevel),
206211
Serverless: viper.IsSet(params.Serverless),

cmd/mapt/cmd/aws/services/openshift-snc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func createSNC() *cobra.Command {
4848
}
4949
if _, err := openshiftsnc.Create(
5050
&maptContext.ContextArgs{
51+
Context: cmd.Context(),
5152
ProjectName: viper.GetString(params.ProjectName),
5253
BackedURL: viper.GetString(params.BackedURL),
5354
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -89,6 +90,7 @@ func destroySNC() *cobra.Command {
8990
return err
9091
}
9192
return openshiftsnc.Destroy(&maptContext.ContextArgs{
93+
Context: cmd.Context(),
9294
ProjectName: viper.GetString(params.ProjectName),
9395
BackedURL: viper.GetString(params.BackedURL),
9496
Debug: viper.IsSet(params.Debug),

cmd/mapt/cmd/azure/hosts/linux.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func getCreateLinux(ostype data.OSType, defaultOSVersion string) *cobra.Command
5252
}
5353
return azureLinux.Create(
5454
&maptContext.ContextArgs{
55+
Context: cmd.Context(),
5556
ProjectName: viper.GetString(params.ProjectName),
5657
BackedURL: viper.GetString(params.BackedURL),
5758
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
@@ -90,13 +91,13 @@ func getDestroyLinux() *cobra.Command {
9091
if err := viper.BindPFlags(cmd.Flags()); err != nil {
9192
return err
9293
}
93-
return azureLinux.Destroy(
94-
&maptContext.ContextArgs{
95-
ProjectName: viper.GetString(params.ProjectName),
96-
BackedURL: viper.GetString(params.BackedURL),
97-
Debug: viper.IsSet(params.Debug),
98-
DebugLevel: viper.GetUint(params.DebugLevel),
99-
})
94+
return azureLinux.Destroy(&maptContext.ContextArgs{
95+
Context: cmd.Context(),
96+
ProjectName: viper.GetString(params.ProjectName),
97+
BackedURL: viper.GetString(params.BackedURL),
98+
Debug: viper.IsSet(params.Debug),
99+
DebugLevel: viper.GetUint(params.DebugLevel),
100+
})
100101
},
101102
}
102103
}

0 commit comments

Comments
 (0)