cleanup: add IsBlockMultiNode() helper

IsBlockMultiNode() is a new helper that takes a slice of
VolumeCapability objects and checks if it includes multi-node access
and/or block-mode support.

This can then easily be used in other services that need checking for
these particular capabilities, and preventing multi-node block-mode
access.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos
2021-12-09 17:23:02 +01:00
committed by mergify[bot]
parent 50d6ea825c
commit 30333378ef
3 changed files with 79 additions and 11 deletions

View File

@ -290,3 +290,19 @@ func requirePositive(x int64) int64 {
return 0
}
// IsBlockMultiNode checks the volume capabilities for BlockMode and MultiNode.
func IsBlockMultiNode(caps []*csi.VolumeCapability) (bool, bool) {
isMultiNode := false
isBlock := false
for _, capability := range caps {
if capability.GetAccessMode().GetMode() == csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER {
isMultiNode = true
}
if capability.GetBlock() != nil {
isBlock = true
}
}
return isBlock, isMultiNode
}