Skip to content

Commit

Permalink
Always set inventory map low case, no matter the configuration casing
Browse files Browse the repository at this point in the history
  • Loading branch information
damyan committed Sep 26, 2024
1 parent 40496c9 commit 6b21ea9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugins/metal/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func loadConfig(args ...string) (map[string]string, error) {
inventories := make(map[string]string)
for _, i := range config {
if i.MacAddress != "" && i.Name != "" {
inventories[i.MacAddress] = i.Name
inventories[strings.ToLower(i.MacAddress)] = i.Name
}
}

Expand Down Expand Up @@ -133,7 +133,7 @@ func handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {
}

func applyEndpointForMACAddress(mac net.HardwareAddr, subnetFamily ipamv1alpha1.SubnetAddressType) error {
inventoryName, ok := inventoryMap[mac.String()]
inventoryName, ok := inventoryMap[strings.ToLower(mac.String())]
if !ok {
// done here, return no error, next plugin
log.Printf("Unknown inventory MAC address: %s", mac.String())
Expand Down Expand Up @@ -203,7 +203,7 @@ func GetIPForMACAddress(mac net.HardwareAddr, subnetFamily ipamv1alpha1.SubnetAd
return nil, fmt.Errorf("failed to list IPs: %v", err)
}

sanitizedMAC := strings.Replace(mac.String(), ":", "", -1)
sanitizedMAC := strings.Replace(strings.ToLower(mac.String()), ":", "", -1)
for _, ip := range ips.Items {
if ip.Labels["mac"] == sanitizedMAC && ipFamilyMatches(ip, subnetFamily) {
return &ip.Status.Reserved.Net, nil
Expand Down

0 comments on commit 6b21ea9

Please sign in to comment.