Skip to content

Commit 7094461

Browse files
authored
fix(probe): initialize labels before probe start (#663)
- earlier the blockdevice labels map was initialized in the customtag probe which causes undeclared map, if the labels are used before using customtag probe. Now the label initialization happens before the probes are run. - update unit test Signed-off-by: Akhil Mohan <akhil.mohan@datacore.com>
1 parent 7c64d44 commit 7094461

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

cmd/ndm_daemonset/controller/probe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (c *Controller) ListProbe(requestedProbes ...string) []*Probe {
112112
func (c *Controller) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevice,
113113
requestedProbes ...string) {
114114
blockDevice.NodeAttributes = c.NodeAttributes
115+
blockDevice.Labels = make(map[string]string)
115116
selectedProbes := c.ListProbe(requestedProbes...)
116117
for _, probe := range selectedProbes {
117118
probe.FillBlockDeviceDetails(blockDevice)

cmd/ndm_daemonset/controller/probe_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ func TestFillDetails(t *testing.T) {
212212

213213
// create one fake Disk struct
214214
expectedDr := &bd.BlockDevice{}
215+
expectedDr.Labels = make(map[string]string)
215216
expectedDr.DeviceAttributes.Model = fakeModel
216217
expectedDr.DeviceAttributes.Serial = fakeSerial
217218
expectedDr.DeviceAttributes.Vendor = fakeVendor

cmd/ndm_daemonset/probe/customtagprobe.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ func (ctp *customTagProbe) FillBlockDeviceDetails(bd *blockdevice.BlockDevice) {
9696
case tagTypePath:
9797
fieldToMatch = bd.DevPath
9898
}
99-
if bd.Labels == nil {
100-
bd.Labels = make(map[string]string)
101-
}
10299
if util.IsMatchRegex(tag.regex, fieldToMatch) {
103100
bd.Labels[kubernetes.BlockDeviceTagLabel] = tag.label
104101
klog.Infof("Device: %s Label %s:%s added by custom tag probe", bd.DevPath, kubernetes.BlockDeviceTagLabel, tag.label)

cmd/ndm_daemonset/probe/customtagprobe_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestCustomTagProbeFillBlockDeviceDetails(t *testing.T) {
3737
Identifier: blockdevice.Identifier{
3838
DevPath: "/dev/sda",
3939
},
40+
Labels: make(map[string]string),
4041
},
4142
customTags: nil,
4243
wantTagLabel: "",
@@ -47,6 +48,7 @@ func TestCustomTagProbeFillBlockDeviceDetails(t *testing.T) {
4748
Identifier: blockdevice.Identifier{
4849
DevPath: "/dev/sda",
4950
},
51+
Labels: make(map[string]string),
5052
},
5153
customTags: []tag{
5254
{
@@ -63,6 +65,7 @@ func TestCustomTagProbeFillBlockDeviceDetails(t *testing.T) {
6365
Identifier: blockdevice.Identifier{
6466
DevPath: "/dev/sdb",
6567
},
68+
Labels: make(map[string]string),
6669
},
6770
customTags: []tag{
6871
{
@@ -79,6 +82,7 @@ func TestCustomTagProbeFillBlockDeviceDetails(t *testing.T) {
7982
Identifier: blockdevice.Identifier{
8083
DevPath: "/dev/sdb",
8184
},
85+
Labels: make(map[string]string),
8286
},
8387
customTags: []tag{
8488
{

0 commit comments

Comments
 (0)