From 6be46d9a7be494fc1bb92c759be6d22829679e5d Mon Sep 17 00:00:00 2001 From: chansuke Date: Sat, 7 Jun 2025 03:17:09 +0900 Subject: [PATCH] chore: use context.Background() instead of context.TODO() Signed-off-by: chansuke --- cmd/run.go | 2 +- cmd/util_test.go | 2 +- pkg/argocd/argocd.go | 2 +- pkg/argocd/argocd_test.go | 18 +++++++++--------- registry-scanner/pkg/registry/registry.go | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 6e51e5e2..d9b96a9c 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -316,7 +316,7 @@ func runImageUpdater(cfg *ImageUpdaterConfig, warmUp bool) (argocd.ImageUpdaterR wg.Add(len(appList)) for app, curApplication := range appList { - lockErr := sem.Acquire(context.TODO(), 1) + lockErr := sem.Acquire(context.Background(), 1) if lockErr != nil { log.Errorf("Could not acquire semaphore for application %s: %v", app, lockErr) // Release entry in wait group on error, too - we're never gonna execute diff --git a/cmd/util_test.go b/cmd/util_test.go index 5b3a428b..012e8161 100644 --- a/cmd/util_test.go +++ b/cmd/util_test.go @@ -41,7 +41,7 @@ func TestGetKubeConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - client, err := getKubeConfig(context.TODO(), tt.namespace, tt.configPath) + client, err := getKubeConfig(context.Background(), tt.namespace, tt.configPath) if tt.expectError { require.Error(t, err) } else { diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go index b7d053d4..a06d351a 100644 --- a/pkg/argocd/argocd.go +++ b/pkg/argocd/argocd.go @@ -69,7 +69,7 @@ func (client *k8sClient) getApplicationInAllNamespaces(appName string) (*v1alpha // ListApplications lists all applications across all namespaces. func (client *k8sClient) ListApplications(labelSelector string) ([]v1alpha1.Application, error) { - list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(*client.appNamespace).List(context.TODO(), v1.ListOptions{LabelSelector: labelSelector}) + list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(*client.appNamespace).List(context.Background(), v1.ListOptions{LabelSelector: labelSelector}) if err != nil { return nil, fmt.Errorf("error listing applications: %w", err) } diff --git a/pkg/argocd/argocd_test.go b/pkg/argocd/argocd_test.go index b19a0278..261cc9f0 100644 --- a/pkg/argocd/argocd_test.go +++ b/pkg/argocd/argocd_test.go @@ -1035,19 +1035,19 @@ func TestKubernetesClient(t *testing.T) { }) t.Run("Get application test-app1 successful", func(t *testing.T) { - app, err := client.GetApplication(context.TODO(), "test-app1") + app, err := client.GetApplication(context.Background(), "test-app1") require.NoError(t, err) assert.Equal(t, "test-app1", app.GetName()) }) t.Run("Get application test-app2 successful", func(t *testing.T) { - app, err := client.GetApplication(context.TODO(), "test-app2") + app, err := client.GetApplication(context.Background(), "test-app2") require.NoError(t, err) assert.Equal(t, "test-app2", app.GetName()) }) t.Run("Get application not found", func(t *testing.T) { - _, err := client.GetApplication(context.TODO(), "test-app-non-existent") + _, err := client.GetApplication(context.Background(), "test-app-non-existent") require.Error(t, err) assert.Contains(t, err.Error(), "application test-app-non-existent not found") }) @@ -1073,7 +1073,7 @@ func TestKubernetesClient(t *testing.T) { assert.EqualError(t, err, "error listing applications: Internal error occurred: list error") // Test GetApplication error handling - _, err = client.GetApplication(context.TODO(), "test-app") + _, err = client.GetApplication(context.Background(), "test-app") assert.Error(t, err) assert.Contains(t, err.Error(), "error listing applications: Internal error occurred: list error") }) @@ -1098,7 +1098,7 @@ func TestKubernetesClient(t *testing.T) { require.NoError(t, err) // Test GetApplication with multiple matching applications - _, err = client.GetApplication(context.TODO(), "test-app") + _, err = client.GetApplication(context.Background(), "test-app") assert.Error(t, err) assert.EqualError(t, err, "multiple applications found matching test-app") }) @@ -1128,7 +1128,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) { require.NoError(t, err) appName := "test-app" - spec, err := client.UpdateSpec(context.TODO(), &application.ApplicationUpdateSpecRequest{ + spec, err := client.UpdateSpec(context.Background(), &application.ApplicationUpdateSpecRequest{ Name: &appName, Spec: &v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{ RepoURL: "https://github.com/argoproj/argocd-example-apps", @@ -1156,7 +1156,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) { Spec: &v1alpha1.ApplicationSpec{}, } - _, err = client.UpdateSpec(context.TODO(), spec) + _, err = client.UpdateSpec(context.Background(), spec) assert.Error(t, err) assert.Contains(t, err.Error(), "error getting application: application test-app not found") }) @@ -1185,7 +1185,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) { Spec: &v1alpha1.ApplicationSpec{}, } - _, err = client.UpdateSpec(context.TODO(), spec) + _, err = client.UpdateSpec(context.Background(), spec) assert.Error(t, err) assert.Contains(t, err.Error(), "max retries(0) reached while updating application: test-app") }) @@ -1213,7 +1213,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) { Spec: &v1alpha1.ApplicationSpec{}, } - _, err = client.UpdateSpec(context.TODO(), spec) + _, err = client.UpdateSpec(context.Background(), spec) assert.Error(t, err) assert.Contains(t, err.Error(), "error updating application: non-conflict error") }) diff --git a/registry-scanner/pkg/registry/registry.go b/registry-scanner/pkg/registry/registry.go index 5c84b8f2..fb0143df 100644 --- a/registry-scanner/pkg/registry/registry.go +++ b/registry-scanner/pkg/registry/registry.go @@ -124,7 +124,7 @@ func (endpoint *RegistryEndpoint) GetTags(img *image.ContainerImage, regClient R logCtx.Tracef("Getting manifest for image %s:%s (operation %d/%d)", nameInRegistry, tagStr, i, len(tags)) - lockErr := sem.Acquire(context.TODO(), 1) + lockErr := sem.Acquire(context.Background(), 1) if lockErr != nil { log.Warnf("could not acquire semaphore: %v", lockErr) wg.Done()