Thread a real context through phase DryRun - #1152
Open
magic-peach wants to merge 1 commit into
Open
Conversation
Disconnect.DryRun called p.Run(context.TODO()) and used context.Background() for its host cleanup, detached from the context that phase.Manager already has in scope while running phases. InstallBinaries and StageBinaries had the same context.Background() pattern in their DryRun paths. Add context.Context to the withDryRun interface and pass the manager's own ctx through to all DryRun implementations, so dry-run phases respect the same cancellation/deadline as a real run. Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the phase dry-run mechanism to accept and use the real context.Context already owned by the phase manager, avoiding ad-hoc context.Background()/context.TODO() usage inside DryRun() implementations.
Changes:
- Updated the
withDryRuninterface fromDryRun() errortoDryRun(context.Context) error. - Threaded the manager’s
ctxinto dry-run execution (Manager.Run) and across all existingDryRunimplementers. - Replaced some prior
context.Background()/context.TODO()dry-run invocations with the passed-through context.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| phase/manager.go | Updates the withDryRun interface and passes manager ctx into DryRun(ctx). |
| phase/stage_binaries.go | Uses the passed ctx when invoking Run from DryRun. |
| phase/install_binaries.go | Uses the passed ctx for parallelDo during DryRun. |
| phase/disconnect.go | Threads ctx through ParallelEach and Run in DryRun. |
| phase/reset_workers.go | Updates DryRun signature to accept context.Context (unused). |
| phase/reset_leader.go | Updates DryRun signature to accept context.Context (unused). |
| phase/reset_controllers.go | Updates DryRun signature to accept context.Context (unused). |
| phase/get_kubeconfig.go | Updates DryRun signature to accept context.Context (unused). |
| phase/configure_k0s.go | Updates DryRun signature to accept context.Context (unused). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+20
to
27
| func (p *Disconnect) DryRun(ctx context.Context) error { | ||
| _ = p.Config.Spec.Hosts.ParallelEach(ctx, func(_ context.Context, h *cluster.Host) error { | ||
| if h.Metadata.K0sBinaryTempFile != "" && h.FS().FileExist(h.Metadata.K0sBinaryTempFile) { | ||
| _ = h.Sudo().FS().Remove(h.Metadata.K0sBinaryTempFile) | ||
| } | ||
| h.Metadata.K0sBinaryTempFile = "" | ||
| return nil | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
withDryRun.DryRun()took no context, so every implementer calledp.Run(context.TODO())or similar instead of the real context the phase manager already has in scope.Changed
DryRun() errortoDryRun(context.Context) erroracross all 8 implementers andmanager.go, threading the real context through instead.