Skip to content

Commit f146a97

Browse files
committed
Use contextcheck
1 parent ef69b57 commit f146a97

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
linters:
22
enable:
3+
- contextcheck
34
- errcheck
45
- exhaustive
56
- gofumpt

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PROG := cluster-image-registry-operator
44

55
GOLANGCI_LINT = _output/tools/golangci-lint
66
GOLANGCI_LINT_CACHE = $(PWD)/_output/golangci-lint-cache
7-
GOLANGCI_LINT_VERSION = v1.50.0
7+
GOLANGCI_LINT_VERSION = v1.50.1
88

99
GO_REQUIRED_MIN_VERSION = 1.16
1010

pkg/client/operatorclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (c *ConfigOperatorClient) UpdateOperatorStatus(ctx context.Context, oldReso
7777

7878
config.Status.OperatorStatus = *in
7979

80-
updatedConfig, err := c.client.UpdateStatus(context.TODO(), config, metav1.UpdateOptions{})
80+
updatedConfig, err := c.client.UpdateStatus(ctx, config, metav1.UpdateOptions{})
8181
if err != nil {
8282
return nil, err
8383
}

pkg/operator/starter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func RunOperator(ctx context.Context, kubeconfig *restclient.Config) error {
6262

6363
// library-go just logs a warning and continues
6464
// https://github.com/openshift/library-go/blob/4362aa519714a4b62b00ab8318197ba2bba51cb7/pkg/controller/controllercmd/builder.go#L230
65-
controllerRef, err := events.GetControllerReferenceForCurrentPod(context.TODO(), kubeClient, defaults.ImageRegistryOperatorNamespace, nil)
65+
controllerRef, err := events.GetControllerReferenceForCurrentPod(ctx, kubeClient, defaults.ImageRegistryOperatorNamespace, nil)
6666
if err != nil {
6767
klog.Warningf("unable to get owner reference (falling back to namespace): %v", err)
6868
}

test/e2e/removed_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func dumpBuildInfo(ctx context.Context, te framework.TestEnv, nsName string, bui
143143
}
144144
te.Log("attempting to dump build information")
145145
buildPodName := fmt.Sprintf("%s-build", buildName)
146-
buildLogs, err := framework.GetLogsForPod(te.Client(), nsName, buildPodName)
146+
buildLogs, err := framework.GetLogsForPod(ctx, te.Client(), nsName, buildPodName)
147147
if err != nil {
148148
te.Logf("failed to get build logs: %v", err)
149149
} else {

test/framework/logs.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ func (psl PodSetLogs) Contains(re *regexp.Regexp) bool {
4646
}
4747

4848
func GetLogsByLabelSelector(client *Clientset, namespace string, labelSelector *metav1.LabelSelector, previous bool) (PodSetLogs, error) {
49+
ctx := context.Background()
50+
4951
selector, err := metav1.LabelSelectorAsSelector(labelSelector)
5052
if err != nil {
5153
return nil, err
5254
}
5355

5456
podList, err := client.Pods(namespace).List(
55-
context.Background(), metav1.ListOptions{
57+
ctx, metav1.ListOptions{
5658
LabelSelector: selector.String(),
5759
},
5860
)
@@ -62,7 +64,7 @@ func GetLogsByLabelSelector(client *Clientset, namespace string, labelSelector *
6264

6365
podLogs := make(PodSetLogs)
6466
for _, pod := range podList.Items {
65-
podLog, err := readPodLogs(client, &pod, previous)
67+
podLog, err := readPodLogs(ctx, client, &pod, previous)
6668
if err != nil {
6769
return nil, err
6870
}
@@ -71,13 +73,12 @@ func GetLogsByLabelSelector(client *Clientset, namespace string, labelSelector *
7173
return podLogs, nil
7274
}
7375

74-
func GetLogsForPod(client *Clientset, namespace string, podName string) (PodSetLogs, error) {
75-
ctx := context.Background()
76+
func GetLogsForPod(ctx context.Context, client *Clientset, namespace string, podName string) (PodSetLogs, error) {
7677
pod, err := client.Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
7778
if err != nil {
7879
return nil, err
7980
}
80-
podLogs, err := readPodLogs(client, pod, false)
81+
podLogs, err := readPodLogs(ctx, client, pod, false)
8182
if err != nil {
8283
return nil, err
8384
}
@@ -86,14 +87,14 @@ func GetLogsForPod(client *Clientset, namespace string, podName string) (PodSetL
8687
return podSetLogs, nil
8788
}
8889

89-
func readPodLogs(client *Clientset, pod *corev1.Pod, previous bool) (PodLog, error) {
90+
func readPodLogs(ctx context.Context, client *Clientset, pod *corev1.Pod, previous bool) (PodLog, error) {
9091
podLog := make(PodLog)
9192
for _, container := range pod.Spec.Containers {
9293
var containerLog ContainerLog
9394
log, err := client.Pods(pod.Namespace).GetLogs(pod.Name, &corev1.PodLogOptions{
9495
Container: container.Name,
9596
Previous: previous,
96-
}).Stream(context.Background())
97+
}).Stream(ctx)
9798
if err != nil {
9899
return nil, fmt.Errorf("failed to get logs for pod %s: %s", pod.Name, err)
99100
}

0 commit comments

Comments
 (0)