diff --git a/.github/workflows/ocs-operator-ci.yaml b/.github/workflows/ocs-operator-ci.yaml index f70d7051f2..2808b11838 100644 --- a/.github/workflows/ocs-operator-ci.yaml +++ b/.github/workflows/ocs-operator-ci.yaml @@ -37,7 +37,7 @@ jobs: - uses: golangci/golangci-lint-action@v6 with: - version: v1.54.2 + version: v1.63.4 args: "--out-format=colored-line-number --timeout=6m ./..." go-test: diff --git a/.golangci.yaml b/.golangci.yaml index 8b2710eabf..3ea44b2872 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -6,14 +6,8 @@ run: # timeout for analysis, e.g. 30s, 5m, default is 1m timeout: 2m -linters: - disable-all: true - enable: - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - unused - - gofmt - - revive +issues: + exclude: + #https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/handler#TypedMapFunc + - "parameter 'context' seems to be unused" + - "parameter 'obj' seems to be unused" diff --git a/controllers/mirroring/mirroring_controller.go b/controllers/mirroring/mirroring_controller.go index 6f5374aa8b..18dba93665 100644 --- a/controllers/mirroring/mirroring_controller.go +++ b/controllers/mirroring/mirroring_controller.go @@ -15,12 +15,14 @@ package mirroring import ( "context" + "errors" "fmt" - "golang.org/x/exp/maps" - "k8s.io/utils/ptr" "slices" "time" + "golang.org/x/exp/maps" + "k8s.io/utils/ptr" + ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1" providerClient "github.com/red-hat-storage/ocs-operator/services/provider/api/v4/client" @@ -337,7 +339,7 @@ func (r *MirroringReconciler) reconcileBlockPoolMirroring( for i := range response.Errors { resp := response.Errors[i] r.log.Error( - fmt.Errorf(resp.Message), + errors.New(resp.Message), "failed to get BlockPoolsInfo", "CephBlockPool", resp.BlockPoolName, @@ -494,7 +496,7 @@ func (r *MirroringReconciler) reconcileRadosNamespaceMirroring( for i := range response.Errors { resp := response.Errors[i] r.log.Error( - fmt.Errorf(resp.Message), + errors.New(resp.Message), "failed to get StorageClientsInfo", "CephBlockPool", resp.ClientID, diff --git a/controllers/ocsinitialization/ocsinitialization_controller.go b/controllers/ocsinitialization/ocsinitialization_controller.go index cc2b9f8b33..c8c3ad8953 100644 --- a/controllers/ocsinitialization/ocsinitialization_controller.go +++ b/controllers/ocsinitialization/ocsinitialization_controller.go @@ -608,9 +608,8 @@ func getFailureDomainKeyFromStorageClassParameter(sc *storagev1.StorageClass) st return "topology.rook.io/rack" } else if failuredomain == "hostname" || failuredomain == "host" { return "kubernetes.io/hostname" - } else { - return "" } + return "" } func (r *OCSInitializationReconciler) reconcileUXBackendSecret(initialData *ocsv1.OCSInitialization) error { diff --git a/controllers/storagecluster/reconcile.go b/controllers/storagecluster/reconcile.go index 06d04a6b40..e7f5b88025 100644 --- a/controllers/storagecluster/reconcile.go +++ b/controllers/storagecluster/reconcile.go @@ -4,10 +4,11 @@ import ( "context" error1 "errors" "fmt" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "strings" "time" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1" "github.com/red-hat-storage/ocs-operator/v4/controllers/util" @@ -212,9 +213,8 @@ func (r *StorageClusterReconciler) Reconcile(ctx context.Context, request reconc return result, reconcileError } else if statusError != nil { return result, statusError - } else { - return result, nil } + return result, nil } func (r *StorageClusterReconciler) initializeImagesStatus(sc *ocsv1.StorageCluster) { @@ -699,9 +699,8 @@ func (r *StorageClusterReconciler) SetOperatorConditions(message string, reason return error1.New(prevError.Error() + operatorConditionErr.Error()) } else if prevError != nil { return prevError - } else { - return operatorConditionErr } + return operatorConditionErr } // validateStorageDeviceSets checks the StorageDeviceSets of the given diff --git a/hack/common.sh b/hack/common.sh index 3c08387473..fdee81cfe5 100644 --- a/hack/common.sh +++ b/hack/common.sh @@ -25,7 +25,7 @@ OPERATOR_SDK="${LOCALBIN}/operator-sdk-${OPERATOR_SDK_VERSION}" OPM_VERSION="v1.28.0" OPM="${LOCALBIN}/opm-${OPM_VERSION}" GINKGO="${LOCALBIN}/ginkgo" -GOLANGCI_LINT_VERSION="v1.54.2" +GOLANGCI_LINT_VERSION="v1.63.4" GOLANGCI_LINT="${LOCALBIN}/golangci-lint" SHELLCHECK_VERSION="v0.9.0" SHELLCHECK="${LOCALBIN}/shellcheck" diff --git a/services/provider/server/server.go b/services/provider/server/server.go index 5645eb872f..4408ee9def 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -508,7 +508,7 @@ func (s *OCSProviderServer) getExternalResources(ctx context.Context, consumerRe if err = s.client.Get(ctx, client.ObjectKeyFromObject(noobaMgmtRoute), noobaMgmtRoute); err != nil { return nil, fmt.Errorf("failed to get noobaa-mgmt route. %v", err) } - if noobaMgmtRoute.Status.Ingress == nil || len(noobaMgmtRoute.Status.Ingress) == 0 { + if len(noobaMgmtRoute.Status.Ingress) == 0 { return nil, fmt.Errorf("no Ingress available in noobaa-mgmt route") } @@ -660,7 +660,7 @@ func (s *OCSProviderServer) FulfillStorageClaim(ctx context.Context, req *pb.Ful // Get storage consumer resource using UUID consumerObj, err := s.consumerManager.Get(ctx, req.StorageConsumerUUID) if err != nil { - return nil, status.Errorf(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } klog.Infof("Found StorageConsumer %q (%q)", consumerObj.Name, req.StorageConsumerUUID) @@ -695,7 +695,7 @@ func (s *OCSProviderServer) RevokeStorageClaim(ctx context.Context, req *pb.Revo if err != nil { errMsg := fmt.Sprintf("failed to revoke storage class claim %q for %q. %v", req.StorageClaimName, req.StorageConsumerUUID, err) klog.Error(errMsg) - return nil, status.Errorf(codes.Internal, errMsg) + return nil, status.Error(codes.Internal, errMsg) } return &pb.RevokeStorageClaimResponse{}, nil diff --git a/services/ux-backend/main.go b/services/ux-backend/main.go index 555d39dc2c..43c64d5973 100644 --- a/services/ux-backend/main.go +++ b/services/ux-backend/main.go @@ -27,14 +27,17 @@ type serverConfig struct { } func readEnvVar[T any](envVarName string, defaultValue T, parser func(str string) (T, error)) (T, error) { - if str := os.Getenv(envVarName); str == "" { + str := os.Getenv(envVarName) + if str == "" { klog.Infof("no user-defined %s provided, defaulting to %v", envVarName, defaultValue) return defaultValue, nil - } else if value, err := parser(str); err != nil { + } + + value, err := parser(str) + if err != nil { return *new(T), fmt.Errorf("malformed user-defined %s value %s: %v", envVarName, str, err) - } else { - return value, nil } + return value, nil } func loadAndValidateServerConfig() (*serverConfig, error) {