diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 040791978..7397e4765 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -49,8 +49,8 @@ func TestSysctlConfigEnsure(t *testing.T) { func TestIPRouteConfigEnsure(t *testing.T) { r := IPRouteConfig{ Route: netlink.Route{}, - RouteAdd: func(route *netlink.Route) error { return os.ErrExist }, - RouteDel: func(route *netlink.Route) error { return syscall.ESRCH }, + RouteAdd: func(_ *netlink.Route) error { return os.ErrExist }, + RouteDel: func(_ *netlink.Route) error { return syscall.ESRCH }, } if err := r.Ensure(true); err != nil { t.Error("ipRouteConfig.Ensure(true) should ignore the os.ErrExist Error.") @@ -81,7 +81,7 @@ func TestIPRuleConfigEnsure(t *testing.T) { Rule: netlink.Rule{SuppressIfgroup: -1, SuppressPrefixlen: -1, Mark: -1, Mask: -1, Goto: -1}, RuleAdd: func(rule *netlink.Rule) error { ruleList = append(ruleList, *rule); return nil }, RuleDel: mockRuleDel, - RuleList: func(family int) ([]netlink.Rule, error) { return ruleList, nil }, + RuleList: func(_ int) ([]netlink.Rule, error) { return ruleList, nil }, } if count, _ := ipRule.count(); count != 2 { t.Errorf("IPRuleConfig.count() should return 2.") diff --git a/pkg/metrics/collector/pod_ip_metrics.go b/pkg/metrics/collector/pod_ip_metrics.go index 1a055b64c..a336ebe3a 100644 --- a/pkg/metrics/collector/pod_ip_metrics.go +++ b/pkg/metrics/collector/pod_ip_metrics.go @@ -232,6 +232,8 @@ func (c *podIPMetricsCollector) listIPAddresses(dir string) error { continue } f, ok := podMap[podID] + // TODO: #351 - fix lint errors + //nolint:gocritic if !ok { podMap[podID] = family } else if (f == ipv4 && family == ipv6) || (f == ipv6 && family == ipv4) { @@ -319,18 +321,18 @@ func (c *podIPMetricsCollector) countIPsFromRange(subnet *net.IPNet) (uint64, er if bits-ones >= 64 { return math.MaxUint64, nil } - max := uint64(1) << uint(bits-ones) - max-- + count := uint64(1) << uint(bits-ones) + count-- if subnet.IP.To4() != nil { // Don't use the IPv4 network's broadcast address - if max == 0 { + if count == 0 { return 0, fmt.Errorf("subnet includes only the network and broadcast addresses") } - max-- - } else if max == 0 { + count-- + } else if count == 0 { return 0, fmt.Errorf("subnet includes only the network address") } - return max, nil + return count, nil } func (c *podIPMetricsCollector) updateAssignedIPs(subnet *net.IPNet, totalIP uint64) { diff --git a/pkg/metrics/collector/pod_ip_metrics_test.go b/pkg/metrics/collector/pod_ip_metrics_test.go index 571aa9cb5..ca43a8827 100644 --- a/pkg/metrics/collector/pod_ip_metrics_test.go +++ b/pkg/metrics/collector/pod_ip_metrics_test.go @@ -211,7 +211,7 @@ func TestSetupDirectoryWatcher(t *testing.T) { t.Fatal("podIPMetricsWatcherIsIntialized: want: true, got: false") } - //Add a new file to the directory. Verify metrics + // Add a new file to the directory. Verify metrics mustCreateFile(t, dir1, "10.0.0.3", "hash3") time.Sleep(1 * time.Second) if mc.usedIPv4AddrCount != 3 { @@ -230,7 +230,7 @@ func TestSetupDirectoryWatcher(t *testing.T) { t.Errorf("duplicateIpCount. want: 0, got %d", mc.duplicateIPCount) } - //Remove a file from the directory. Verify metrics + // Remove a file from the directory. Verify metrics mustDeleteFile(t, dir1, "10.0.0.3") time.Sleep(1 * time.Second) if mc.usedIPv4AddrCount != 2 { @@ -271,6 +271,8 @@ func TestSetupDirectoryWatcher(t *testing.T) { for _, bound := range bucketKeys { v, ok := mc.reuseIPs.buckets[bound] + // TODO: #351 - fix lint errors + //nolint:gocritic if !ok { t.Errorf("reused ip: buckets are initialized with 0 values. want: ok, got %v", ok) } else if bound == 5e3 && v != 0 {