From 0f27374bf7c4ad465749fecace6ff8fd799d9b59 Mon Sep 17 00:00:00 2001 From: Feny Mehta Date: Wed, 8 Jan 2025 15:51:21 +0530 Subject: [PATCH 1/2] KUBESAW-250: Updating GolangCiLint to v1.63.1 Signed-off-by: Feny Mehta --- .github/workflows/ci-golang-sbom.yml | 2 +- controllers/memberstatus/memberstatus_controller_test.go | 2 +- controllers/nstemplateset/space_roles.go | 5 ++--- pkg/webhook/mutatingwebhook/mutate.go | 2 +- .../validatingwebhook/validate_rolebinding_request.go | 2 +- .../validatingwebhook/validate_spacebindingrequest.go | 2 +- pkg/webhook/validatingwebhook/validate_ssp_request.go | 2 +- pkg/webhook/validatingwebhook/validate_vm_request.go | 2 +- 8 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-golang-sbom.yml b/.github/workflows/ci-golang-sbom.yml index 4a260017..c7656cf7 100644 --- a/.github/workflows/ci-golang-sbom.yml +++ b/.github/workflows/ci-golang-sbom.yml @@ -29,7 +29,7 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v6 with: - version: v1.56.2 + version: v1.63.1 skip-pkg-cache: true skip-build-cache: true args: --config=./.golangci.yml --verbose diff --git a/controllers/memberstatus/memberstatus_controller_test.go b/controllers/memberstatus/memberstatus_controller_test.go index 919f8138..f47f7c0d 100644 --- a/controllers/memberstatus/memberstatus_controller_test.go +++ b/controllers/memberstatus/memberstatus_controller_test.go @@ -74,7 +74,7 @@ func TestNoMemberStatusFound(t *testing.T) { getHostClusterFunc := newGetHostClusterReady reconciler, req, fakeClient := prepareReconcile(t, requestName, getHostClusterFunc, allNamespacesCl, mockLastGitHubAPICall, defaultGitHubClient) fakeClient.MockGet = func(ctx context.Context, key types.NamespacedName, obj client.Object, opts ...client.GetOption) error { - return fmt.Errorf(expectedErrMsg) + return fmt.Errorf("%s", expectedErrMsg) } // when diff --git a/controllers/nstemplateset/space_roles.go b/controllers/nstemplateset/space_roles.go index 60768494..84e995be 100644 --- a/controllers/nstemplateset/space_roles.go +++ b/controllers/nstemplateset/space_roles.go @@ -3,7 +3,6 @@ package nstemplateset import ( "context" "encoding/json" - "fmt" "reflect" toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" @@ -79,7 +78,7 @@ func (r *spaceRolesManager) ensure(ctx context.Context, nsTmplSet *toolchainv1al sr, err := json.Marshal(nsTmplSet.Spec.SpaceRoles) if err != nil { return false, r.wrapErrorWithStatusUpdate(lctx, nsTmplSet, r.setStatusProvisionFailed, err, - fmt.Sprintf("failed to marshal space roles to update '%s' annotation on namespace", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey)) + "failed to marshal space roles to update '%v' annotation on namespace", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey) } if ns.Annotations == nil { ns.Annotations = map[string]string{} @@ -87,7 +86,7 @@ func (r *spaceRolesManager) ensure(ctx context.Context, nsTmplSet *toolchainv1al ns.Annotations[toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey] = string(sr) if err := r.Client.Update(ctx, &ns); err != nil { return false, r.wrapErrorWithStatusUpdate(lctx, nsTmplSet, r.setStatusProvisionFailed, err, - fmt.Sprintf("failed to update namespace with '%s' annotation", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey)) + "failed to update namespace with '%q' annotation", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey) } logger.Info("updated annotation on namespace", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey, string(sr)) return true, nil diff --git a/pkg/webhook/mutatingwebhook/mutate.go b/pkg/webhook/mutatingwebhook/mutate.go index efdd620d..12a2b2a4 100644 --- a/pkg/webhook/mutatingwebhook/mutate.go +++ b/pkg/webhook/mutatingwebhook/mutate.go @@ -63,7 +63,7 @@ func handleMutate(logger logr.Logger, w http.ResponseWriter, r *http.Request, mu func writeResponse(logger logr.Logger, responseCode int, w http.ResponseWriter, respBody []byte) { w.WriteHeader(responseCode) - if _, err := io.WriteString(w, string(respBody)); err != nil { + if _, err := io.Writer.Write(w, respBody); err != nil { //using 'io.Writer.Write' as per the static check SA6006: use io.Writer.Write instead of converting from []byte to string to use io.WriteString (staticcheck) logger.Error(err, "unable to write adm review response") } } diff --git a/pkg/webhook/validatingwebhook/validate_rolebinding_request.go b/pkg/webhook/validatingwebhook/validate_rolebinding_request.go index 5148de63..89c51285 100644 --- a/pkg/webhook/validatingwebhook/validate_rolebinding_request.go +++ b/pkg/webhook/validatingwebhook/validate_rolebinding_request.go @@ -40,7 +40,7 @@ func (v RoleBindingRequestValidator) HandleValidate(w http.ResponseWriter, r *ht respBody = v.validate(r.Context(), body) w.WriteHeader(http.StatusOK) } - if _, err := io.WriteString(w, string(respBody)); err != nil { + if _, err := io.Writer.Write(w, respBody); err != nil { //using 'io.Writer.Write' as per the static check SA6006: use io.Writer.Write instead of converting from []byte to string to use io.WriteString (staticcheck) log.Error(err, "unable to write response") } } diff --git a/pkg/webhook/validatingwebhook/validate_spacebindingrequest.go b/pkg/webhook/validatingwebhook/validate_spacebindingrequest.go index fc72f9eb..296eb7a4 100644 --- a/pkg/webhook/validatingwebhook/validate_spacebindingrequest.go +++ b/pkg/webhook/validatingwebhook/validate_spacebindingrequest.go @@ -42,7 +42,7 @@ func (v SpaceBindingRequestValidator) HandleValidate(w http.ResponseWriter, r *h respBody = v.validate(r.Context(), body) w.WriteHeader(http.StatusOK) } - if _, err := io.WriteString(w, string(respBody)); err != nil { + if _, err := io.Writer.Write(w, respBody); err != nil { //using 'io.Writer.Write' as per the static check SA6006: use io.Writer.Write instead of converting from []byte to string to use io.WriteString (staticcheck) log.Error(err, "unable to write response") } } diff --git a/pkg/webhook/validatingwebhook/validate_ssp_request.go b/pkg/webhook/validatingwebhook/validate_ssp_request.go index 22c841c9..7a6826e6 100644 --- a/pkg/webhook/validatingwebhook/validate_ssp_request.go +++ b/pkg/webhook/validatingwebhook/validate_ssp_request.go @@ -37,7 +37,7 @@ func (v SSPRequestValidator) HandleValidate(w http.ResponseWriter, r *http.Reque respBody = v.validate(r.Context(), body) w.WriteHeader(http.StatusOK) } - if _, err := io.WriteString(w, string(respBody)); err != nil { + if _, err := io.Writer.Write(w, respBody); err != nil { //using 'io.Writer.Write' as per the static check SA6006: use io.Writer.Write instead of converting from []byte to string to use io.WriteString (staticcheck) log.Error(err, "unable to write response") } } diff --git a/pkg/webhook/validatingwebhook/validate_vm_request.go b/pkg/webhook/validatingwebhook/validate_vm_request.go index b68753cd..cd30d30f 100644 --- a/pkg/webhook/validatingwebhook/validate_vm_request.go +++ b/pkg/webhook/validatingwebhook/validate_vm_request.go @@ -32,7 +32,7 @@ func (v VMRequestValidator) HandleValidate(w http.ResponseWriter, r *http.Reques respBody = v.validate(body) w.WriteHeader(http.StatusOK) } - if _, err := io.WriteString(w, string(respBody)); err != nil { + if _, err := io.Writer.Write(w, respBody); err != nil { //using 'io.Writer.Write' as per the static check SA6006: use io.Writer.Write instead of converting from []byte to string to use io.WriteString (staticcheck) log.Error(err, "unable to write response") } } From 3b7b998a23294a8d913c967e1b0a8ac562d71819 Mon Sep 17 00:00:00 2001 From: Feny Mehta Date: Wed, 8 Jan 2025 15:56:27 +0530 Subject: [PATCH 2/2] %s update Signed-off-by: Feny Mehta --- controllers/nstemplateset/space_roles.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/nstemplateset/space_roles.go b/controllers/nstemplateset/space_roles.go index 84e995be..3d1f70b8 100644 --- a/controllers/nstemplateset/space_roles.go +++ b/controllers/nstemplateset/space_roles.go @@ -78,7 +78,7 @@ func (r *spaceRolesManager) ensure(ctx context.Context, nsTmplSet *toolchainv1al sr, err := json.Marshal(nsTmplSet.Spec.SpaceRoles) if err != nil { return false, r.wrapErrorWithStatusUpdate(lctx, nsTmplSet, r.setStatusProvisionFailed, err, - "failed to marshal space roles to update '%v' annotation on namespace", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey) + "failed to marshal space roles to update '%s' annotation on namespace", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey) } if ns.Annotations == nil { ns.Annotations = map[string]string{} @@ -86,7 +86,7 @@ func (r *spaceRolesManager) ensure(ctx context.Context, nsTmplSet *toolchainv1al ns.Annotations[toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey] = string(sr) if err := r.Client.Update(ctx, &ns); err != nil { return false, r.wrapErrorWithStatusUpdate(lctx, nsTmplSet, r.setStatusProvisionFailed, err, - "failed to update namespace with '%q' annotation", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey) + "failed to update namespace with '%s' annotation", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey) } logger.Info("updated annotation on namespace", toolchainv1alpha1.LastAppliedSpaceRolesAnnotationKey, string(sr)) return true, nil