Skip to content

Commit 217e9bb

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> (cherry picked from commit 7cf1de2)
1 parent d7779a5 commit 217e9bb

File tree

30 files changed

+127
-109
lines changed

30 files changed

+127
-109
lines changed

go.mod

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

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,12 @@ github.com/siderolabs/gen v0.8.6 h1:pE6shuqov3L+5rEcAUJ/kY6iJofimljQw5G95P8a5c4=
623623
github.com/siderolabs/gen v0.8.6/go.mod h1:J9IbusbES2W6QWjtSHpDV9iPGZHc978h1+KJ4oQRspQ=
624624
github.com/siderolabs/go-api-signature v0.3.12 h1:i1X+kPh9fzo+lEjtEplZSbtq1p21vKv4FCWJcB/ozvk=
625625
github.com/siderolabs/go-api-signature v0.3.12/go.mod h1:dPLiXohup4qHX7KUgF/wwOE3lRU5uAr3ssEomNxiyxY=
626-
github.com/siderolabs/go-blockdevice/v2 v2.0.24 h1:40e2Ty1u+A5if47NcIZI2j1ie4MZD5xxJbztpplYVGs=
627-
github.com/siderolabs/go-blockdevice/v2 v2.0.24/go.mod h1:8J8R+5PG4+oTq1g9zTYKFMikBx01U6gTPc5NKo7BEV8=
626+
github.com/siderolabs/go-blockdevice/v2 v2.0.25 h1:itUZVY68iINZJS3Dcz3NZMWReT4WybLGkuZZSUW5l+0=
627+
github.com/siderolabs/go-blockdevice/v2 v2.0.25/go.mod h1:a6KUjzyU8Joo7y9cW9BdmORCFJwVNweHYRpKiuDfMU8=
628628
github.com/siderolabs/go-circular v0.2.3 h1:GKkA1Tw79kEFGtWdl7WTxEUTbwtklITeiRT0V1McHrA=
629629
github.com/siderolabs/go-circular v0.2.3/go.mod h1:YBN/q9YpQphUYnBtBgPsngauSHj1TEZfgQZWZVjk1WE=
630-
github.com/siderolabs/go-cmd v0.1.3 h1:JrgZwqhJQeoec3QRON0LK+fv+0y7d0DyY7zsfkO6ciw=
631-
github.com/siderolabs/go-cmd v0.1.3/go.mod h1:bg7HY4mRNu4zKebAgUevSwuYNtcvPMJfuhLRkVKHZ0k=
630+
github.com/siderolabs/go-cmd v0.2.0 h1:fZ0jbQzZg4bFLmJzNEDZM/RlebZsfHOo2k+PCJ6g7y4=
631+
github.com/siderolabs/go-cmd v0.2.0/go.mod h1:YA/UEDh8Av84RlI4LfQw7HN9+vgxUrQw/Byef1dgptY=
632632
github.com/siderolabs/go-copy v0.1.0 h1:OIWCtSg+rhOtnIZTpT31Gfpn17rv5kwJqQHG+QUEgC8=
633633
github.com/siderolabs/go-copy v0.1.0/go.mod h1:4bF2rZOZAR/ags/U4AVSpjFE5RPGdEeSkOq6yR9YOkU=
634634
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/dual/dual.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (c *Config) installGrub(opts options.InstallOptions) error {
166166

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

169-
if _, err := cmd.Run("grub-install", args...); err != nil {
169+
if _, err := cmd.Run("grub-install", args...); err != nil { //nolint:staticcheck
170170
return fmt.Errorf("failed to install grub: %w", err)
171171
}
172172

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (c *Config) install(opts options.InstallOptions) (*options.InstallResult, e
208208

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

211-
if _, err := cmd.Run("grub-install", args...); err != nil {
211+
if _, err := cmd.Run("grub-install", args...); err != nil { //nolint:staticcheck
212212
return nil, fmt.Errorf("failed to install grub: %w", err)
213213
}
214214
}

internal/app/machined/pkg/runtime/v1alpha1/platform/opennebula/opennebula.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func parseRouteEntry(entry, linkName string) (network.RouteSpecSpec, error) {
302302
// ParseRoutes parses the ETH*_ROUTES variable into RouteSpecSpec entries.
303303
// Multiple routes are separated by commas.
304304
func ParseRoutes(routesStr, linkName string) ([]network.RouteSpecSpec, error) {
305-
var routes []network.RouteSpecSpec
305+
var routes []network.RouteSpecSpec //nolint:prealloc
306306

307307
for entry := range strings.SplitSeq(routesStr, ",") {
308308
entry = strings.TrimSpace(entry)
@@ -801,7 +801,7 @@ func (o *OpenNebula) ParseMetadata(st state.State, oneContextPlain []byte) (*run
801801
// SEARCH_DOMAIN). These are applied regardless of interface, matching the
802802
// reference get_nameservers()/get_searchdomains() which processes global
803803
// variables before per-interface ones.
804-
var allDNSIPs []netip.Addr
804+
var allDNSIPs []netip.Addr //nolint:prealloc
805805

806806
for s := range strings.FieldsSeq(oneContext["DNS"]) {
807807
ip, err := netip.ParseAddr(s)

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
}
@@ -120,16 +114,16 @@ func (c *Udevd) HealthFunc(runtime.Runtime) health.Check {
120114
// udevadm trigger returns with an exit code of 0 even if udevd is not fully running,
121115
// so running `udevadm control --reload` to ensure that udevd is fully initialized
122116
// which returns an exit code of 2 if udevd is not running. This complements the previous check
123-
if _, err := cmd.RunContext(ctx, "/sbin/udevadm", "control", "--reload"); err != nil {
117+
if _, err := cmd.RunWithOptions(ctx, "/sbin/udevadm", []string{"control", "--reload"}); err != nil {
124118
return err
125119
}
126120

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

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

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

0 commit comments

Comments
 (0)