From 1eb880a0b4beecfc69856127cb4b839855fc8939 Mon Sep 17 00:00:00 2001 From: Thomas Guettler Date: Wed, 4 Sep 2024 13:57:25 +0200 Subject: [PATCH] ... make linter happy. --- .gitignore | 3 +++ .golangci.yaml | 19 +++++-------------- Makefile | 4 ++-- go.mod | 2 +- .../controller/clusteraddon_controller.go | 19 +++++++++++-------- .../controller/clusterstack_controller.go | 12 ++++++------ .../clusterstackrelease_controller.go | 9 ++++++--- pkg/assetsclient/github/client.go | 2 +- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index bfdd9323b..6d10773d3 100644 --- a/.gitignore +++ b/.gitignore @@ -82,3 +82,6 @@ main *.tgz.yaml *.build.yaml .release + +# .config/go/telemetry/local/ +.config diff --git a/.golangci.yaml b/.golangci.yaml index eb96277e6..ec881ccde 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -12,7 +12,7 @@ linters: - errname - errorlint - exhaustive - - exportloopref + - copyloopvar - forcetypeassert - gci - goconst @@ -86,10 +86,7 @@ linters-settings: allow-unused: false allow-leading-space: false require-specific: true - staticcheck: - go: "1.21" stylecheck: - go: "1.21" checks: ["all", "-ST1006"] dot-import-whitelist: - "github.com/onsi/gomega" @@ -247,9 +244,6 @@ linters-settings: # Suggest the use of rpc.DefaultXXPath. # Default: false default-rpc-path: true - # Suggest the use of os.DevNull. - # Default: false - os-dev-null: true # Suggest the use of sql.LevelXX.String(). # Default: false sql-isolation-level: true @@ -259,9 +253,6 @@ linters-settings: # Suggest the use of constant.Kind.String(). # Default: false constant-kind: true - # Suggest the use of syslog.Priority. - # Default: false - syslog-priority: true wrapcheck: ignoreSigs: - status.Error( @@ -285,11 +276,11 @@ issues: - linters: - wrapcheck path: _test\.go + exclude-dirs: + - vendor$ + - test/vendor$ run: timeout: 10m - go: "1.21" + go: "1.22" allow-parallel-runners: true modules-download-mode: vendor - skip-dirs: - - vendor$ - - test/vendor$ diff --git a/Makefile b/Makefile index 04651eb36..d746c9b5a 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ MGT_CLUSTER_KUBECONFIG ?= ".mgt-cluster-kubeconfig.yaml" # Kubebuilder. export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.29.3 -# versions +# versions CTLPTL_VERSION := 0.8.25 ##@ Binaries @@ -445,7 +445,7 @@ ifeq ($(BUILD_IN_CONTAINER),true) else go version golangci-lint version - GO111MODULE=on golangci-lint run -v --out-format=github-actions + GO111MODULE=on golangci-lint run -v --out-format=colored-line-number endif .PHONY: lint-yaml diff --git a/go.mod b/go.mod index c92508b16..6c809ddd8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/SovereignCloudStack/cluster-stack-operator -go 1.21 +go 1.22 require ( github.com/go-logr/logr v1.4.2 diff --git a/internal/controller/clusteraddon_controller.go b/internal/controller/clusteraddon_controller.go index 23aaf7d41..aab0fd366 100644 --- a/internal/controller/clusteraddon_controller.go +++ b/internal/controller/clusteraddon_controller.go @@ -188,7 +188,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re releaseAsset, download, err := release.New(release.ConvertFromClusterClassToClusterStackFormat(cluster.Spec.Topology.Class), r.ReleaseDirectory) if err != nil { - conditions.MarkFalse(clusterAddon, csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.IssueWithReleaseAssetsReason, clusterv1.ConditionSeverityError, err.Error()) + conditions.MarkFalse(clusterAddon, csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.IssueWithReleaseAssetsReason, clusterv1.ConditionSeverityError, "%s", err.Error()) return ctrl.Result{RequeueAfter: 10 * time.Second}, nil } if download { @@ -204,9 +204,9 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.IssueWithReleaseAssetsReason, clusterv1.ConditionSeverityError, - msg, + "%s", msg, ) - record.Warnf(clusterAddon, "ValidateHelmChartFailed", msg) + record.Warn(clusterAddon, "ValidateHelmChartFailed", msg) return reconcile.Result{}, nil } @@ -947,9 +947,9 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont csov1alpha1.AssetsClientAPIAvailableCondition, csov1alpha1.FailedCreateAssetsClientReason, clusterv1.ConditionSeverityError, - err.Error(), + "%s", err.Error(), ) - record.Warnf(clusterAddon, "FailedCreateAssetsClient", err.Error()) + record.Warn(clusterAddon, "FailedCreateAssetsClient", err.Error()) // give the assets client a second change if isSet { @@ -963,7 +963,10 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont // check if old cluster stack release is present or not. releaseAsset, download, err := release.New(release.ConvertFromClusterClassToClusterStackFormat(clusterAddon.Spec.ClusterStack), r.ReleaseDirectory) if err != nil { - conditions.MarkFalse(clusterAddon, csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.IssueWithReleaseAssetsReason, clusterv1.ConditionSeverityError, err.Error()) + conditions.MarkFalse(clusterAddon, + csov1alpha1.ClusterStackReleaseAssetsReadyCondition, + csov1alpha1.IssueWithReleaseAssetsReason, + clusterv1.ConditionSeverityError, "%s", err.Error()) return nil, true, nil } if download { @@ -991,9 +994,9 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.IssueWithReleaseAssetsReason, clusterv1.ConditionSeverityError, - msg, + "%s", msg, ) - record.Warnf(clusterAddon, "ValidateHelmChartFailed", msg) + record.Warn(clusterAddon, "ValidateHelmChartFailed", msg) return nil, false, nil } diff --git a/internal/controller/clusterstack_controller.go b/internal/controller/clusterstack_controller.go index 605b9e4c4..cb8475cc5 100644 --- a/internal/controller/clusterstack_controller.go +++ b/internal/controller/clusterstack_controller.go @@ -120,9 +120,9 @@ func (r *ClusterStackReconciler) Reconcile(ctx context.Context, req reconcile.Re csov1alpha1.AssetsClientAPIAvailableCondition, csov1alpha1.FailedCreateAssetsClientReason, clusterv1.ConditionSeverityError, - err.Error(), + "%s", err.Error(), ) - record.Warnf(clusterStack, "FailedCreateAssetsClient", err.Error()) + record.Warn(clusterStack, "FailedCreateAssetsClient", err.Error()) // give the assets client a second change if isSet { @@ -140,7 +140,7 @@ func (r *ClusterStackReconciler) Reconcile(ctx context.Context, req reconcile.Re csov1alpha1.ReleasesSyncedCondition, csov1alpha1.FailedToSyncReason, clusterv1.ConditionSeverityWarning, - err.Error(), + "%s", err.Error(), ) logger.Error(err, "failed to get latest release from remote repository") } @@ -165,7 +165,7 @@ func (r *ClusterStackReconciler) Reconcile(ctx context.Context, req reconcile.Re if err := r.Delete(ctx, toDelete[i]); err != nil && !apierrors.IsNotFound(err) { // ignore not found errors when deleting reterr := fmt.Errorf("failed to delete cluster stack release %s: %w", csr.Name, err) - record.Eventf(clusterStack, "FailedToDeleteClusterStackRelease", reterr.Error()) + record.Event(clusterStack, "FailedToDeleteClusterStackRelease", reterr.Error()) return reconcile.Result{}, reterr } } @@ -198,7 +198,7 @@ func (r *ClusterStackReconciler) Reconcile(ctx context.Context, req reconcile.Re csov1alpha1.ProviderClusterStackReleasesSyncedCondition, csov1alpha1.FailedToCreateOrUpdateReason, clusterv1.ConditionSeverityWarning, - err.Error(), + "%s", err.Error(), ) } return reconcile.Result{}, fmt.Errorf("failed to create or update provider specific ClusterStackRelease %s/%s: %w", req.Namespace, csr.Name, err) @@ -210,7 +210,7 @@ func (r *ClusterStackReconciler) Reconcile(ctx context.Context, req reconcile.Re csov1alpha1.ClusterStackReleasesSyncedCondition, csov1alpha1.FailedToCreateOrUpdateReason, clusterv1.ConditionSeverityWarning, - err.Error(), + "%s", err.Error(), ) return reconcile.Result{}, fmt.Errorf("failed to get or create ClusterStackRelease %s/%s: %w", req.Namespace, csr.Name, err) } diff --git a/internal/controller/clusterstackrelease_controller.go b/internal/controller/clusterstackrelease_controller.go index e3fd87280..82110107d 100644 --- a/internal/controller/clusterstackrelease_controller.go +++ b/internal/controller/clusterstackrelease_controller.go @@ -107,7 +107,10 @@ func (r *ClusterStackReleaseReconciler) Reconcile(ctx context.Context, req recon releaseAssets, download, err := release.New(releaseTag, r.ReleaseDirectory) if err != nil { - conditions.MarkFalse(clusterStackRelease, csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.IssueWithReleaseAssetsReason, clusterv1.ConditionSeverityError, err.Error()) + conditions.MarkFalse(clusterStackRelease, + csov1alpha1.ClusterStackReleaseAssetsReadyCondition, + csov1alpha1.IssueWithReleaseAssetsReason, + clusterv1.ConditionSeverityError, "%s", err.Error()) return reconcile.Result{RequeueAfter: 1 * time.Minute}, fmt.Errorf("failed to create release: %w", err) } @@ -127,9 +130,9 @@ func (r *ClusterStackReleaseReconciler) Reconcile(ctx context.Context, req recon csov1alpha1.AssetsClientAPIAvailableCondition, csov1alpha1.FailedCreateAssetsClientReason, clusterv1.ConditionSeverityError, - err.Error(), + "%s", err.Error(), ) - record.Warnf(clusterStackRelease, "FailedCreateAssetsClient", err.Error()) + record.Warn(clusterStackRelease, "FailedCreateAssetsClient", err.Error()) // give the assets client a second change if isSet { diff --git a/pkg/assetsclient/github/client.go b/pkg/assetsclient/github/client.go index 4eb4118d7..4a7e88c51 100644 --- a/pkg/assetsclient/github/client.go +++ b/pkg/assetsclient/github/client.go @@ -77,7 +77,7 @@ func (c *realGhClient) ListRelease(ctx context.Context) ([]string, error) { return nil, fmt.Errorf("failed to list releases: %w", err) } - if response != nil && response.StatusCode != 200 { + if response != nil && response.StatusCode != http.StatusOK { return nil, fmt.Errorf("got unexpected status from call to remote repository: %s", response.Status) }