Skip to content

Thread a real context through phase DryRun - #1152

Open
magic-peach wants to merge 1 commit into
k0sproject:mainfrom
magic-peach:fix/disconnect-dryrun-context
Open

Thread a real context through phase DryRun#1152
magic-peach wants to merge 1 commit into
k0sproject:mainfrom
magic-peach:fix/disconnect-dryrun-context

Conversation

@magic-peach

Copy link
Copy Markdown

withDryRun.DryRun() took no context, so every implementer called p.Run(context.TODO()) or similar instead of the real context the phase manager already has in scope.

Changed DryRun() error to DryRun(context.Context) error across all 8 implementers and manager.go, threading the real context through instead.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 withDryRun interface from DryRun() error to DryRun(context.Context) error.
  • Threaded the manager’s ctx into dry-run execution (Manager.Run) and across all existing DryRun implementers.
  • 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 thread phase/disconnect.go
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
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants