Skip to content

Commit

Permalink
[cherry-pick] feat(cstor-operator): filter out released block devices…
Browse files Browse the repository at this point in the history
… during auto provisioning (#1312)

* fix(cstor-operator): honour spc type in case of manual provisioning of cStor pool (#1281)

Signed-off-by: mittachaitu <[email protected]>

* feat(cstor-operator): filter out released block devices during auto provisioning (#1310)

Signed-off-by: mittachaitu <[email protected]>
  • Loading branch information
sai chaithanya authored and vishnuitta committed Jun 19, 2019
1 parent 6277cf5 commit 338657c
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/algorithm/nodeselect/v1alpha1/select_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (ac *Config) getBlockDevice() (*ndmapis.BlockDeviceList, error) {
}

if ProvisioningType(ac.Spc) == ProvisioningTypeAuto {
filterList = append(filterList, blockdevice.FilterNonFSType)
filterList = append(filterList, blockdevice.FilterNonFSType, blockdevice.FilterNonReleasedDevices)
}

bdl = bdList.Filter(filterList...)
Expand Down
29 changes: 22 additions & 7 deletions pkg/blockdevice/v1alpha1/blockdevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ const (
FilterInactive = "filterInactive"
FilterNonInactive = "filterNonInactive"
//FilterNonPartitions = "filterNonPartitions"
FilterNonFSType = "filterNonFSType"
FilterSparseDevices = "filterSparseDevices"
FilterNonSparseDevices = "filterNonSparseDevices"
InActiveStatus = "Inactive"
FilterNonFSType = "filterNonFSType"
FilterSparseDevices = "filterSparseDevices"
FilterNonSparseDevices = "filterNonSparseDevices"
InActiveStatus = "Inactive"
FilterNonReleasedDevices = "filterNonReleasedDevices"
)

// DefaultDiskCount is a map containing the default block device count of various raid types.
Expand Down Expand Up @@ -113,9 +114,10 @@ var filterOptionFuncMap = map[string]filterOptionFunc{
FilterInactive: filterInactive,
FilterNonInactive: filterNonInactive,
//FilterNonPartitions: filterNonPartitions,
FilterNonFSType: filterNonFSType,
FilterSparseDevices: filterSparseDevices,
FilterNonSparseDevices: filterNonSparseDevices,
FilterNonFSType: filterNonFSType,
FilterSparseDevices: filterSparseDevices,
FilterNonSparseDevices: filterNonSparseDevices,
FilterNonReleasedDevices: filterNonReleasedDevices,
}

// predicateFailedError returns the predicate error which is provided to this function as an argument
Expand Down Expand Up @@ -289,6 +291,19 @@ func filterNonSparseDevices(originalList *BlockDeviceList) *BlockDeviceList {
return filteredList
}

func filterNonReleasedDevices(originalList *BlockDeviceList) *BlockDeviceList {
filteredList := &BlockDeviceList{
BlockDeviceList: &ndm.BlockDeviceList{},
errs: nil,
}
for _, device := range originalList.Items {
if !(device.Status.ClaimState == ndm.BlockDeviceReleased) {
filteredList.Items = append(filteredList.Items, device)
}
}
return filteredList
}

// Hasitems checks whether the BlockDeviceList contains BlockDevices
func (bdl *BlockDeviceList) Hasitems() (string, bool) {
if bdl == nil || bdl.BlockDeviceList == nil || bdl.Items == nil {
Expand Down
82 changes: 82 additions & 0 deletions pkg/blockdevice/v1alpha1/blockdevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,3 +727,85 @@ func TestFilterNonFSType(t *testing.T) {
})
}
}

func TestFilterNonReleasedDevices(t *testing.T) {
tests := map[string]struct {
// fakeCasPool holds the fake fakeCasPool object in test cases.
blockDeviceList *BlockDeviceList
// expectedBlockDeviceListLength holds the length of disk list
expectedBlockDeviceCount int
}{
"EmptyBlockDeviceList1": {
blockDeviceList: &BlockDeviceList{
BlockDeviceList: &ndm.BlockDeviceList{},
errs: nil,
},
expectedBlockDeviceCount: 0,
},
"blockDeviceList2": {
blockDeviceList: &BlockDeviceList{
BlockDeviceList: &ndm.BlockDeviceList{
TypeMeta: metav1.TypeMeta{},
ListMeta: metav1.ListMeta{},
Items: []ndm.BlockDevice{
{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{},
Spec: ndm.DeviceSpec{
Path: "/dev/sda",
},
Status: ndm.DeviceStatus{
State: "Active",
ClaimState: ndm.BlockDeviceReleased,
},
},
{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{},
Spec: ndm.DeviceSpec{
Path: "/dev/sdb",
},
Status: ndm.DeviceStatus{
State: "Active",
ClaimState: ndm.BlockDeviceUnclaimed,
},
},
{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{},
Spec: ndm.DeviceSpec{
Path: "/dev/sdb",
},
Status: ndm.DeviceStatus{
State: "Active",
ClaimState: ndm.BlockDeviceReleased,
},
},
{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{},
Spec: ndm.DeviceSpec{
Path: "/dev/sdb",
Partitioned: "NO",
},
Status: ndm.DeviceStatus{
State: "Active",
},
},
},
},
errs: nil,
},
expectedBlockDeviceCount: 2,
},
}
for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
filtteredBlockDeviceList := filterNonReleasedDevices(test.blockDeviceList)
if len(filtteredBlockDeviceList.Items) != test.expectedBlockDeviceCount {
t.Errorf("Test %q failed: expected block device object count %d but got %d", name, test.expectedBlockDeviceCount, len(filtteredBlockDeviceList.Items))
}
})
}
}

0 comments on commit 338657c

Please sign in to comment.