Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Commit 42213e5

Browse files
committed
Fix various lint issues
1 parent b5da141 commit 42213e5

File tree

14 files changed

+21
-15
lines changed

14 files changed

+21
-15
lines changed

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ issues:
2323
- target
2424
- virt-tests
2525
- vm-images
26+
exclude-rules:
27+
- path: hostmetadata/azure/azure.go
28+
linters:
29+
- lll
2630

2731
linters:
2832
enable-all: true

config/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (e EnvironmentType) String() string {
8080
case envAzure:
8181
return "azure"
8282
case envAWS:
83-
// nolint: goconst
83+
//nolint: goconst
8484
return "aws"
8585
default:
8686
return fmt.Sprintf("unknown environment %d", e)

containermetadata/containermetadata_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func BenchmarkGetKubernetesPodMetadata(b *testing.B) {
362362

363363
file, err := os.CreateTemp("", "test_containermetadata_cgroup*")
364364
require.NoError(b, err)
365-
defer os.Remove(file.Name()) // nolint: gocritic
365+
defer os.Remove(file.Name()) //nolint: gocritic
366366

367367
_, err = fmt.Fprintf(file,
368368
"0::/kubepods/besteffort/poda9c80282-3f6b-4d5b-84d5-a137a6668011/"+

hostmetadata/azure/azure.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ type IMDS struct {
8282
// Failures (missing keys, etc) are logged and ignored.
8383
//
8484
// We extract the Azure metadata according to the information at
85-
// nolint:lll
8685
// https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service?tabs=linux#endpoint-categories
8786
//
8887
// - 169.254.169.254 is the standard endpoint for the instance metadata service in all clouds.

hostmetadata/azure/azure_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18-
// nolint:lll
18+
//nolint:lll
1919
const fakeAzureAnswer = `{
2020
"compute": {
2121
"azEnvironment": "AzurePublicCloud",

hostmetadata/host/cpuid_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestCPUID_ParseOnlineCPUCoreIDs(t *testing.T) {
4242
func prepareFakeCPUOnlineFile(t *testing.T, content string) *os.File {
4343
f, err := os.CreateTemp("", "sys_device_cpu_online")
4444
require.NoError(t, err)
45+
//nolint:gosec
4546
_ = os.WriteFile(f.Name(), []byte(content), os.ModePerm)
4647
return f
4748
}

hostmetadata/host/cpuinfo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestReadCPUInfo(t *testing.T) {
5959
assert.NotEmpty(t, cps)
6060
i, err := strconv.Atoi(cps)
6161
require.NoErrorf(t, err, "%v must be parseable as a number", cps)
62-
assert.Greater(t, i, 0)
62+
assert.Positive(t, i)
6363
},
6464
"OnlineCPUs": func(t *testing.T) {
6565
assert.Contains(t, info[key(keyCPUOnline)], 0)

libpf/pfelf/pfelf_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func TestGetGoBuildID(t *testing.T) {
5757
t.Fatalf("GetGoBuildID failed with error: %s", err)
5858
}
5959

60-
// nolint:lll
6160
if buildID !=
6261
"tUhrGOwxi48kXlLhYlY3/WlmPekR2qonrFvofssLt/8beXJbt0rDaHhn3I6x8D/IA6Zd8Qc8Rsh_bFKoPVn" {
6362
t.Fatalf("Invalid build-id: %s", buildID)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func mainWithExitCode() exitCode {
186186
}
187187

188188
if err = tracer.ProbeBPFSyscall(); err != nil {
189-
log.Errorf(fmt.Sprintf("Failed to probe eBPF syscall: %v", err))
189+
log.Errorf("Failed to probe eBPF syscall: %v", err)
190190
return exitFailure
191191
}
192192

metrics/cpumetrics/cpu.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ func getCPUUsage() (pAvgCPU uint16, err error) {
223223
// Calculate the maximum possible value for the elapsed time (duration).
224224
// nCPUs*userHZ: The max. number of ticks per second.
225225
// duration / time.Second: Time elapsed in seconds.
226-
max := float64(nCPUs*userHZ) * (float64(duration) / float64(time.Second))
226+
maximum := float64(nCPUs*userHZ) * (float64(duration) / float64(time.Second))
227227

228228
// Calculate the % value of the CPU usage with rounding.
229-
if max > 0 {
230-
pAvgCPU = uint16(float64(load*100)/max + 0.5)
229+
if maximum > 0 {
230+
pAvgCPU = uint16(float64(load*100)/maximum + 0.5)
231231
if pAvgCPU > 100 {
232232
pAvgCPU = 100
233233
}

0 commit comments

Comments
 (0)