Skip to content

Commit

Permalink
openstack: fix bootOrder setting
Browse files Browse the repository at this point in the history
Currently, because bootOrder was declared outside the loop, it would
keep the same value from a previous iteration, being set on a disk that
shouldn't be set.

Signed-off-by: Benny Zlotnik <[email protected]>
  • Loading branch information
bennyz authored and ahadas committed Mar 24, 2024
1 parent 3f1d432 commit 3abf28a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/controller/plan/adapter/openstack/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,13 @@ func (r *Builder) mapDisks(vm *model.Workload, persistentVolumeClaims []*core.Pe
bus = VirtioBus
}

var bootOrder *uint
var bootOrderSet bool
var imagePVC *core.PersistentVolumeClaim
for _, pvc := range persistentVolumeClaims {
// Handle loopvar https://go.dev/wiki/LoopvarExperiment
pvc := pvc

var bootOrder *uint
image, err := r.getImageFromPVC(pvc)
if err != nil {
r.Log.Error(err, "image not found in inventory", "imageID", pvc.Labels["imageID"])
Expand All @@ -536,6 +537,7 @@ func (r *Builder) mapDisks(vm *model.Workload, persistentVolumeClaims []*core.Pe
if bootable, err := strconv.ParseBool(volume.Bootable); err == nil && bootable {
r.Log.Info("bootable volume found", "volumeID", volumeID)
bootOrder = ptr.To[uint](1)
bootOrderSet = true
}
}

Expand Down Expand Up @@ -584,7 +586,7 @@ func (r *Builder) mapDisks(vm *model.Workload, persistentVolumeClaims []*core.Pe
}

// If bootOrder wasn't set by a bootable volume, set it to the image (if exists)
if bootOrder == nil && imagePVC != nil {
if !bootOrderSet && imagePVC != nil {
r.Log.Info("No bootable volume found, falling back to image", "image", imagePVC.Name)
for i, disk := range kDisks {
if disk.Name == fmt.Sprintf("vol-%s", imagePVC.Annotations[planbase.AnnDiskSource]) {
Expand Down

0 comments on commit 3abf28a

Please sign in to comment.