Skip to content

Commit 3f54063

Browse files
author
Kiran Mova
authored
feat(bdc): update bdc builder with adding tag (#36)
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 <[email protected]>
1 parent 0c3617e commit 3f54063

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/apis/openebs.io/v1alpha1/blockdeviceclaimbuilder.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const (
2929
StoragePoolKindCSPC = "CStorPoolCluster"
3030
// APIVersion holds the value of OpenEBS version
3131
APIVersion = "openebs.io/v1alpha1"
32+
33+
// bdTagKey defines the label selector key
34+
// used for grouping block devices using a tag.
35+
bdTagKey = "openebs.io/block-device-tag"
3236
)
3337

3438
func NewBlockDeviceClaim() *BlockDeviceClaim {
@@ -144,6 +148,23 @@ func (bdc *BlockDeviceClaim) WithBlockVolumeMode(mode corev1.PersistentVolumeMod
144148
return bdc
145149
}
146150

151+
// WithBlockDeviceTag appends (or creates) the BDC Label Selector
152+
// by setting the provided value to the fixed key
153+
// openebs.io/block-device-tag
154+
// This will enable the NDM to pick only devices that
155+
// match the node (hostname) and block device tag value.
156+
func (bdc *BlockDeviceClaim) WithBlockDeviceTag(bdTagValue string) *BlockDeviceClaim {
157+
if bdc.Spec.Selector == nil {
158+
bdc.Spec.Selector = &metav1.LabelSelector{}
159+
}
160+
if bdc.Spec.Selector.MatchLabels == nil {
161+
bdc.Spec.Selector.MatchLabels = map[string]string{}
162+
}
163+
164+
bdc.Spec.Selector.MatchLabels[bdTagKey] = bdTagValue
165+
return bdc
166+
}
167+
147168
// RemoveFinalizer removes the given finalizer from the object.
148169
func (bdc *BlockDeviceClaim) RemoveFinalizer(finalizer string) {
149170
bdc.Finalizers = util.RemoveString(bdc.Finalizers, finalizer)

0 commit comments

Comments
 (0)