Skip to content

Commit 9666cd0

Browse files
committed
propogate context
1 parent edaca01 commit 9666cd0

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

cmd/lk/agent.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func createAgentConfig(ctx context.Context, cmd *cli.Command) error {
478478
if configExists && lkConfig.HasAgent() {
479479
agentID = lkConfig.Agent.ID
480480
} else {
481-
agentID, err = selectAgent(cmd, false)
481+
agentID, err = selectAgent(ctx, cmd, false)
482482
if err != nil {
483483
return err
484484
}
@@ -704,7 +704,7 @@ func updateAgent(ctx context.Context, cmd *cli.Command) error {
704704
}
705705

706706
var resp *lkproto.UpdateAgentResponse
707-
err = util.Await("Updating agent ["+util.Accented(lkConfig.Agent.ID)+"]", func(ctx context.Context) error {
707+
err = util.Await("Updating agent ["+util.Accented(lkConfig.Agent.ID)+"]", ctx, func(ctx context.Context) error {
708708
var clientErr error
709709
resp, clientErr = agentsClient.UpdateAgent(ctx, req)
710710
return clientErr
@@ -734,7 +734,7 @@ func rollbackAgent(ctx context.Context, cmd *cli.Command) error {
734734
}
735735

736736
var resp *lkproto.RollbackAgentResponse
737-
err = util.Await("Rolling back agent ["+util.Accented(agentID)+"]", func(ctx context.Context) error {
737+
err = util.Await("Rolling back agent ["+util.Accented(agentID)+"]", ctx, func(ctx context.Context) error {
738738
var clientErr error
739739
resp, clientErr = agentsClient.RollbackAgent(ctx, &lkproto.RollbackAgentRequest{
740740
AgentId: agentID,
@@ -796,6 +796,7 @@ func deleteAgent(ctx context.Context, cmd *cli.Command) error {
796796
var res *lkproto.DeleteAgentResponse
797797
err = util.Await(
798798
"Deleting agent ["+util.Accented(agentID)+"]",
799+
ctx,
799800
func(ctx context.Context) error {
800801
var clientErr error
801802
res, clientErr = agentsClient.DeleteAgent(ctx, &lkproto.DeleteAgentRequest{
@@ -1010,7 +1011,7 @@ func getAgentID(ctx context.Context, cmd *cli.Command, agentDir string, tomlFile
10101011
}
10111012
agentID = lkConfig.Agent.ID
10121013
} else {
1013-
agentID, err = selectAgent(cmd, excludeEmptyVersion)
1014+
agentID, err = selectAgent(ctx, cmd, excludeEmptyVersion)
10141015
if err != nil {
10151016
return "", err
10161017
}
@@ -1027,10 +1028,10 @@ func getAgentID(ctx context.Context, cmd *cli.Command, agentDir string, tomlFile
10271028
return agentID, nil
10281029
}
10291030

1030-
func selectAgent(_ *cli.Command, excludeEmptyVersion bool) (string, error) {
1031+
func selectAgent(ctx context.Context, _ *cli.Command, excludeEmptyVersion bool) (string, error) {
10311032
var agents *lkproto.ListAgentsResponse
10321033

1033-
err := util.Await("No agent ID provided, selecting from available agents...", func(ctx context.Context) error {
1034+
err := util.Await("No agent ID provided, selecting from available agents...", ctx, func(ctx context.Context) error {
10341035
var clientErr error
10351036
agents, clientErr = agentsClient.ListAgents(ctx, &lkproto.ListAgentsRequest{})
10361037
return clientErr
@@ -1131,7 +1132,7 @@ func requireSecrets(_ context.Context, cmd *cli.Command, required, lazy bool) ([
11311132
return secretsSlice, nil
11321133
}
11331134

1134-
func requireDockerfile(_ context.Context, cmd *cli.Command, workingDir string, projectType agentfs.ProjectType, settingsMap map[string]string) error {
1135+
func requireDockerfile(ctx context.Context, cmd *cli.Command, workingDir string, projectType agentfs.ProjectType, settingsMap map[string]string) error {
11351136
dockerfileExists, err := agentfs.HasDockerfile(workingDir)
11361137
if err != nil {
11371138
return err
@@ -1141,6 +1142,7 @@ func requireDockerfile(_ context.Context, cmd *cli.Command, workingDir string, p
11411142
if !cmd.Bool("silent") {
11421143
err := util.Await(
11431144
"Creating Dockerfile...",
1145+
ctx,
11441146
func(ctx context.Context) error {
11451147
return agentfs.CreateDockerfile(workingDir, projectType, settingsMap)
11461148
},
@@ -1170,6 +1172,7 @@ func getClientSettings(ctx context.Context, silent bool) (map[string]string, err
11701172
if !silent {
11711173
err = util.Await(
11721174
"Loading client settings...",
1175+
ctx,
11731176
func(ctx context.Context) error {
11741177
clientSettingsResponse, err = agentsClient.GetClientSettings(ctx, &lkproto.ClientSettingsRequest{})
11751178
return err

cmd/lk/app.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func setupTemplate(ctx context.Context, cmd *cli.Command) error {
386386
return cleanupTemplate(ctx, cmd, appName)
387387
}
388388

389-
func cloneTemplate(_ context.Context, cmd *cli.Command, url, appName string) error {
389+
func cloneTemplate(ctx context.Context, cmd *cli.Command, url, appName string) error {
390390
var stdout string
391391
var stderr string
392392

@@ -395,6 +395,7 @@ func cloneTemplate(_ context.Context, cmd *cli.Command, url, appName string) err
395395

396396
err := util.Await(
397397
"Cloning template from "+url,
398+
ctx,
398399
func(ctx context.Context) error {
399400
var cmdErr error
400401
stdout, stderr, cmdErr = bootstrap.CloneTemplate(url, tempName)
@@ -516,6 +517,7 @@ func doInstall(ctx context.Context, task bootstrap.KnownTask, rootPath string, v
516517

517518
err = util.Await(
518519
"Installing...",
520+
ctx,
519521
func(ctx context.Context) error {
520522
return install()
521523
},

cmd/lk/cloud.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ func tryAuthIfNeeded(ctx context.Context, cmd *cli.Command) error {
302302
var ak *ClaimAccessKeyResponse
303303
err = util.Await(
304304
"Awaiting confirmation...",
305+
ctx,
305306
func(ctx context.Context) error {
306307
var pollErr error
307308
ak, pollErr = pollClaim(ctx, cmd)

pkg/util/action.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import (
2121
)
2222

2323
// Call an action and show a spinner while waiting for it to finish.
24-
func Await(title string, action func(ctx context.Context) error) error {
24+
func Await(title string, ctx context.Context, action func(ctx context.Context) error) error {
2525
return spinner.New().
2626
Title(" " + title).
2727
ActionWithErr(action).
2828
Type(spinner.Pulse).
2929
Style(Theme.Focused.Title).
30+
Context(ctx).
3031
Run()
3132
}

0 commit comments

Comments
 (0)