Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.15] OCPBUGS-29351: fix: resolve PV name before comparing to KName #573

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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