Skip to content

Commit 6b42617

Browse files
chansukechengfang
andauthored
chore: use context.Background() instead of context.TODO() (#1163)
Signed-off-by: chansuke <moonset20@gmail.com> Co-authored-by: Cheng Fang <cfang@redhat.com>
1 parent daf5543 commit 6b42617

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func runImageUpdater(cfg *ImageUpdaterConfig, warmUp bool) (argocd.ImageUpdaterR
316316
wg.Add(len(appList))
317317

318318
for app, curApplication := range appList {
319-
lockErr := sem.Acquire(context.TODO(), 1)
319+
lockErr := sem.Acquire(context.Background(), 1)
320320
if lockErr != nil {
321321
log.Errorf("Could not acquire semaphore for application %s: %v", app, lockErr)
322322
// Release entry in wait group on error, too - we're never gonna execute

cmd/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestGetKubeConfig(t *testing.T) {
4141

4242
for _, tt := range tests {
4343
t.Run(tt.name, func(t *testing.T) {
44-
client, err := getKubeConfig(context.TODO(), tt.namespace, tt.configPath)
44+
client, err := getKubeConfig(context.Background(), tt.namespace, tt.configPath)
4545
if tt.expectError {
4646
require.Error(t, err)
4747
} else {

pkg/argocd/argocd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (client *k8sClient) getApplicationInAllNamespaces(appName string) (*v1alpha
6969

7070
// ListApplications lists all applications across all namespaces.
7171
func (client *k8sClient) ListApplications(labelSelector string) ([]v1alpha1.Application, error) {
72-
list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(*client.appNamespace).List(context.TODO(), v1.ListOptions{LabelSelector: labelSelector})
72+
list, err := client.kubeClient.ApplicationsClientset.ArgoprojV1alpha1().Applications(*client.appNamespace).List(context.Background(), v1.ListOptions{LabelSelector: labelSelector})
7373
if err != nil {
7474
return nil, fmt.Errorf("error listing applications: %w", err)
7575
}

pkg/argocd/argocd_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,19 +1035,19 @@ func TestKubernetesClient(t *testing.T) {
10351035
})
10361036

10371037
t.Run("Get application test-app1 successful", func(t *testing.T) {
1038-
app, err := client.GetApplication(context.TODO(), "test-app1")
1038+
app, err := client.GetApplication(context.Background(), "test-app1")
10391039
require.NoError(t, err)
10401040
assert.Equal(t, "test-app1", app.GetName())
10411041
})
10421042

10431043
t.Run("Get application test-app2 successful", func(t *testing.T) {
1044-
app, err := client.GetApplication(context.TODO(), "test-app2")
1044+
app, err := client.GetApplication(context.Background(), "test-app2")
10451045
require.NoError(t, err)
10461046
assert.Equal(t, "test-app2", app.GetName())
10471047
})
10481048

10491049
t.Run("Get application not found", func(t *testing.T) {
1050-
_, err := client.GetApplication(context.TODO(), "test-app-non-existent")
1050+
_, err := client.GetApplication(context.Background(), "test-app-non-existent")
10511051
require.Error(t, err)
10521052
assert.Contains(t, err.Error(), "application test-app-non-existent not found")
10531053
})
@@ -1073,7 +1073,7 @@ func TestKubernetesClient(t *testing.T) {
10731073
assert.EqualError(t, err, "error listing applications: Internal error occurred: list error")
10741074

10751075
// Test GetApplication error handling
1076-
_, err = client.GetApplication(context.TODO(), "test-app")
1076+
_, err = client.GetApplication(context.Background(), "test-app")
10771077
assert.Error(t, err)
10781078
assert.Contains(t, err.Error(), "error listing applications: Internal error occurred: list error")
10791079
})
@@ -1098,7 +1098,7 @@ func TestKubernetesClient(t *testing.T) {
10981098
require.NoError(t, err)
10991099

11001100
// Test GetApplication with multiple matching applications
1101-
_, err = client.GetApplication(context.TODO(), "test-app")
1101+
_, err = client.GetApplication(context.Background(), "test-app")
11021102
assert.Error(t, err)
11031103
assert.EqualError(t, err, "multiple applications found matching test-app")
11041104
})
@@ -1128,7 +1128,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) {
11281128
require.NoError(t, err)
11291129

11301130
appName := "test-app"
1131-
spec, err := client.UpdateSpec(context.TODO(), &application.ApplicationUpdateSpecRequest{
1131+
spec, err := client.UpdateSpec(context.Background(), &application.ApplicationUpdateSpecRequest{
11321132
Name: &appName,
11331133
Spec: &v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{
11341134
RepoURL: "https://github.com/argoproj/argocd-example-apps",
@@ -1156,7 +1156,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) {
11561156
Spec: &v1alpha1.ApplicationSpec{},
11571157
}
11581158

1159-
_, err = client.UpdateSpec(context.TODO(), spec)
1159+
_, err = client.UpdateSpec(context.Background(), spec)
11601160
assert.Error(t, err)
11611161
assert.Contains(t, err.Error(), "error getting application: application test-app not found")
11621162
})
@@ -1185,7 +1185,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) {
11851185
Spec: &v1alpha1.ApplicationSpec{},
11861186
}
11871187

1188-
_, err = client.UpdateSpec(context.TODO(), spec)
1188+
_, err = client.UpdateSpec(context.Background(), spec)
11891189
assert.Error(t, err)
11901190
assert.Contains(t, err.Error(), "max retries(0) reached while updating application: test-app")
11911191
})
@@ -1213,7 +1213,7 @@ func TestKubernetesClientUpdateSpec(t *testing.T) {
12131213
Spec: &v1alpha1.ApplicationSpec{},
12141214
}
12151215

1216-
_, err = client.UpdateSpec(context.TODO(), spec)
1216+
_, err = client.UpdateSpec(context.Background(), spec)
12171217
assert.Error(t, err)
12181218
assert.Contains(t, err.Error(), "error updating application: non-conflict error")
12191219
})

registry-scanner/pkg/registry/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (endpoint *RegistryEndpoint) GetTags(img *image.ContainerImage, regClient R
124124

125125
logCtx.Tracef("Getting manifest for image %s:%s (operation %d/%d)", nameInRegistry, tagStr, i, len(tags))
126126

127-
lockErr := sem.Acquire(context.TODO(), 1)
127+
lockErr := sem.Acquire(context.Background(), 1)
128128
if lockErr != nil {
129129
log.Warnf("could not acquire semaphore: %v", lockErr)
130130
wg.Done()

0 commit comments

Comments
 (0)