Skip to content

Commit

Permalink
fix(disk): exit on lsblks success during retries (#263)
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho authored Dec 23, 2024
1 parent 7b51852 commit 018ffed
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/disk/component_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func CreateGet(cfg Config) query.GetFunc {

o := &Output{}

prevFailed := false
for i := 0; i < 5; i++ {
cctx, ccancel := context.WithTimeout(ctx, time.Minute)
blks, err := disk.GetBlockDevices(cctx, disk.WithDeviceType(func(dt string) bool {
Expand All @@ -212,14 +213,22 @@ func CreateGet(cfg Config) query.GetFunc {
return nil, ctx.Err()
case <-time.After(5 * time.Second):
}

prevFailed = true
continue
}

o.DiskBlockDevices = blks
if prevFailed {
log.Logger.Infow("successfully got block devices after retries", "num_block_devices", len(blks))
}
break
}
if len(o.DiskBlockDevices) == 0 {
return nil, errors.New("no block device found")
}

prevFailed = false
for i := 0; i < 5; i++ {
cctx, ccancel := context.WithTimeout(ctx, time.Minute)
parts, err := disk.GetPartitions(cctx, disk.WithFstype(func(fs string) bool {
Expand All @@ -234,9 +243,16 @@ func CreateGet(cfg Config) query.GetFunc {
return nil, ctx.Err()
case <-time.After(5 * time.Second):
}

prevFailed = true
continue
}

o.DiskExtPartitions = parts
if prevFailed {
log.Logger.Infow("successfully got partitions after retries", "num_partitions", len(parts))
}
break
}
if len(o.DiskExtPartitions) == 0 {
return nil, errors.New("no ext4 partition found")
Expand Down

0 comments on commit 018ffed

Please sign in to comment.