Skip to content

Commit 3b3af21

Browse files
committed
Fix lint errors
1 parent b200d87 commit 3b3af21

17 files changed

Lines changed: 44 additions & 37 deletions

File tree

cli/cmd/capture/create_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type testcase struct {
3939
wantErr bool
4040
}
4141

42-
func randomString(length int) string {
42+
func randomString(length int) string { //nolint:unparam // length is always 5 but keeping the param for readability
4343
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
4444
result := make([]byte, length)
4545
for i := range result {
@@ -120,7 +120,7 @@ func NewClientServerPods(service, namespace string) []*corev1.Pod {
120120
func TestCreateJobsWithNamespace(t *testing.T) {
121121
// Create a fake Kubernetes client with workload and capture namespaces
122122
newKubeclient := func() *fake.Clientset {
123-
objects := []runtime.Object{
123+
objects := []runtime.Object{ //nolint:prealloc // slice grows dynamically with pods added below
124124
NewNode("A1"),
125125
NewNode("A2"),
126126
NewNode("B1"),
@@ -676,6 +676,7 @@ func TestCreateCaptureCommand_AbsoluteHostPath_ShouldFail(t *testing.T) {
676676
require.Contains(t, err.Error(), "OutputConfiguration.HostPath",
677677
"error should reference the rejected HostPath field; got: %v", err)
678678
}
679+
679680
func TestHasRemoteDestination(t *testing.T) {
680681
tests := []struct {
681682
name string

cli/cmd/capture/delete_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type deleteTestCase struct {
3535

3636
// newKubeclient creates a consistent fake Kubernetes client for all tests
3737
func newKubeclient() *fake.Clientset {
38-
objects := []runtime.Object{
38+
objects := []runtime.Object{ //nolint:prealloc // slice grows dynamically with pods added below
3939
NewNode("A1"),
4040
NewNode("A2"),
4141
NewNode("B1"),

cli/cmd/capture/table_util.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ func printCaptureResult(captureJobs []batchv1.Job) {
7979
for captureRef := range captureToJobs {
8080
jobs := captureToJobs[captureRef]
8181
captureParts := strings.Split(captureRef, "/")
82-
captureNamespace, captureName := captureParts[0], captureParts[1]
82+
captureNamespace := captureParts[0]
83+
captureShortName := captureParts[1]
8384

8485
sort.SliceStable(jobs, func(i, j int) bool {
8586
return jobs[i].Name < jobs[j].Name
@@ -92,7 +93,7 @@ func printCaptureResult(captureJobs []batchv1.Job) {
9293
completions = fmt.Sprintf("%d/%d", job.Status.Succeeded, *job.Spec.Completions)
9394
}
9495
age := durationUtil.HumanDuration(time.Since(job.CreationTimestamp.Time))
95-
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", captureNamespace, captureName, job.Name, completions, age)
96+
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", captureNamespace, captureShortName, job.Name, completions, age)
9697
}
9798
}
9899
w.Flush()

pkg/capture/crd_to_job.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func (translator *CaptureToPodTranslator) renderJob(captureTargetOnNode *Capture
435435
return nil, fmt.Errorf("no nodes are selected")
436436
}
437437

438-
stringTimestamp := translator.jobTemplate.Spec.Template.ObjectMeta.Annotations[captureConstants.CaptureTimestampAnnotationKey]
438+
stringTimestamp := translator.jobTemplate.Spec.Template.Annotations[captureConstants.CaptureTimestampAnnotationKey]
439439
captureTimestamp, err := file.StringToTime(stringTimestamp)
440440
if err != nil {
441441
return nil, fmt.Errorf("failed to parse capture start timestamp: %w", err)
@@ -457,7 +457,7 @@ func (translator *CaptureToPodTranslator) renderJob(captureTargetOnNode *Capture
457457
NodeHostname: nodeName,
458458
StartTimestamp: captureTimestamp,
459459
}
460-
job.Spec.Template.ObjectMeta.Annotations[captureConstants.CaptureFilenameAnnotationKey] = captureFilename.String()
460+
job.Spec.Template.Annotations[captureConstants.CaptureFilenameAnnotationKey] = captureFilename.String()
461461

462462
fmt.Printf("%s.tar.gz\n", captureFilename.String())
463463

@@ -1049,7 +1049,9 @@ func (translator *CaptureToPodTranslator) ObtainCaptureJobPodEnv(capture retinav
10491049
return translator.obtainCaptureJobPodEnv(capture, resolvedHostPath)
10501050
}
10511051

1052-
func (translator *CaptureToPodTranslator) obtainCaptureJobPodEnv(capture retinav1alpha1.Capture, resolvedHostPath string) (map[string]string, error) {
1052+
func (translator *CaptureToPodTranslator) obtainCaptureJobPodEnv( //nolint:gocyclo // complexity is inherent to env var mapping logic
1053+
capture retinav1alpha1.Capture, resolvedHostPath string,
1054+
) (map[string]string, error) {
10531055
jobPodEnv := map[string]string{}
10541056

10551057
captureOutputEnv, err := translator.obtainCaptureOutputEnv(capture.Spec.OutputConfiguration, resolvedHostPath)

pkg/capture/file/timestamp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestNow(t *testing.T) {
1717
require.NotNil(t, result)
1818
assert.GreaterOrEqual(t, result.Time, before)
1919
assert.LessOrEqual(t, result.Time, after)
20-
assert.Equal(t, 0, result.Time.Nanosecond()) // ensure timestamp is truncated
20+
assert.Equal(t, 0, result.Nanosecond()) // ensure timestamp is truncated
2121
}
2222

2323
func TestStringToTime(t *testing.T) {

pkg/capture/provider/network_capture_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
interfaceEth0 = "eth0"
2828
interfaceEth1 = "eth1"
2929
interfaceAny = "any"
30+
tcpdumpBinary = "tcpdump"
3031
)
3132

3233
func TestSetupAndCleanup(t *testing.T) {
@@ -108,7 +109,7 @@ func TestTcpdumpEmptyFilter(t *testing.T) {
108109

109110
// Verify only expected args are present and no malicious content
110111
for _, arg := range cmd.Args {
111-
if arg != "tcpdump" && arg != "-w" && arg != testCaptureFilePath &&
112+
if arg != tcpdumpBinary && arg != "-w" && arg != testCaptureFilePath &&
112113
arg != "--relinquish-privileges=root" && arg != "-i" && arg != interfaceAny {
113114
t.Errorf("Unexpected argument '%s' found in empty filter command: %v", arg, cmd.Args)
114115
}
@@ -308,7 +309,7 @@ func TestTcpdumpBPFFilterOnly(t *testing.T) {
308309
}
309310

310311
// Should have basic structure (tcpdump, -w, path, -i, etc.)
311-
if !slices.Contains(cmd.Args, "tcpdump") {
312+
if !slices.Contains(cmd.Args, tcpdumpBinary) {
312313
t.Errorf("Expected 'tcpdump' in command args, but got: %v", cmd.Args)
313314
}
314315
if !slices.Contains(cmd.Args, "-w") {
@@ -319,7 +320,7 @@ func TestTcpdumpBPFFilterOnly(t *testing.T) {
319320
for _, arg := range cmd.Args {
320321
// Skip our internal flags and the BPF filter
321322
if arg == "-w" || arg == "-i" || arg == "-s" || arg == "--relinquish-privileges=root" ||
322-
arg == testCaptureFilePath || arg == "tcpdump" || arg == "any" || arg == bpfFilter {
323+
arg == testCaptureFilePath || arg == tcpdumpBinary || arg == "any" || arg == bpfFilter {
323324
continue
324325
}
325326
// Any other argument starting with '-' is suspicious
@@ -737,7 +738,7 @@ func TestTcpdumpCommandBaseArgs(t *testing.T) {
737738
cmd := constructTcpdumpCommand(testCaptureFilePath, "")
738739

739740
// Verify base args are always present
740-
if cmd.Args[0] != "tcpdump" {
741+
if cmd.Args[0] != tcpdumpBinary {
741742
t.Errorf("Expected first arg to be 'tcpdump', got %s", cmd.Args[0])
742743
}
743744
if !hasArgPair(cmd, "-w", testCaptureFilePath) {

pkg/capture/provider/network_capture_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func constructTcpdumpCommand(captureFilePath, bpfFilter string) *exec.Cmd {
5959
// tcpdump: Couldn't find user 'tcpdump'
6060
// To disable this behavior, we use `--relinquish-privileges=root` same as `-Z root`.
6161
// ref: https://manpages.debian.org/bullseye/tcpdump/tcpdump.8.en.html#Z
62-
captureStartCmd := exec.Command(
62+
captureStartCmd := exec.Command( //nolint:noctx // tcpdump is managed via process signals, not context cancellation
6363
"tcpdump",
6464
"-w", captureFilePath,
6565
"--relinquish-privileges=root",

pkg/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ var (
5656
"telemetryInterval smaller than %v is not allowed",
5757
MinTelemetryInterval,
5858
)
59-
DefaultTelemetryInterval = 15 * time.Minute
60-
DefaultSamplingRate uint32 = 1
61-
DefaultFilterMapMaxEntries uint32 = 255
62-
DefaultConntrackReportInterval = 30 * time.Second
59+
DefaultTelemetryInterval = 15 * time.Minute
60+
DefaultSamplingRate uint32 = 1
61+
DefaultFilterMapMaxEntries uint32 = 255
62+
DefaultConntrackReportInterval = 30 * time.Second
6363
)
6464

6565
func (l *Level) UnmarshalText(text []byte) error {

pkg/controllers/daemon/node/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ func (r *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
7676
}
7777

7878
if len(node.Status.Addresses) == 0 {
79-
r.l.Warn("Node has no addresses", zap.String("Node", req.NamespacedName.String()))
79+
r.l.Warn("Node has no addresses", zap.String("Node", req.Name))
8080
return ctrl.Result{}, nil
8181
}
8282

8383
retinaNodeCommon := retinaCommon.NewRetinaNode(node.Name, net.ParseIP(node.Status.Addresses[0].Address), node.Labels[corev1.LabelTopologyZone])
8484
if err := r.cache.UpdateRetinaNode(retinaNodeCommon); err != nil {
85-
r.l.Error("Failed to update RetinaNode in Cache", zap.Error(err), zap.String("Node", req.NamespacedName.String()))
85+
r.l.Error("Failed to update RetinaNode in Cache", zap.Error(err), zap.String("Node", req.String()))
8686
return ctrl.Result{}, err
8787
}
8888

pkg/enricher/enricher_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
)
2727

28+
const logLevelDebug = "debug"
29+
2830
var (
2931
// number of events
3032
eventsGeneratedCount = 5
@@ -90,7 +92,7 @@ func writeEventToEnricher(t *testing.T, e *Enricher, ev *v1.Event) {
9092

9193
func TestEnricher(t *testing.T) {
9294
opts := log.GetDefaultLogOpts()
93-
opts.Level = "debug"
95+
opts.Level = logLevelDebug
9496
_, err := log.SetupZapLogger(opts)
9597
require.NoError(t, err)
9698

@@ -145,7 +147,7 @@ func TestEnricherSecondaryIPs(t *testing.T) {
145147
expectedOutputCount := 18
146148

147149
opts := log.GetDefaultLogOpts()
148-
opts.Level = "debug"
150+
opts.Level = logLevelDebug
149151
log.SetupZapLogger(opts)
150152
l := log.Logger().Named("test-enricher")
151153

@@ -245,7 +247,7 @@ func assertEqualEndpoint(t *testing.T, expected *common.RetinaEndpoint, actual *
245247

246248
func TestEnricherZoneResolution(t *testing.T) {
247249
opts := log.GetDefaultLogOpts()
248-
opts.Level = "debug"
250+
opts.Level = logLevelDebug
249251
_, err := log.SetupZapLogger(opts)
250252
require.NoError(t, err)
251253

@@ -310,7 +312,7 @@ func TestEnricherZoneResolution(t *testing.T) {
310312

311313
func TestEnricherZoneResolution_NoNode(t *testing.T) {
312314
opts := log.GetDefaultLogOpts()
313-
opts.Level = "debug"
315+
opts.Level = logLevelDebug
314316
_, err := log.SetupZapLogger(opts)
315317
require.NoError(t, err)
316318

0 commit comments

Comments
 (0)