From a084f4d0396af7388717c7933bea9f6b0cd0481b Mon Sep 17 00:00:00 2001 From: Xuefeng Chen Date: Mon, 24 Jul 2023 07:49:05 -0700 Subject: [PATCH] Prevent volume from schedualing to offline or readonly pool (#448) * Prevent volume from schedualing to offline or readonly pool Signed-off-by: xchen * code syntax match Signed-off-by: xchen --------- Signed-off-by: xchen Co-authored-by: xchen Signed-off-by: Niladri Halder --- .../cstorvolumeconfig/volume_operations.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/controllers/cstorvolumeconfig/volume_operations.go b/pkg/controllers/cstorvolumeconfig/volume_operations.go index 891158ed..8e952db7 100644 --- a/pkg/controllers/cstorvolumeconfig/volume_operations.go +++ b/pkg/controllers/cstorvolumeconfig/volume_operations.go @@ -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) @@ -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{}