Skip to content

Commit

Permalink
fix: resolve PV name before comparing to KName
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmoellerdev committed Feb 8, 2024
1 parent 39f73d4 commit f204965
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 @@ -206,7 +206,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 @@ -55,6 +56,9 @@ var (
}
)

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

type Filter func(lsblk.BlockDevice, []lvm.PhysicalVolume, lsblk.BlockDeviceInfos) error

type Filters map[string]Filter
Expand Down Expand Up @@ -102,7 +106,11 @@ func DefaultFilters(vg *lvmv1alpha1.LVMVolumeGroup) Filters {
if dev.FSType == FSTypeLVM2Member {
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 @@ -188,6 +188,9 @@ func TestOnlyValidFilesystemSignatures(t *testing.T) {
lvmExpect: []lvm.PhysicalVolume{{PvName: "dev1", VgName: "vg1"}},
},
}
evalSymlinks = func(path string) (string, error) {
return path, nil
}
for _, tc := range testcases {
t.Run(tc.label, func(t *testing.T) {
vg := &lvmv1alpha1.LVMVolumeGroup{}
Expand Down

0 comments on commit f204965

Please sign in to comment.