Skip to content

Commit

Permalink
feat(bdc): update bdc builder with adding tag
Browse files Browse the repository at this point in the history
Ref: openebs-archive/maya#1648

A new label fixed selector (openebs.io/block-device-tag)
has been added to BDC to help with narrowing down the
block devices that can be claimed via the BDC.

This will allow users to tag block devices
and indicate which tagged devices can be used
by the BDC.

Signed-off-by: kmova <kiran.mova@mayadata.io>
  • Loading branch information
kmova committed Apr 8, 2020
1 parent 7c22996 commit b4b2e4e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/apis/openebs.io/v1alpha1/blockdeviceclaimbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const (
StoragePoolKindCSPC = "CStorPoolCluster"
// APIVersion holds the value of OpenEBS version
APIVersion = "openebs.io/v1alpha1"

// bdTagKey defines the label selector key
// used for grouping block devices using a tag.
bdTagKey = "openebs.io/block-device-tag"
)

func NewBlockDeviceClaim() *BlockDeviceClaim {
Expand Down Expand Up @@ -144,6 +148,23 @@ func (bdc *BlockDeviceClaim) WithBlockVolumeMode(mode corev1.PersistentVolumeMod
return bdc
}

// WithBlockDeviceTag appends (or creates) the BDC Label Selector
// by setting the provided value to the fixed key
// openebs.io/block-device-tag
// This will enable the NDM to pick only devices that
// match the node (hostname) and block device tag value.
func (bdc *BlockDeviceClaim) WithBlockDeviceTag(bdTagValue string) *BlockDeviceClaim {
if bdc.Spec.Selector == nil {
bdc.Spec.Selector = &metav1.LabelSelector{}
}
if bdc.Spec.Selector.MatchLabels == nil {
bdc.Spec.Selector.MatchLabels = map[string]string{}
}

bdc.Spec.Selector.MatchLabels[bdTagKey] = bdTagValue
return bdc
}

// RemoveFinalizer removes the given finalizer from the object.
func (bdc *BlockDeviceClaim) RemoveFinalizer(finalizer string) {
bdc.Finalizers = util.RemoveString(bdc.Finalizers, finalizer)
Expand Down

0 comments on commit b4b2e4e

Please sign in to comment.