@@ -26,7 +26,6 @@ import (
26
26
"google.golang.org/grpc/status"
27
27
28
28
"github.com/siderolabs/talos/cmd/talosctl/cmd/common"
29
- "github.com/siderolabs/talos/cmd/talosctl/pkg/talos/global"
30
29
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
31
30
machineapi "github.com/siderolabs/talos/pkg/machinery/api/machine"
32
31
"github.com/siderolabs/talos/pkg/machinery/client"
@@ -92,7 +91,7 @@ type Tracker struct {
92
91
timeout time.Duration
93
92
isTerminal bool
94
93
debug bool
95
- cliContext * global. Args
94
+ clientExecutor ClientExecutor
96
95
}
97
96
98
97
// TrackerOption is the functional option for the Tracker.
@@ -119,21 +118,28 @@ func WithDebug(debug bool) TrackerOption {
119
118
}
120
119
}
121
120
121
+ // WithTerminalOverride sets the terminal override.
122
+ func WithTerminalOverride (isTerminal bool ) TrackerOption {
123
+ return func (t * Tracker ) {
124
+ t .isTerminal = isTerminal
125
+ }
126
+ }
127
+
122
128
// NewTracker creates a new Tracker.
123
129
func NewTracker (
124
- cliContext * global. Args ,
130
+ clientExecutor ClientExecutor ,
125
131
expectedEventFn func (event client.EventResult ) bool ,
126
132
actionFn func (ctx context.Context , c * client.Client ) (string , error ),
127
133
opts ... TrackerOption ,
128
134
) * Tracker {
129
135
tracker := Tracker {
130
136
expectedEventFn : expectedEventFn ,
131
137
actionFn : actionFn ,
132
- nodeToLatestStatusUpdate : make (map [string ]reporter.Update , len (cliContext . Nodes )),
138
+ nodeToLatestStatusUpdate : make (map [string ]reporter.Update , len (clientExecutor . NodeList () )),
133
139
reporter : reporter .New (),
134
140
reportCh : make (chan nodeUpdate ),
135
141
isTerminal : isatty .IsTerminal (os .Stderr .Fd ()),
136
- cliContext : cliContext ,
142
+ clientExecutor : clientExecutor ,
137
143
}
138
144
139
145
for _ , option := range opts {
@@ -143,6 +149,12 @@ func NewTracker(
143
149
return & tracker
144
150
}
145
151
152
+ // ClientExecutor is the interface for the client executor.
153
+ type ClientExecutor interface {
154
+ WithClient (action func (context.Context , * client.Client ) error , dialOptions ... grpc.DialOption ) error
155
+ NodeList () []string
156
+ }
157
+
146
158
// Run executes the action on nodes and tracks its progress by watching events with retries.
147
159
// After receiving the expected event, if provided, it tracks the progress by running the post check with retries.
148
160
//
@@ -152,7 +164,7 @@ func (a *Tracker) Run() error {
152
164
153
165
var eg errgroup.Group
154
166
155
- err := a .cliContext .WithClient (func (ctx context.Context , c * client.Client ) error {
167
+ err := a .clientExecutor .WithClient (func (ctx context.Context , c * client.Client ) error {
156
168
ctx , cancel := context .WithTimeout (ctx , a .timeout )
157
169
defer cancel ()
158
170
@@ -170,7 +182,7 @@ func (a *Tracker) Run() error {
170
182
171
183
var trackEg errgroup.Group
172
184
173
- for _ , node := range a .cliContext . Nodes {
185
+ for _ , node := range a .clientExecutor . NodeList () {
174
186
var (
175
187
dmesg * circular.Buffer
176
188
err error
0 commit comments