Skip to content

Commit

Permalink
Merge pull request #573 from jakobmoellerdev/OCPBUGS-29351
Browse files Browse the repository at this point in the history
[release-4.15] OCPBUGS-29351: fix: resolve PV name before comparing to KName
  • Loading branch information
openshift-merge-bot[bot] authored Feb 14, 2024
2 parents 1e61965 + 00ad26d commit 81fdbf2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/controllers/vgmanager/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func isDeviceAlreadyPartOfVG(nodeStatus *lvmv1alpha1.LVMVolumeGroupNodeStatus, d
for _, vgStatus := range nodeStatus.Spec.LVMVGStatus {
if vgStatus.Name == volumeGroup.Name {
for _, pv := range vgStatus.Devices {
if pv == diskName {
if resolvedPV, _ := evalSymlinks(pv); resolvedPV == diskName {
return true
}
}
Expand Down
10 changes: 9 additions & 1 deletion internal/controllers/vgmanager/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package filter
import (
"errors"
"fmt"
"path/filepath"
"strings"

lvmv1alpha1 "github.com/openshift/lvm-operator/api/v1alpha1"
Expand Down Expand Up @@ -64,6 +65,9 @@ var (
}
)

// evalSymlinks redefined to be able to override in tests
var evalSymlinks = filepath.EvalSymlinks

type Filter func(lsblk.BlockDevice) error

type Filters map[string]Filter
Expand Down Expand Up @@ -116,7 +120,11 @@ func DefaultFilters(vg *lvmv1alpha1.LVMVolumeGroup, lvmInstance lvm.LVM, lsblkIn

var foundPV *lvm.PhysicalVolume
for _, pv := range pvs {
if pv.PvName == dev.KName {
resolvedPVPath, err := evalSymlinks(pv.PvName)
if err != nil {
return fmt.Errorf("the pv %s could not be resolved via symlink: %w", pv, err)
}
if resolvedPVPath == dev.KName {
foundPV = &pv
break
}
Expand Down
3 changes: 3 additions & 0 deletions internal/controllers/vgmanager/filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ func TestOnlyValidFilesystemSignatures(t *testing.T) {
},
},
}
evalSymlinks = func(path string) (string, error) {
return path, nil
}
for _, tc := range testcases {
t.Run(tc.label, func(t *testing.T) {
mockLVM := lvmmocks.NewMockLVM(t)
Expand Down

0 comments on commit 81fdbf2

Please sign in to comment.