Skip to content

Commit cfd1459

Browse files
ihexonBlackHole1
authored andcommitted
refactor(machine): ssh service support ctx
1 parent a30b46e commit cfd1459

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

cmd/bauklotze/machine/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func start(cmd *cobra.Command, args []string) error {
155155

156156
// Start Sleep Notifier and dispatch tasks
157157
logrus.Infof("Start Sleep Notifier and dispatch tasks")
158-
go shim.SleepNotifier(mc)
158+
go shim.SleepNotifier(ctx, mc)
159159

160160
if err = mc.UpdateLastBoot(); err != nil {
161161
logrus.Errorf("failed to update last boot time: %v", err)

pkg/machine/shim/host.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,23 @@ func Start(ctx context.Context, mc *vmconfig.MachineConfig) (context.Context, er
209209
}
210210

211211
// SleepNotifier start Sleep Notifier and dispatch tasks
212-
func SleepNotifier(mc *vmconfig.MachineConfig) {
212+
func SleepNotifier(ctx context.Context, mc *vmconfig.MachineConfig) {
213213
notifierCh := notifier.GetInstance().Start()
214214
for { //nolint:gosimple
215215
select {
216216
case activity := <-notifierCh:
217217
if activity.Type == notifier.Awake {
218218
logrus.Infof("machine awake, dispatch tasks")
219-
if err := TimeSync(mc); err != nil {
219+
if err := TimeSync(ctx, mc); err != nil {
220220
logrus.Errorf("Failed to sync timestamp: %v", err)
221221
}
222222
}
223223
}
224224
}
225225
}
226226

227-
func TimeSync(mc *vmconfig.MachineConfig) error {
228-
return sshService.DoTimeSync(mc) //nolint:wrapcheck
227+
func TimeSync(ctx context.Context, mc *vmconfig.MachineConfig) error {
228+
return sshService.DoTimeSync(ctx, mc) //nolint:wrapcheck
229229
}
230230

231231
func DiskSync(mc *vmconfig.MachineConfig) error {

pkg/machine/shim/networking.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func ConductVMReadinessCheck(ctx context.Context, mc *vmconfig.MachineConfig) bo
3232
time.Sleep(defaultBackoff)
3333
}
3434

35-
if err := sshService.GetKernelInfo(mc); err != nil {
35+
if err := sshService.GetKernelInfo(ctx, mc); err != nil {
3636
logrus.Warnf("SSH readiness check for machine failed: %v, try again", err)
3737
continue
3838
}

pkg/machine/ssh/service/service.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
package service
55

66
import (
7+
"context"
78
"fmt"
89
"time"
910

1011
"bauklotze/pkg/machine/vmconfig"
1112
)
1213

13-
func GetKernelInfo(mc *vmconfig.MachineConfig) error {
14-
return run(mc, "uname", []string{
14+
func GetKernelInfo(ctx context.Context, mc *vmconfig.MachineConfig) error {
15+
return runCtx(ctx, mc, "uname", []string{
1516
"-a",
1617
})
1718
}
1819

19-
func DoTimeSync(mc *vmconfig.MachineConfig) error {
20-
return run(mc, "date", []string{
20+
func DoTimeSync(ctx context.Context, mc *vmconfig.MachineConfig) error {
21+
return runCtx(ctx, mc, "date", []string{
2122
"-s",
2223
fmt.Sprintf("@%d", time.Now().Unix()),
2324
})

0 commit comments

Comments
 (0)