Skip to content

Commit 060e15e

Browse files
ibrokethecloudfrelon
authored andcommitted
Minor change to lookup devices using blkid
Minor change to lookup devices using blkid and updating the upgradeSpec if needed. This may be needed when running elemental upgrade in multipathd systems Signed-off-by: Gaurav Mehta <[email protected]>
1 parent f29ac26 commit 060e15e

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

cmd/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ func ReadUpgradeSpec(r *types.RunConfig, flags *pflag.FlagSet, recoveryOnly bool
468468
} else {
469469
err = upgrade.Sanitize()
470470
}
471+
if err != nil {
472+
return nil, fmt.Errorf("failed sanitizing upgrade spec: %v", err)
473+
}
474+
475+
err = config.ReconcileUpgradeSpec(upgrade)
471476
r.Logger.Debugf("Loaded upgrade UpgradeSpec: %s", litter.Sdump(upgrade))
472477
return upgrade, err
473478
}

pkg/config/config.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package config
1818

1919
import (
2020
"fmt"
21+
"os/exec"
2122
"path/filepath"
2223
"runtime"
2324
"strings"
@@ -585,3 +586,54 @@ func NewBuildConfig(opts ...GenericOptions) *types.BuildConfig {
585586
}
586587
return b
587588
}
589+
590+
// ReconcileUpgradeSpec will check current mounts which may differ from elemental disovery from /sys/block tree
591+
// as this skips multipathed devices which may be in use.
592+
func ReconcileUpgradeSpec(spec *v1.UpgradeSpec) error {
593+
if spec.Partitions.State != nil {
594+
if err := reconcilePartition(spec.Partitions.State); err != nil {
595+
return err
596+
}
597+
}
598+
if spec.Partitions.Recovery != nil {
599+
if err := reconcilePartition(spec.Partitions.Recovery); err != nil {
600+
return err
601+
}
602+
}
603+
604+
if spec.Partitions.Persistent != nil {
605+
if err := reconcilePartition(spec.Partitions.Persistent); err != nil {
606+
return err
607+
}
608+
}
609+
610+
if spec.Partitions.OEM != nil {
611+
if err := reconcilePartition(spec.Partitions.OEM); err != nil {
612+
return err
613+
}
614+
}
615+
return nil
616+
}
617+
618+
func reconcilePartition(part *v1.Partition) error {
619+
discoveredMountDiskBytes, err := execBlkid(part.FilesystemLabel)
620+
if err != nil {
621+
return fmt.Errorf("error discovering current partition using label %s: %w", part.FilesystemLabel, err)
622+
}
623+
624+
// trim space since `blkid` output has a newline in result
625+
discoveredMount := strings.TrimSpace(string(discoveredMountDiskBytes))
626+
if part.Path != discoveredMount {
627+
part.Path = discoveredMount
628+
}
629+
return nil
630+
}
631+
func execBlkid(name string) ([]byte, error) {
632+
path, err := exec.LookPath("blkid")
633+
if err != nil {
634+
return nil, err
635+
}
636+
637+
blkidCmd := exec.Command(path, "-L", name)
638+
return blkidCmd.Output()
639+
}

0 commit comments

Comments
 (0)