From e0bef38a65cf50b4ef4ab605c04b1469769594bb Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Mon, 13 Nov 2023 13:35:15 +0100 Subject: [PATCH] fix lint issues --- cmd/install.go | 19 +++++++++++-------- make/lint.mk | 2 +- pkg/utils/external_resource_reader.go | 6 +++--- pkg/utils/http_utils.go | 4 ++-- pkg/utils/k8s_utils.go | 4 ++-- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index 9d1741b..755664f 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -101,8 +101,9 @@ func waitForDeployments(k8sClient client.Client) error { } for _, key := range deploymentKeys { - err := wait.Poll(retryInterval, timeout, func() (bool, error) { - return utils.CheckDeploymentAvailable(k8sClient, key) + immediate := true + err := wait.PollUntilContextTimeout(context.Background(), retryInterval, timeout, immediate, func(ctx context.Context) (bool, error) { + return utils.CheckDeploymentAvailable(ctx, k8sClient, key) }) if err != nil { @@ -147,10 +148,11 @@ func deployKuadrantOperator(k8sClient client.Client) error { var installPlanKey client.ObjectKey // Wait for the install process to be completed + immediate := true logf.Log.Info("Waiting for the kuadrant operator installation") - err = wait.Poll(time.Second*2, time.Second*20, func() (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second*2, time.Second*20, immediate, func(ctx context.Context) (bool, error) { existingSubs := &operators.Subscription{} - err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(subs), existingSubs) + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(subs), existingSubs) if err != nil { if apierrors.IsNotFound(err) { logf.Log.Info("Subscription not available", "name", client.ObjectKeyFromObject(subs)) @@ -176,9 +178,9 @@ func deployKuadrantOperator(k8sClient client.Client) error { } logf.Log.Info("Waiting for the install plan", "name", installPlanKey) - err = wait.Poll(time.Second*5, time.Minute*2, func() (bool, error) { + err = wait.PollUntilContextTimeout(context.Background(), time.Second*5, time.Minute*2, immediate, func(ctx context.Context) (bool, error) { ip := &operators.InstallPlan{} - err := k8sClient.Get(context.Background(), installPlanKey, ip) + err := k8sClient.Get(ctx, installPlanKey, ip) if err != nil { if apierrors.IsNotFound(err) { logf.Log.Info("Install plan not available", "name", installPlanKey) @@ -230,8 +232,9 @@ func createNamespace(k8sClient client.Client) error { retryInterval := time.Second * 2 timeout := time.Second * 20 - return wait.Poll(retryInterval, timeout, func() (bool, error) { - err := k8sClient.Get(context.Background(), types.NamespacedName{Name: installNamespace}, &corev1.Namespace{}) + immediate := true + return wait.PollUntilContextTimeout(context.Background(), retryInterval, timeout, immediate, func(ctx context.Context) (bool, error) { + err := k8sClient.Get(ctx, types.NamespacedName{Name: installNamespace}, &corev1.Namespace{}) if err != nil && apierrors.IsNotFound(err) { return false, nil } diff --git a/make/lint.mk b/make/lint.mk index 45842b0..c190494 100644 --- a/make/lint.mk +++ b/make/lint.mk @@ -1,7 +1,7 @@ GOLANGCI-LINT=$(PROJECT_PATH)/bin/golangci-lint $(GOLANGCI-LINT): mkdir -p $(PROJECT_PATH)/bin - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.41.1 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_PATH)/bin v1.55.2 .PHONY: golangci-lint golangci-lint: $(GOLANGCI-LINT) diff --git a/pkg/utils/external_resource_reader.go b/pkg/utils/external_resource_reader.go index d60642a..43dd6bf 100644 --- a/pkg/utils/external_resource_reader.go +++ b/pkg/utils/external_resource_reader.go @@ -16,7 +16,7 @@ limitations under the License. package utils import ( - "io/ioutil" + "io" "os" ) @@ -26,7 +26,7 @@ import ( // - Files func ReadExternalResource(resource string) ([]byte, error) { if resource == "@" { - return ioutil.ReadAll(os.Stdin) + return io.ReadAll(os.Stdin) } if url, isURL := ParseURL(resource); isURL { @@ -34,5 +34,5 @@ func ReadExternalResource(resource string) ([]byte, error) { } // Defaulting to filepath - return ioutil.ReadFile(resource) + return os.ReadFile(resource) } diff --git a/pkg/utils/http_utils.go b/pkg/utils/http_utils.go index 4a90cd7..9d2195c 100644 --- a/pkg/utils/http_utils.go +++ b/pkg/utils/http_utils.go @@ -16,7 +16,7 @@ limitations under the License. package utils import ( - "io/ioutil" + "io" "net/http" "net/url" ) @@ -32,7 +32,7 @@ func ReadURL(location *url.URL) ([]byte, error) { if err != nil { return nil, err } - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { return nil, err diff --git a/pkg/utils/k8s_utils.go b/pkg/utils/k8s_utils.go index 075b9d4..80e87d6 100644 --- a/pkg/utils/k8s_utils.go +++ b/pkg/utils/k8s_utils.go @@ -123,9 +123,9 @@ func IsDeploymentAvailable(dc *appsv1.Deployment) bool { return false } -func CheckDeploymentAvailable(k8sClient client.Client, key types.NamespacedName) (bool, error) { +func CheckDeploymentAvailable(ctx context.Context, k8sClient client.Client, key types.NamespacedName) (bool, error) { existingDeployment := &appsv1.Deployment{} - err := k8sClient.Get(context.Background(), key, existingDeployment) + err := k8sClient.Get(ctx, key, existingDeployment) if err != nil { if apierrors.IsNotFound(err) { logf.Log.Info("Deployment not available", "name", key.Name)