Skip to content

Commit 84757c2

Browse files
committed
refactor(engine): drop unused ctx parameter from FullConfigProcess
FullConfigProcess took a context.Context that it never observed — the function performs no I/O respecting cancellation. The "_" parameter masked an honest API: callers were passing live contexts to a function that discarded them, which is misleading review surface. Drop the parameter from FullConfigProcess and propagate to its two callers (apply.applyOneFileDirectPatchMode, upgrade_handler) plus the four FullConfigProcess contract tests. The upgrade handler also drops a now-orphaned context.Background() allocation and the unused "context" import; the apply path drops the now-unused ctx threading down to applyOneFileDirectPatchMode which had been carrying it for this single FullConfigProcess call. If a future configpatcher needs cancellation, reintroduce ctx typed as the first argument. Signed-off-by: Aleksei Sviridkin <f@lex.la>
1 parent 0f565e7 commit 84757c2

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

pkg/commands/upgrade_handler.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package commands
1616

1717
import (
18-
"context"
1918
"fmt"
2019
"os"
2120

@@ -94,7 +93,6 @@ func wrapUpgradeCommand(wrappedCmd *cobra.Command, originalRunE func(*cobra.Comm
9493
}
9594

9695
// Process config to extract image
97-
ctx := context.Background()
9896
eopts := engine.Options{
9997
TalosVersion: talosVersion,
10098
WithSecrets: withSecrets,
@@ -103,7 +101,7 @@ func wrapUpgradeCommand(wrappedCmd *cobra.Command, originalRunE func(*cobra.Comm
103101

104102
patches := []string{"@" + configFile}
105103

106-
configBundle, machineType, err := engine.FullConfigProcess(ctx, eopts, patches)
104+
configBundle, machineType, err := engine.FullConfigProcess(eopts, patches)
107105
if err != nil {
108106
return errors.Wrap(err, "full config processing error")
109107
}

pkg/engine/contract_render_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func TestContract_SerializeConfiguration_ControlplaneVsWorker(t *testing.T) {
266266
// machine.TypeUnknown — a reduced state operators do not normally
267267
// reach.
268268
func TestContract_FullConfigProcess_NoPatchesUsesBundleDefault(t *testing.T) {
269-
bundle, mtype, err := FullConfigProcess(context.Background(), Options{}, nil)
269+
bundle, mtype, err := FullConfigProcess(Options{}, nil)
270270
if err != nil {
271271
t.Fatalf("FullConfigProcess: %v", err)
272272
}
@@ -286,7 +286,7 @@ func TestContract_FullConfigProcess_NoPatchesUsesBundleDefault(t *testing.T) {
286286
// own machineType inference does not interfere.
287287
func TestContract_FullConfigProcess_ControlplaneFromPatch(t *testing.T) {
288288
patch := "machine:\n type: controlplane\n"
289-
_, mtype, err := FullConfigProcess(context.Background(), Options{}, []string{patch})
289+
_, mtype, err := FullConfigProcess(Options{}, []string{patch})
290290
if err != nil {
291291
t.Fatalf("FullConfigProcess: %v", err)
292292
}
@@ -300,7 +300,7 @@ func TestContract_FullConfigProcess_ControlplaneFromPatch(t *testing.T) {
300300
// silently swallows malformed patches surfaces here.
301301
func TestContract_FullConfigProcess_MalformedPatchError(t *testing.T) {
302302
bad := "this is not valid YAML\n : :"
303-
_, _, err := FullConfigProcess(context.Background(), Options{}, []string{bad})
303+
_, _, err := FullConfigProcess(Options{}, []string{bad})
304304
if err == nil {
305305
t.Fatal("expected error for malformed patch")
306306
}
@@ -309,7 +309,7 @@ func TestContract_FullConfigProcess_MalformedPatchError(t *testing.T) {
309309
// Contract: FullConfigProcess with a malformed TalosVersion option
310310
// surfaces InitializeConfigBundle's error path.
311311
func TestContract_FullConfigProcess_BadTalosVersionError(t *testing.T) {
312-
_, _, err := FullConfigProcess(context.Background(), Options{TalosVersion: "garbage"}, nil)
312+
_, _, err := FullConfigProcess(Options{TalosVersion: "garbage"}, nil)
313313
if err == nil {
314314
t.Fatal("expected error")
315315
}

pkg/engine/engine.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,14 @@ func debugPhase(opts Options, patches []string, clusterName string, clusterEndpo
120120

121121
// FullConfigProcess handles the full process of creating and updating the Bundle.
122122
//
123+
// The function performs no I/O that would respect a context; the
124+
// ctx parameter that callers used to pass in was always discarded
125+
// inside. Dropping the parameter makes the contract honest. If a
126+
// future caller needs cancellation (e.g. a future remote
127+
// configpatcher), reintroduce it as a typed first argument.
128+
//
123129
//nolint:gocritic // hugeParam: Options is the package's public facing configuration carrier; converting this to a pointer would propagate the change across every caller in pkg/commands and break the API for external consumers.
124-
func FullConfigProcess(_ context.Context, opts Options, patches []string) (*bundle.Bundle, machine.Type, error) {
130+
func FullConfigProcess(opts Options, patches []string) (*bundle.Bundle, machine.Type, error) {
125131
configBundle, err := InitializeConfigBundle(opts)
126132
if err != nil {
127133
return nil, machine.TypeUnknown, errors.Wrap(err, "initial config bundle error")

0 commit comments

Comments
 (0)