From 96db451723e5c30785e729899ee458b07ceb6869 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 10 Sep 2024 14:42:38 +0200 Subject: [PATCH] Fix golangci-lint issues Signed-off-by: Vincent Demeester --- cmd/entrypoint/subcommands/subcommands.go | 1 - pkg/apis/config/feature_flags_test.go | 2 +- pkg/pod/creds_init_test.go | 4 ++-- pkg/pod/pod.go | 4 ++-- pkg/reconciler/events/k8sevent/events.go | 2 +- .../pipelinerun/resources/pipelineref_test.go | 12 +++++------- pkg/reconciler/taskrun/resources/taskref_test.go | 10 +++++----- 7 files changed, 16 insertions(+), 19 deletions(-) diff --git a/cmd/entrypoint/subcommands/subcommands.go b/cmd/entrypoint/subcommands/subcommands.go index a4e7838192c..b9229546d8d 100644 --- a/cmd/entrypoint/subcommands/subcommands.go +++ b/cmd/entrypoint/subcommands/subcommands.go @@ -98,7 +98,6 @@ func Process(args []string) error { return OK{message: "Decoded script " + src} } case StepInitCommand: - //nolint: gosec if err := stepInit(args[1:]); err != nil { return SubcommandError{subcommand: StepInitCommand, message: err.Error()} } diff --git a/pkg/apis/config/feature_flags_test.go b/pkg/apis/config/feature_flags_test.go index c9eca976953..30c0e06a8e0 100644 --- a/pkg/apis/config/feature_flags_test.go +++ b/pkg/apis/config/feature_flags_test.go @@ -332,7 +332,6 @@ func TestNewFeatureFlagsConfigMapErrors(t *testing.T) { } func TestGetVerificationNoMatchPolicy(t *testing.T) { - ctx := context.Background() tcs := []struct { name, noMatchPolicy, expected string }{{ @@ -351,6 +350,7 @@ func TestGetVerificationNoMatchPolicy(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { + ctx := context.Background() store := config.NewStore(logging.FromContext(ctx).Named("config-store")) featureflags := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/pod/creds_init_test.go b/pkg/pod/creds_init_test.go index c7dcacf81c3..33f2e32a0be 100644 --- a/pkg/pod/creds_init_test.go +++ b/pkg/pod/creds_init_test.go @@ -335,8 +335,8 @@ func TestCredsInit(t *testing.T) { eventObj := &corev1.Event{} kubeclient := fakek8s.NewSimpleClientset(c.objs...) recorder := record.NewFakeRecorder(1000) - c.ctx = controller.WithEventRecorder(c.ctx, recorder) - args, volumes, volumeMounts, err := credsInit(c.ctx, eventObj, serviceAccountName, namespace, kubeclient) + ctx := controller.WithEventRecorder(c.ctx, recorder) + args, volumes, volumeMounts, err := credsInit(ctx, eventObj, serviceAccountName, namespace, kubeclient) if err != nil { t.Fatalf("credsInit: %v", err) } diff --git a/pkg/pod/pod.go b/pkg/pod/pod.go index ad58b473910..61c40ef92ae 100644 --- a/pkg/pod/pod.go +++ b/pkg/pod/pod.go @@ -336,7 +336,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1.TaskRun, taskSpec v1.Ta // Each step should only mount their own volume as RW, // all other steps should be mounted RO. volumes = append(volumes, runVolume(i)) - for j := range len(stepContainers) { + for j := range stepContainers { s.VolumeMounts = append(s.VolumeMounts, runMount(j, i != j)) } @@ -362,7 +362,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1.TaskRun, taskSpec v1.Ta if s.Name != pipeline.ReservedResultsSidecarName { continue } - for j := range len(stepContainers) { + for j := range stepContainers { s.VolumeMounts = append(s.VolumeMounts, runMount(j, true)) } requestedVolumeMounts := map[string]bool{} diff --git a/pkg/reconciler/events/k8sevent/events.go b/pkg/reconciler/events/k8sevent/events.go index 15b4eb76790..048308de881 100644 --- a/pkg/reconciler/events/k8sevent/events.go +++ b/pkg/reconciler/events/k8sevent/events.go @@ -46,7 +46,7 @@ func eventsFromChannel(c chan string, wantEvents []string) error { // on the channel forever if fewer than expected events are received timer := time.After(wait.ForeverTestTimeout) foundEvents := []string{} - for ii := range len(wantEvents) { + for ii := range wantEvents { // We loop over all the events that we expect. Once they are all received // we exit the loop. If we never receive enough events, the timeout takes us // out of the loop. diff --git a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go index a58992af187..e10fbcd9134 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go @@ -741,7 +741,7 @@ func TestGetPipelineFunc_V1beta1Pipeline_VerifyNoError(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - ctx = test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) + ctx := test.SetupTrustedResourceConfig(context.Background(), tc.verificationNoMatchPolicy) fn := resources.GetPipelineFunc(ctx, k8sclient, tektonclient, tc.requester, &tc.pipelinerun, tc.policies) gotResolvedPipeline, gotSource, gotVerificationResult, err := fn(ctx, pipelineRef.Name) @@ -768,7 +768,6 @@ func TestGetPipelineFunc_V1beta1Pipeline_VerifyNoError(t *testing.T) { } func TestGetPipelineFunc_V1beta1Pipeline_VerifyError(t *testing.T) { - ctx := context.Background() tektonclient := fake.NewSimpleClientset() signer, _, k8sclient, vps := test.SetupVerificationPolicies(t) @@ -863,7 +862,7 @@ func TestGetPipelineFunc_V1beta1Pipeline_VerifyError(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - ctx = test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) + ctx := test.SetupTrustedResourceConfig(context.Background(), tc.verificationNoMatchPolicy) pr := &v1.PipelineRun{ ObjectMeta: metav1.ObjectMeta{Namespace: "trusted-resources"}, Spec: v1.PipelineRunSpec{ @@ -1072,7 +1071,7 @@ func TestGetPipelineFunc_V1Pipeline_VerifyNoError(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - ctx = test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) + ctx := test.SetupTrustedResourceConfig(context.Background(), tc.verificationNoMatchPolicy) fn := resources.GetPipelineFunc(ctx, k8sclient, tektonclient, tc.requester, &tc.pipelinerun, tc.policies) gotResolvedPipeline, gotSource, gotVerificationResult, err := fn(ctx, pipelineRef.Name) @@ -1099,7 +1098,6 @@ func TestGetPipelineFunc_V1Pipeline_VerifyNoError(t *testing.T) { } func TestGetPipelineFunc_V1Pipeline_VerifyError(t *testing.T) { - ctx := context.Background() tektonclient := fake.NewSimpleClientset() signer, _, k8sclient, vps := test.SetupVerificationPolicies(t) @@ -1193,7 +1191,7 @@ func TestGetPipelineFunc_V1Pipeline_VerifyError(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - ctx = test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) + ctx := test.SetupTrustedResourceConfig(context.Background(), tc.verificationNoMatchPolicy) pr := &v1.PipelineRun{ ObjectMeta: metav1.ObjectMeta{Namespace: "trusted-resources"}, Spec: v1.PipelineRunSpec{ @@ -1215,7 +1213,6 @@ func TestGetPipelineFunc_V1Pipeline_VerifyError(t *testing.T) { } func TestGetPipelineFunc_GetFuncError(t *testing.T) { - ctx := context.Background() tektonclient := fake.NewSimpleClientset() _, k8sclient, vps := test.SetupMatchAllVerificationPolicies(t, "trusted-resources") @@ -1259,6 +1256,7 @@ func TestGetPipelineFunc_GetFuncError(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { + ctx := context.Background() store := config.NewStore(logging.FromContext(ctx).Named("config-store")) featureflags := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/reconciler/taskrun/resources/taskref_test.go b/pkg/reconciler/taskrun/resources/taskref_test.go index 01d98c05025..2354743e63a 100644 --- a/pkg/reconciler/taskrun/resources/taskref_test.go +++ b/pkg/reconciler/taskrun/resources/taskref_test.go @@ -1430,7 +1430,7 @@ func TestGetTaskFunc_V1beta1Task_VerifyNoError(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - ctx = test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) + ctx := test.SetupTrustedResourceConfig(context.Background(), tc.verificationNoMatchPolicy) tr := &v1.TaskRun{ ObjectMeta: metav1.ObjectMeta{Namespace: "trusted-resources"}, Spec: v1.TaskRunSpec{ @@ -1558,7 +1558,7 @@ func TestGetTaskFunc_V1beta1Task_VerifyError(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - ctx = test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) + ctx := test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) tr := &v1.TaskRun{ ObjectMeta: metav1.ObjectMeta{Namespace: "trusted-resources"}, Spec: v1.TaskRunSpec{ @@ -1694,7 +1694,7 @@ func TestGetTaskFunc_V1Task_VerifyNoError(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - ctx = test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) + ctx := test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) tr := &v1.TaskRun{ ObjectMeta: metav1.ObjectMeta{Namespace: "trusted-resources"}, Spec: v1.TaskRunSpec{ @@ -1820,7 +1820,7 @@ func TestGetTaskFunc_V1Task_VerifyError(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - ctx = test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) + ctx := test.SetupTrustedResourceConfig(ctx, tc.verificationNoMatchPolicy) tr := &v1.TaskRun{ ObjectMeta: metav1.ObjectMeta{Namespace: "trusted-resources"}, Spec: v1.TaskRunSpec{ @@ -1892,7 +1892,7 @@ func TestGetTaskFunc_GetFuncError(t *testing.T) { }, } store.OnConfigChanged(featureflags) - ctx = store.ToContext(ctx) + ctx := store.ToContext(ctx) fn := resources.GetTaskFunc(ctx, k8sclient, tektonclient, tc.requester, &tc.taskrun, tc.taskrun.Spec.TaskRef, "", "default", "default", vps)