Skip to content

Commit

Permalink
cherry-pick(probe): initialize labels before probe start (#664)
Browse files Browse the repository at this point in the history
- 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.

- chore(test): update unit test

Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored Dec 24, 2021
1 parent 7c64d44 commit a1e8959
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/ndm_daemonset/controller/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (c *Controller) ListProbe(requestedProbes ...string) []*Probe {
func (c *Controller) FillBlockDeviceDetails(blockDevice *blockdevice.BlockDevice,
requestedProbes ...string) {
blockDevice.NodeAttributes = c.NodeAttributes
blockDevice.Labels = make(map[string]string)
selectedProbes := c.ListProbe(requestedProbes...)
for _, probe := range selectedProbes {
probe.FillBlockDeviceDetails(blockDevice)
Expand Down
1 change: 1 addition & 0 deletions cmd/ndm_daemonset/controller/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func TestFillDetails(t *testing.T) {

// create one fake Disk struct
expectedDr := &bd.BlockDevice{}
expectedDr.Labels = make(map[string]string)
expectedDr.DeviceAttributes.Model = fakeModel
expectedDr.DeviceAttributes.Serial = fakeSerial
expectedDr.DeviceAttributes.Vendor = fakeVendor
Expand Down
3 changes: 0 additions & 3 deletions cmd/ndm_daemonset/probe/customtagprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ func (ctp *customTagProbe) FillBlockDeviceDetails(bd *blockdevice.BlockDevice) {
case tagTypePath:
fieldToMatch = bd.DevPath
}
if bd.Labels == nil {
bd.Labels = make(map[string]string)
}
if util.IsMatchRegex(tag.regex, fieldToMatch) {
bd.Labels[kubernetes.BlockDeviceTagLabel] = tag.label
klog.Infof("Device: %s Label %s:%s added by custom tag probe", bd.DevPath, kubernetes.BlockDeviceTagLabel, tag.label)
Expand Down
4 changes: 4 additions & 0 deletions cmd/ndm_daemonset/probe/customtagprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestCustomTagProbeFillBlockDeviceDetails(t *testing.T) {
Identifier: blockdevice.Identifier{
DevPath: "/dev/sda",
},
Labels: make(map[string]string),
},
customTags: nil,
wantTagLabel: "",
Expand All @@ -47,6 +48,7 @@ func TestCustomTagProbeFillBlockDeviceDetails(t *testing.T) {
Identifier: blockdevice.Identifier{
DevPath: "/dev/sda",
},
Labels: make(map[string]string),
},
customTags: []tag{
{
Expand All @@ -63,6 +65,7 @@ func TestCustomTagProbeFillBlockDeviceDetails(t *testing.T) {
Identifier: blockdevice.Identifier{
DevPath: "/dev/sdb",
},
Labels: make(map[string]string),
},
customTags: []tag{
{
Expand All @@ -79,6 +82,7 @@ func TestCustomTagProbeFillBlockDeviceDetails(t *testing.T) {
Identifier: blockdevice.Identifier{
DevPath: "/dev/sdb",
},
Labels: make(map[string]string),
},
customTags: []tag{
{
Expand Down

0 comments on commit a1e8959

Please sign in to comment.