Skip to content

Commit

Permalink
Prevent volume from schedualing to offline or readonly pool (#448)
Browse files Browse the repository at this point in the history
* Prevent volume from schedualing to offline or readonly pool

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

* code syntax match

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

---------

Signed-off-by: xchen <[email protected]>
Co-authored-by: xchen <[email protected]>
Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
2 people authored and niladrih committed Jul 24, 2023
1 parent eb5ec54 commit a084f4d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/controllers/cstorvolumeconfig/volume_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ func (c *CVCController) distributeCVRs(
usablePoolList = getUsablePoolList(c.clientset, volume.Name, poolList)
}

// sanitizePoolList to remove pool that has status.Phase as offline
// or Status.ReadOnly as true from usablePoolList
usablePoolList = sanitizePoolList(usablePoolList)

// randomizePoolList to get the pool list in random order
usablePoolList = randomizePoolList(usablePoolList)

Expand Down Expand Up @@ -597,6 +601,22 @@ func prioritizedPoolList(nodeName string, list *apis.CStorPoolInstanceList) *api
return list
}

// sanitizePoolList returns santized pool list
// 1. It removes the pool from the list if its phase is offline.
// 2. It removes the pool from the list if its readonly.
func sanitizePoolList(list *apis.CStorPoolInstanceList) *apis.CStorPoolInstanceList {
res := &apis.CStorPoolInstanceList{}

for _, pool := range list.Items {
if pool.Status.Phase == apis.CStorPoolStatusOffline || pool.Status.ReadOnly {
continue
}

res.Items = append(res.Items, pool)
}
return res
}

// randomizePoolList returns randomized pool list
func randomizePoolList(list *apis.CStorPoolInstanceList) *apis.CStorPoolInstanceList {
res := &apis.CStorPoolInstanceList{}
Expand Down

0 comments on commit a084f4d

Please sign in to comment.