From eea20cd06fed4818c853d1201bfae85c70295c7c Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 12 Nov 2024 10:18:20 -0500 Subject: [PATCH] fix lint errors --- hack/benchmark/cpu_usage/auto_pause/chart.go | 4 ++-- hack/benchmark/cpu_usage/idle_only/chart.go | 4 ++-- pkg/drivers/qemu/qemu.go | 4 ++-- pkg/minikube/assets/vm_assets.go | 8 ++++---- pkg/minikube/cruntime/containerd.go | 8 ++++---- pkg/minikube/cruntime/cri.go | 6 +++--- pkg/minikube/cruntime/crio.go | 8 ++++---- pkg/minikube/cruntime/docker.go | 12 ++++++------ pkg/minikube/perf/binary_test.go | 12 +++--------- pkg/network/network.go | 12 ++++++------ 10 files changed, 36 insertions(+), 42 deletions(-) diff --git a/hack/benchmark/cpu_usage/auto_pause/chart.go b/hack/benchmark/cpu_usage/auto_pause/chart.go index 56b97796eda8..295ba645a10a 100644 --- a/hack/benchmark/cpu_usage/auto_pause/chart.go +++ b/hack/benchmark/cpu_usage/auto_pause/chart.go @@ -37,9 +37,9 @@ var FOLDER = "site/static/images/benchmarks/cpuUsage/autoPause" type integerTicks struct{} -func (integerTicks) Ticks(min, max float64) []plot.Tick { +func (integerTicks) Ticks(minimum, maximum float64) []plot.Tick { var t []plot.Tick - for i := math.Trunc(min); i <= max; i += 50 { + for i := math.Trunc(minimum); i <= maximum; i += 50 { t = append(t, plot.Tick{Value: i, Label: fmt.Sprint(i)}) } return t diff --git a/hack/benchmark/cpu_usage/idle_only/chart.go b/hack/benchmark/cpu_usage/idle_only/chart.go index c7058894eb14..f3f4e1f75963 100644 --- a/hack/benchmark/cpu_usage/idle_only/chart.go +++ b/hack/benchmark/cpu_usage/idle_only/chart.go @@ -36,9 +36,9 @@ var FOLDER = "site/static/images/benchmarks/cpuUsage/idleOnly" type integerTicks struct{} -func (integerTicks) Ticks(min, max float64) []plot.Tick { +func (integerTicks) Ticks(minimum, maximum float64) []plot.Tick { var t []plot.Tick - for i := math.Trunc(min); i <= max; i += 50 { + for i := math.Trunc(minimum); i <= maximum; i += 50 { t = append(t, plot.Tick{Value: i, Label: fmt.Sprint(i)}) } return t diff --git a/pkg/drivers/qemu/qemu.go b/pkg/drivers/qemu/qemu.go index 5ccc8659da71..08b6ff1ad24f 100644 --- a/pkg/drivers/qemu/qemu.go +++ b/pkg/drivers/qemu/qemu.go @@ -327,8 +327,8 @@ func parsePortRange(rawPortRange string) (int, int, error) { return minPort, maxPort, nil } -func getRandomPortNumberInRange(min, max int) int { - return rand.Intn(max-min) + min +func getRandomPortNumberInRange(minimum, maximum int) int { + return rand.Intn(maximum-minimum) + minimum } func getAvailableTCPPortFromRange(minPort, maxPort int) (int, error) { diff --git a/pkg/minikube/assets/vm_assets.go b/pkg/minikube/assets/vm_assets.go index 907f389917ff..faa573aa4cd1 100644 --- a/pkg/minikube/assets/vm_assets.go +++ b/pkg/minikube/assets/vm_assets.go @@ -268,8 +268,8 @@ func (m *MemoryAsset) GetLength() int { } // SetLength returns length -func (m *MemoryAsset) SetLength(len int) { - m.length = len +func (m *MemoryAsset) SetLength(length int) { + m.length = length } // Read reads the asset @@ -403,8 +403,8 @@ func (m *BinAsset) GetLength() int { } // SetLength sets length -func (m *BinAsset) SetLength(len int) { - m.length = len +func (m *BinAsset) SetLength(length int) { + m.length = length } // Read reads the asset diff --git a/pkg/minikube/cruntime/containerd.go b/pkg/minikube/cruntime/containerd.go index 4cb0ad665966..290007e1bd05 100644 --- a/pkg/minikube/cruntime/containerd.go +++ b/pkg/minikube/cruntime/containerd.go @@ -507,13 +507,13 @@ func (r *Containerd) StopContainers(ids []string) error { } // ContainerLogCmd returns the command to retrieve the log for a container based on ID -func (r *Containerd) ContainerLogCmd(id string, len int, follow bool) string { - return criContainerLogCmd(r.Runner, id, len, follow) +func (r *Containerd) ContainerLogCmd(id string, length int, follow bool) string { + return criContainerLogCmd(r.Runner, id, length, follow) } // SystemLogCmd returns the command to retrieve system logs -func (r *Containerd) SystemLogCmd(len int) string { - return fmt.Sprintf("sudo journalctl -u containerd -n %d", len) +func (r *Containerd) SystemLogCmd(length int) string { + return fmt.Sprintf("sudo journalctl -u containerd -n %d", length) } // Preload preloads the container runtime with k8s images diff --git a/pkg/minikube/cruntime/cri.go b/pkg/minikube/cruntime/cri.go index 3dfc50dec35f..99e28632d713 100644 --- a/pkg/minikube/cruntime/cri.go +++ b/pkg/minikube/cruntime/cri.go @@ -329,14 +329,14 @@ func listCRIImages(cr CommandRunner) ([]ListImage, error) { } // criContainerLogCmd returns the command to retrieve the log for a container based on ID -func criContainerLogCmd(cr CommandRunner, id string, len int, follow bool) string { +func criContainerLogCmd(cr CommandRunner, id string, length int, follow bool) string { crictl := getCrictlPath(cr) var cmd strings.Builder cmd.WriteString("sudo ") cmd.WriteString(crictl) cmd.WriteString(" logs ") - if len > 0 { - cmd.WriteString(fmt.Sprintf("--tail %d ", len)) + if length > 0 { + cmd.WriteString(fmt.Sprintf("--tail %d ", length)) } if follow { cmd.WriteString("--follow ") diff --git a/pkg/minikube/cruntime/crio.go b/pkg/minikube/cruntime/crio.go index 4896e9a550ec..fec6339b6bbb 100644 --- a/pkg/minikube/cruntime/crio.go +++ b/pkg/minikube/cruntime/crio.go @@ -406,13 +406,13 @@ func (r *CRIO) StopContainers(ids []string) error { } // ContainerLogCmd returns the command to retrieve the log for a container based on ID -func (r *CRIO) ContainerLogCmd(id string, len int, follow bool) string { - return criContainerLogCmd(r.Runner, id, len, follow) +func (r *CRIO) ContainerLogCmd(id string, length int, follow bool) string { + return criContainerLogCmd(r.Runner, id, length, follow) } // SystemLogCmd returns the command to retrieve system logs -func (r *CRIO) SystemLogCmd(len int) string { - return fmt.Sprintf("sudo journalctl -u crio -n %d", len) +func (r *CRIO) SystemLogCmd(length int) string { + return fmt.Sprintf("sudo journalctl -u crio -n %d", length) } // Preload preloads the container runtime with k8s images diff --git a/pkg/minikube/cruntime/docker.go b/pkg/minikube/cruntime/docker.go index 2a4dd310da5e..a8a57afdf6c1 100644 --- a/pkg/minikube/cruntime/docker.go +++ b/pkg/minikube/cruntime/docker.go @@ -524,14 +524,14 @@ func (r *Docker) UnpauseContainers(ids []string) error { } // ContainerLogCmd returns the command to retrieve the log for a container based on ID -func (r *Docker) ContainerLogCmd(id string, len int, follow bool) string { +func (r *Docker) ContainerLogCmd(id string, length int, follow bool) string { if r.UseCRI { - return criContainerLogCmd(r.Runner, id, len, follow) + return criContainerLogCmd(r.Runner, id, length, follow) } var cmd strings.Builder cmd.WriteString("docker logs ") - if len > 0 { - cmd.WriteString(fmt.Sprintf("--tail %d ", len)) + if length > 0 { + cmd.WriteString(fmt.Sprintf("--tail %d ", length)) } if follow { cmd.WriteString("--follow ") @@ -542,8 +542,8 @@ func (r *Docker) ContainerLogCmd(id string, len int, follow bool) string { } // SystemLogCmd returns the command to retrieve system logs -func (r *Docker) SystemLogCmd(len int) string { - return fmt.Sprintf("sudo journalctl -u docker -u cri-docker -n %d", len) +func (r *Docker) SystemLogCmd(length int) string { + return fmt.Sprintf("sudo journalctl -u docker -u cri-docker -n %d", length) } type dockerDaemonConfig struct { diff --git a/pkg/minikube/perf/binary_test.go b/pkg/minikube/perf/binary_test.go index d6e270b3c0f3..72b84dc3c7cf 100644 --- a/pkg/minikube/perf/binary_test.go +++ b/pkg/minikube/perf/binary_test.go @@ -65,16 +65,10 @@ func TestNewBinary(t *testing.T) { for _, test := range tests { t.Run(test.input, func(t *testing.T) { bin, err := NewBinary(test.input) - if err == nil && test.errExpected { - t.Fatalf("Input %v returned unexpected error", test.input) + if wantErr, gotErr := test.errExpected, (err != nil); wantErr != gotErr { + t.Fatalf("NewBinary(%s) returned err = %v; expected err %t", test.input, err, wantErr) } - if test.errExpected { - return - } - if bin == nil { - t.Fatalf("Input string(%v) returned unexpected empty binary", test.input) - } - if !strings.Contains(bin.path, test.prNum) { + if err == nil && !strings.Contains(bin.path, test.prNum) { t.Fatalf("Binary path(%v) doesn't contain expected(%v)", bin.path, test.prNum) } }) diff --git a/pkg/network/network.go b/pkg/network/network.go index 6ea584569fcc..f7751fdaf6f0 100644 --- a/pkg/network/network.go +++ b/pkg/network/network.go @@ -148,13 +148,13 @@ var Inspect = func(addr string) (*Parameters, error) { } gatewayIP := binary.BigEndian.Uint32(gateway) - min := make(net.IP, 4) - binary.BigEndian.PutUint32(min, gatewayIP+1) // clients-from: first network IP address after gateway - n.ClientMin = min.String() + minIP := make(net.IP, 4) + binary.BigEndian.PutUint32(minIP, gatewayIP+1) // clients-from: first network IP address after gateway + n.ClientMin = minIP.String() - max := make(net.IP, 4) - binary.BigEndian.PutUint32(max, broadcastIP-1) // clients-to: last network IP address before broadcast - n.ClientMax = max.String() + maxIP := make(net.IP, 4) + binary.BigEndian.PutUint32(maxIP, broadcastIP-1) // clients-to: last network IP address before broadcast + n.ClientMax = maxIP.String() return n, nil }