Skip to content

Commit 7cf1de2

Browse files
committed
fix: bring in new version of go-cmd and go-blockdevice
See: * siderolabs/go-blockdevice#147 * siderolabs/go-cmd#9 Lots of changes through the code as I deprecated `Run`, `RunWithContext` methods and allow only new `RunWithOptions` to clean up the library usage. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent c8800b4 commit 7cf1de2

File tree

30 files changed

+149
-127
lines changed

30 files changed

+149
-127
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ require (
140140
github.com/siderolabs/discovery-client v0.1.13
141141
github.com/siderolabs/gen v0.8.6
142142
github.com/siderolabs/go-api-signature v0.3.12
143-
github.com/siderolabs/go-blockdevice/v2 v2.0.24
143+
github.com/siderolabs/go-blockdevice/v2 v2.0.25
144144
github.com/siderolabs/go-circular v0.2.3
145-
github.com/siderolabs/go-cmd v0.1.3
145+
github.com/siderolabs/go-cmd v0.2.0
146146
github.com/siderolabs/go-copy v0.1.0
147147
github.com/siderolabs/go-debug v0.6.2
148148
github.com/siderolabs/go-kmsg v0.1.4

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,12 @@ github.com/siderolabs/gen v0.8.6 h1:pE6shuqov3L+5rEcAUJ/kY6iJofimljQw5G95P8a5c4=
628628
github.com/siderolabs/gen v0.8.6/go.mod h1:J9IbusbES2W6QWjtSHpDV9iPGZHc978h1+KJ4oQRspQ=
629629
github.com/siderolabs/go-api-signature v0.3.12 h1:i1X+kPh9fzo+lEjtEplZSbtq1p21vKv4FCWJcB/ozvk=
630630
github.com/siderolabs/go-api-signature v0.3.12/go.mod h1:dPLiXohup4qHX7KUgF/wwOE3lRU5uAr3ssEomNxiyxY=
631-
github.com/siderolabs/go-blockdevice/v2 v2.0.24 h1:40e2Ty1u+A5if47NcIZI2j1ie4MZD5xxJbztpplYVGs=
632-
github.com/siderolabs/go-blockdevice/v2 v2.0.24/go.mod h1:8J8R+5PG4+oTq1g9zTYKFMikBx01U6gTPc5NKo7BEV8=
631+
github.com/siderolabs/go-blockdevice/v2 v2.0.25 h1:itUZVY68iINZJS3Dcz3NZMWReT4WybLGkuZZSUW5l+0=
632+
github.com/siderolabs/go-blockdevice/v2 v2.0.25/go.mod h1:a6KUjzyU8Joo7y9cW9BdmORCFJwVNweHYRpKiuDfMU8=
633633
github.com/siderolabs/go-circular v0.2.3 h1:GKkA1Tw79kEFGtWdl7WTxEUTbwtklITeiRT0V1McHrA=
634634
github.com/siderolabs/go-circular v0.2.3/go.mod h1:YBN/q9YpQphUYnBtBgPsngauSHj1TEZfgQZWZVjk1WE=
635-
github.com/siderolabs/go-cmd v0.1.3 h1:JrgZwqhJQeoec3QRON0LK+fv+0y7d0DyY7zsfkO6ciw=
636-
github.com/siderolabs/go-cmd v0.1.3/go.mod h1:bg7HY4mRNu4zKebAgUevSwuYNtcvPMJfuhLRkVKHZ0k=
635+
github.com/siderolabs/go-cmd v0.2.0 h1:fZ0jbQzZg4bFLmJzNEDZM/RlebZsfHOo2k+PCJ6g7y4=
636+
github.com/siderolabs/go-cmd v0.2.0/go.mod h1:YA/UEDh8Av84RlI4LfQw7HN9+vgxUrQw/Byef1dgptY=
637637
github.com/siderolabs/go-copy v0.1.0 h1:OIWCtSg+rhOtnIZTpT31Gfpn17rv5kwJqQHG+QUEgC8=
638638
github.com/siderolabs/go-copy v0.1.0/go.mod h1:4bF2rZOZAR/ags/U4AVSpjFE5RPGdEeSkOq6yR9YOkU=
639639
github.com/siderolabs/go-debug v0.6.2 h1:zWWMTcrYDVyiNTotSxEVg++hj9mb2ctuTNVnOeCWtO8=

internal/app/machined/pkg/controllers/block/disks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func serialFromUdevdHelpers(ctx context.Context, id, transport string) string {
284284
}
285285

286286
func runUdevdHelper(ctx context.Context, helper string, args ...string) string {
287-
out, err := cmd.RunContext(ctx, helper, args...)
287+
out, err := cmd.RunWithOptions(ctx, helper, args)
288288
if err != nil {
289289
return ""
290290
}

internal/app/machined/pkg/controllers/block/internal/volumes/format.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func Format(ctx context.Context, logger *zap.Logger, volumeContext ManagerContex
8080
// filesystem already exists and matches the requested type
8181
if volumeContext.Cfg.TypedSpec().Provisioning.PartitionSpec.Grow {
8282
// if the partition is set to grow, we need to grow the filesystem
83-
if err = GrowFilesystem(logger, volumeContext); err != nil {
83+
if err = GrowFilesystem(ctx, logger, volumeContext); err != nil {
8484
return fmt.Errorf("error growing filesystem: %w", err)
8585
}
8686
}
@@ -145,7 +145,7 @@ func Format(ctx context.Context, logger *zap.Logger, volumeContext ManagerContex
145145
}
146146

147147
// GrowFilesystem grows the filesystem on the block device.
148-
func GrowFilesystem(logger *zap.Logger, volumeContext ManagerContext) error {
148+
func GrowFilesystem(ctx context.Context, logger *zap.Logger, volumeContext ManagerContext) error {
149149
switch volumeContext.Cfg.TypedSpec().Provisioning.FilesystemSpec.Type { //nolint:exhaustive
150150
case block.FilesystemTypeXFS:
151151
// XFS requires partition to be mounted to grow
@@ -173,15 +173,15 @@ func GrowFilesystem(logger *zap.Logger, volumeContext ManagerContext) error {
173173

174174
logger.Info("growing XFS filesystem", zap.String("device", volumeContext.Status.MountLocation))
175175

176-
if err = makefs.XFSGrow(tmpDir); err != nil {
176+
if err = makefs.XFSGrow(ctx, tmpDir); err != nil {
177177
return fmt.Errorf("error growing XFS: %w", err)
178178
}
179179

180180
return nil
181181
case block.FilesystemTypeEXT4:
182182
logger.Info("growing ext4 filesystem", zap.String("device", volumeContext.Status.MountLocation))
183183

184-
if err := makefs.Ext4Resize(volumeContext.Status.MountLocation); err != nil {
184+
if err := makefs.Ext4Resize(ctx, volumeContext.Status.MountLocation); err != nil {
185185
return fmt.Errorf("error growing ext4: %w", err)
186186
}
187187

internal/app/machined/pkg/controllers/block/lvm.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ func (ctrl *LVMActivationController) Run(ctx context.Context, r controller.Runti
162162
logger.Info("activating LVM volume", zap.String("name", vgName))
163163

164164
// activate the volume group
165-
if _, err = cmd.RunContext(ctx,
165+
if _, err = cmd.RunWithOptions(ctx,
166166
"/sbin/lvm",
167-
"vgchange",
168-
"-aay",
169-
"--autoactivation",
170-
"event",
171-
vgName,
167+
[]string{
168+
"vgchange",
169+
"-aay",
170+
"--autoactivation",
171+
"event",
172+
vgName,
173+
},
172174
); err != nil {
173175
multiErr = multierror.Append(multiErr, fmt.Errorf("failed to activate LVM volume %s: %w", vgName, err))
174176
} else {
@@ -187,17 +189,19 @@ func (ctrl *LVMActivationController) Run(ctx context.Context, r controller.Runti
187189
func (ctrl *LVMActivationController) checkVGNeedsActivation(ctx context.Context, devicePath string) (string, error) {
188190
// first we check if all associated volumes are available
189191
// https://man7.org/linux/man-pages/man7/lvmautoactivation.7.html
190-
stdOut, err := cmd.RunContext(ctx,
192+
stdOut, err := cmd.RunWithOptions(ctx,
191193
"/sbin/lvm",
192-
"pvscan",
193-
"--cache",
194-
"--listvg",
195-
"--checkcomplete",
196-
"--vgonline",
197-
"--autoactivation",
198-
"event",
199-
"--udevoutput",
200-
devicePath,
194+
[]string{
195+
"pvscan",
196+
"--cache",
197+
"--listvg",
198+
"--checkcomplete",
199+
"--vgonline",
200+
"--autoactivation",
201+
"event",
202+
"--udevoutput",
203+
devicePath,
204+
},
201205
)
202206
if err != nil {
203207
return "", fmt.Errorf("failed to check if LVM volume backed by device %s needs activation: %w", devicePath, err)

internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub/install.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package grub
66

77
import (
8+
"context"
89
"fmt"
910
"io"
1011
"os"
@@ -74,7 +75,7 @@ func (c *Config) Install(opts options.InstallOptions) (*options.InstallResult, e
7475
opts.BootDisk,
7576
mountSpecs,
7677
func() error {
77-
if err := c.runGrubInstall(opts, efiFound); err != nil {
78+
if err := c.runGrubInstall(context.Background(), opts, efiFound); err != nil {
7879
return err
7980
}
8081

@@ -94,7 +95,7 @@ func (c *Config) Install(opts options.InstallOptions) (*options.InstallResult, e
9495
}, err
9596
}
9697

97-
func (c *Config) generateGrubImage(opts options.InstallOptions) error {
98+
func (c *Config) generateGrubImage(ctx context.Context, opts options.InstallOptions) error {
9899
var copyInstructions []utils.CopyInstruction
99100

100101
grubSourceDirectory := "/usr/lib/grub"
@@ -141,9 +142,10 @@ func (c *Config) generateGrubImage(opts options.InstallOptions) error {
141142

142143
args = append(args, slices.Concat(grubModules, grub32Modules)...)
143144

144-
if _, err := cmd.Run(
145+
if _, err := cmd.RunWithOptions(
146+
ctx,
145147
"grub-mkimage",
146-
args...,
148+
args,
147149
); err != nil {
148150
return fmt.Errorf("failed to generate grub core image: %w", err)
149151
}
@@ -180,9 +182,10 @@ func (c *Config) generateGrubImage(opts options.InstallOptions) error {
180182
}
181183
args = append(args, grubModules...)
182184

183-
if _, err := cmd.Run(
185+
if _, err := cmd.RunWithOptions(
186+
ctx,
184187
"grub-mkimage",
185-
args...,
188+
args,
186189
); err != nil {
187190
return fmt.Errorf("failed to generate grub efi image: %w", err)
188191
}
@@ -282,14 +285,14 @@ func (c *Config) generateAssets(opts options.InstallOptions) error {
282285
}
283286

284287
if opts.ImageMode {
285-
return c.generateGrubImage(opts)
288+
return c.generateGrubImage(context.Background(), opts)
286289
}
287290

288291
return nil
289292
}
290293

291294
//nolint:gocyclo
292-
func (c *Config) runGrubInstall(opts options.InstallOptions, efiMode bool) error {
295+
func (c *Config) runGrubInstall(ctx context.Context, opts options.InstallOptions, efiMode bool) error {
293296
var platforms []string
294297

295298
switch opts.Arch {
@@ -330,7 +333,7 @@ func (c *Config) runGrubInstall(opts options.InstallOptions, efiMode bool) error
330333

331334
opts.Printf("executing: grub-install %s", strings.Join(args, " "))
332335

333-
if _, err := cmd.Run("grub-install", args...); err != nil {
336+
if _, err := cmd.RunWithOptions(ctx, "grub-install", args); err != nil {
334337
return fmt.Errorf("failed to install grub: %w", err)
335338
}
336339
}

internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub/upgrade.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package grub
66

77
import (
8+
"context"
89
"path/filepath"
910

1011
"github.com/siderolabs/go-blockdevice/v2/blkid"
@@ -66,7 +67,7 @@ func (c *Config) Upgrade(opts options.InstallOptions) (*options.InstallResult, e
6667
return err
6768
}
6869

69-
if err := c.runGrubInstall(opts, efiFound); err != nil {
70+
if err := c.runGrubInstall(context.Background(), opts, efiFound); err != nil {
7071
return err
7172
}
7273

internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,22 +294,22 @@ func WriteUdevRules(runtime.Sequence, any) (runtime.TaskExecutionFunc, string) {
294294
}
295295

296296
if len(rules) > 0 {
297-
if _, err := cmd.RunContext(ctx, "/sbin/udevadm", "control", "--reload"); err != nil {
297+
if _, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"control", "--reload"}); err != nil {
298298
return err
299299
}
300300

301-
if _, err := cmd.RunContext(ctx, "/sbin/udevadm", "trigger", "--type=devices", "--action=add"); err != nil {
301+
if _, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"trigger", "--type=devices", "--action=add"}); err != nil {
302302
return err
303303
}
304304

305-
if _, err := cmd.RunContext(ctx, "/sbin/udevadm", "trigger", "--type=subsystems", "--action=add"); err != nil {
305+
if _, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"trigger", "--type=subsystems", "--action=add"}); err != nil {
306306
return err
307307
}
308308

309309
// This ensures that `udevd` finishes processing kernel events, triggered by
310310
// `udevd trigger`, to prevent a race condition when a user specifies a path
311311
// under `/dev/disk/*` in any disk definitions.
312-
_, err := cmd.RunContext(ctx, "/sbin/udevadm", "settle", "--timeout=50")
312+
_, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"settle", "--timeout=50"})
313313

314314
return err
315315
}

internal/app/machined/pkg/system/services/udevd.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ func (c *Udevd) ID(runtime.Runtime) string {
4040

4141
// PreFunc implements the Service interface.
4242
func (c *Udevd) PreFunc(ctx context.Context, r runtime.Runtime) error {
43-
_, err := cmd.RunContext(
44-
ctx,
45-
"/sbin/udevadm",
46-
"hwdb",
47-
"--update",
48-
"--root=/usr",
49-
)
43+
_, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"hwdb", "--update", "--root=/usr"})
5044

5145
return err
5246
}
@@ -118,16 +112,16 @@ func (c *Udevd) HealthFunc(runtime.Runtime) health.Check {
118112
// udevadm trigger returns with an exit code of 0 even if udevd is not fully running,
119113
// so running `udevadm control --reload` to ensure that udevd is fully initialized
120114
// which returns an exit code of 2 if udevd is not running. This complements the previous check
121-
if _, err := cmd.RunContext(ctx, "/sbin/udevadm", "control", "--reload"); err != nil {
115+
if _, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"control", "--reload"}); err != nil {
122116
return err
123117
}
124118

125119
if !c.triggered {
126-
if _, err := cmd.RunContext(ctx, "/sbin/udevadm", "trigger", "--type=devices", "--action=add"); err != nil {
120+
if _, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"trigger", "--type=devices", "--action=add"}); err != nil {
127121
return err
128122
}
129123

130-
if _, err := cmd.RunContext(ctx, "/sbin/udevadm", "trigger", "--type=subsystems", "--action=add"); err != nil {
124+
if _, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"trigger", "--type=subsystems", "--action=add"}); err != nil {
131125
return err
132126
}
133127

@@ -137,7 +131,7 @@ func (c *Udevd) HealthFunc(runtime.Runtime) health.Check {
137131
// This ensures that `udevd` finishes processing kernel events, triggered by
138132
// `udevd trigger`, to prevent a race condition when a user specifies a path
139133
// under `/dev/disk/*` in any disk definitions.
140-
_, err := cmd.RunContext(ctx, "/sbin/udevadm", "settle", "--timeout=50") // timeout here should be less than health.Settings.Timeout
134+
_, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"settle", "--timeout=50"}) // timeout here should be less than health.Settings.Timeout
141135
if err != nil {
142136
return err
143137
}

internal/integration/base/cli.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,18 @@ func (cliSuite *CLISuite) discoverKubectl() cluster.Info {
8585
// rely on `nodes:` being set in talosconfig
8686
cliSuite.RunCLI([]string{"kubeconfig", tempDir}, StdoutEmpty())
8787

88-
masterNodes, err := cmd.Run(cliSuite.KubectlPath, "--kubeconfig", filepath.Join(tempDir, "kubeconfig"), "get", "nodes",
89-
"-o", "jsonpath={.items[*].status.addresses[?(@.type==\"InternalIP\")].address}", fmt.Sprintf("--selector=%s", constants.LabelNodeRoleControlPlane))
88+
masterNodes, err := cmd.RunWithOptions(cliSuite.T().Context(), cliSuite.KubectlPath,
89+
[]string{
90+
"--kubeconfig", filepath.Join(tempDir, "kubeconfig"), "get", "nodes",
91+
"-o", "jsonpath={.items[*].status.addresses[?(@.type==\"InternalIP\")].address}", fmt.Sprintf("--selector=%s", constants.LabelNodeRoleControlPlane),
92+
})
9093
cliSuite.Require().NoError(err)
9194

92-
workerNodes, err := cmd.Run(cliSuite.KubectlPath, "--kubeconfig", filepath.Join(tempDir, "kubeconfig"), "get", "nodes",
93-
"-o", "jsonpath={.items[*].status.addresses[?(@.type==\"InternalIP\")].address}", fmt.Sprintf("--selector=!%s", constants.LabelNodeRoleControlPlane))
95+
workerNodes, err := cmd.RunWithOptions(cliSuite.T().Context(), cliSuite.KubectlPath,
96+
[]string{
97+
"--kubeconfig", filepath.Join(tempDir, "kubeconfig"), "get", "nodes",
98+
"-o", "jsonpath={.items[*].status.addresses[?(@.type==\"InternalIP\")].address}", fmt.Sprintf("--selector=!%s", constants.LabelNodeRoleControlPlane),
99+
})
94100
cliSuite.Require().NoError(err)
95101

96102
nodeInfo, err := newNodeInfo(

0 commit comments

Comments
 (0)