diff --git a/.golangci.yml b/.golangci.yml index 3fec058244..ced50f1dc5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,77 +1,85 @@ -# This file contains all available configuration options -# with their default values. - -# options for analysis running +version: "2" run: - # default concurrency is a available CPU number concurrency: 4 - - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 10m - - # exit code when at least one issue was found, default is 1 issues-exit-code: 1 - - # include test files or not, default is true tests: true - -# output configuration options -output: - # print lines of code with issue, default is true - print-issued-lines: true - - # print linter name in the end of issue text, default is true - print-linter-name: true - -issues: - # which dirs to skip: issues from them won't be reported; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but default dirs are skipped independently - # from this option's value (see skip-dirs-use-default). - exclude-dirs: - - build - - client - - docs - - models - - restapi - - # List of regexps of issue texts to exclude, empty list by default. - # But independently from this option we use default exclude patterns, - # it can be disabled by `exclude-use-default: false`. To list all - # excluded by default patterns execute `golangci-lint run --help` - exclude: - - G107 - - G115 # Integer overflow conversion - - G402 # support scality DisableSSL - - G401 # Use of weak cryptographic primitive - - G501 # Blacklisted import `crypto/md5`: weak cryptographic primitive - - '"ok" shadows declaration' - - # make issues output unique by line, default is true - uniq-by-line: true - linters: enable: - - gosimple - - staticcheck - - unused - - govet + - copyloopvar - gocyclo - - gofmt - gosec - unconvert + settings: + govet: + enable: + - shadow + settings: + printf: + funcs: + - Infof + - Warnf + - Errorf + - Fatalf + staticcheck: + checks: + - "all" + - "-ST1001" + - "-ST1003" + - "-ST1005" + - "-ST1008" + - "-ST1011" + - "-ST1016" + - "-ST1017" + - "-ST1019" + - "-ST1023" + - "-QF1001" + - "-QF1002" + - "-QF1003" + - "-QF1005" + - "-QF1006" + - "-QF1007" + - "-QF1008" + - "-QF1011" + - "-QF1012" + gosec: + excludes: + - G107 + - G108 + - G115 + - G402 + - G602 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: [] + paths: + - build + - client + - docs + - models + - restapi + - third_party$ + - builtin$ + - examples$ +issues: + uniq-by-line: true +formatters: + enable: + - gci + - gofmt - goimports - - copyloopvar - -linters-settings: - govet: - enable: - - shadow - - settings: - printf: - funcs: - - Infof - - Warnf - - Errorf - - Fatalf + exclusions: + generated: lax + paths: + - build + - client + - docs + - models + - restapi + - third_party$ + - builtin$ + - examples$ \ No newline at end of file diff --git a/Dockerfile.assisted-installer-build b/Dockerfile.assisted-installer-build index f93840dca6..99fa97c9ea 100644 --- a/Dockerfile.assisted-installer-build +++ b/Dockerfile.assisted-installer-build @@ -2,11 +2,11 @@ FROM registry.access.redhat.com/ubi9/go-toolset:1.25 AS golang ENV GOFLAGS="" -RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.8 && \ - go install golang.org/x/tools/cmd/goimports@v0.1.0 && \ +RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.8.0 && \ + go install golang.org/x/tools/cmd/goimports@v0.34.0 && \ go install github.com/onsi/ginkgo/ginkgo@v1.16.1 && \ go install go.uber.org/mock/mockgen@v0.4.0 && \ - go install gotest.tools/gotestsum@v1.6.3 && \ + go install gotest.tools/gotestsum@v1.12.3 && \ go install github.com/axw/gocov/gocov@v1.1.0 && \ go install github.com/AlekSi/gocov-xml@v1.1.0 diff --git a/go.mod b/go.mod index eda48891d2..6277d80f05 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/openshift/assisted-installer -go 1.21 +go 1.25.0 + +toolchain go1.25.5 require ( github.com/PuerkitoBio/rehttp v1.4.0 diff --git a/src/assisted_installer_controller/assisted_installer_controller.go b/src/assisted_installer_controller/assisted_installer_controller.go index 839276b3f6..66d7157feb 100644 --- a/src/assisted_installer_controller/assisted_installer_controller.go +++ b/src/assisted_installer_controller/assisted_installer_controller.go @@ -18,18 +18,9 @@ import ( "sync/atomic" "time" - "github.com/thoas/go-funk" - "github.com/hashicorp/go-version" metal3v1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" configv1 "github.com/openshift/api/config/v1" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - certificatesv1 "k8s.io/api/certificates/v1" - v1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - mapiv1beta1 "github.com/openshift/api/machine/v1beta1" "github.com/openshift/assisted-installer/src/common" "github.com/openshift/assisted-installer/src/config" @@ -38,6 +29,13 @@ import ( "github.com/openshift/assisted-installer/src/ops" "github.com/openshift/assisted-installer/src/utils" "github.com/openshift/assisted-service/models" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "github.com/thoas/go-funk" + certificatesv1 "k8s.io/api/certificates/v1" + v1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -1345,7 +1343,7 @@ func (c *controller) uploadSummaryLogs(podName string, namespace string, sinceSe if !ok { msg := "Some Logs were not collected in summary" - c.log.Errorf(msg) + c.log.Error(msg) return errors.New(msg) } diff --git a/src/assisted_installer_controller/assisted_installer_controller_test.go b/src/assisted_installer_controller/assisted_installer_controller_test.go index 18e5ed08a9..88c8145857 100644 --- a/src/assisted_installer_controller/assisted_installer_controller_test.go +++ b/src/assisted_installer_controller/assisted_installer_controller_test.go @@ -14,31 +14,28 @@ import ( "testing" "time" - batchV1 "k8s.io/api/batch/v1" - v1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - apischema "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - + "github.com/go-openapi/strfmt" "github.com/google/uuid" metal3v1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" - machinev1beta1 "github.com/openshift/api/machine/v1beta1" - "github.com/openshift/assisted-installer/src/common" - olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" - certificatesv1 "k8s.io/api/certificates/v1" - - "github.com/go-openapi/strfmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/sirupsen/logrus" - gomock "go.uber.org/mock/gomock" - configv1 "github.com/openshift/api/config/v1" + machinev1beta1 "github.com/openshift/api/machine/v1beta1" + "github.com/openshift/assisted-installer/src/common" "github.com/openshift/assisted-installer/src/inventory_client" "github.com/openshift/assisted-installer/src/k8s_client" "github.com/openshift/assisted-installer/src/ops" "github.com/openshift/assisted-service/models" + olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" + "github.com/sirupsen/logrus" + gomock "go.uber.org/mock/gomock" + batchV1 "k8s.io/api/batch/v1" + certificatesv1 "k8s.io/api/certificates/v1" + v1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apischema "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" ) func TestValidator(t *testing.T) { diff --git a/src/assisted_installer_controller/operator_handler.go b/src/assisted_installer_controller/operator_handler.go index 5305c501ec..be1de56d79 100644 --- a/src/assisted_installer_controller/operator_handler.go +++ b/src/assisted_installer_controller/operator_handler.go @@ -3,16 +3,15 @@ package assisted_installer_controller import ( "context" + "github.com/openshift/assisted-installer/src/k8s_client" + "github.com/openshift/assisted-installer/src/utils" + "github.com/openshift/assisted-service/models" olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" "github.com/sirupsen/logrus" batchV1 "k8s.io/api/batch/v1" v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" - - "github.com/openshift/assisted-installer/src/k8s_client" - "github.com/openshift/assisted-installer/src/utils" - "github.com/openshift/assisted-service/models" ) const ( diff --git a/src/common/common.go b/src/common/common.go index c202ee1e22..597e960b61 100644 --- a/src/common/common.go +++ b/src/common/common.go @@ -15,7 +15,6 @@ import ( "github.com/openshift/assisted-installer/src/k8s_client" "github.com/openshift/assisted-installer/src/utils" "github.com/openshift/assisted-service/models" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/thoas/go-funk" diff --git a/src/config/config.go b/src/config/config.go index 6c40d73b37..a5307f5d36 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -3,9 +3,8 @@ package config import ( "encoding/json" "flag" - "os" - "fmt" + "os" "github.com/kelseyhightower/envconfig" "github.com/openshift/assisted-installer/src/utils" diff --git a/src/coreos_logger/coreos_installer_log_writer.go b/src/coreos_logger/coreos_installer_log_writer.go index 8160959287..134b51517e 100644 --- a/src/coreos_logger/coreos_installer_log_writer.go +++ b/src/coreos_logger/coreos_installer_log_writer.go @@ -6,9 +6,8 @@ import ( "strconv" "strings" - "github.com/openshift/assisted-installer/src/utils" - "github.com/openshift/assisted-installer/src/inventory_client" + "github.com/openshift/assisted-installer/src/utils" "github.com/openshift/assisted-service/models" "github.com/sirupsen/logrus" ) diff --git a/src/coreos_logger/coreos_installer_log_writer_test.go b/src/coreos_logger/coreos_installer_log_writer_test.go index 766384fd28..6f32719d12 100644 --- a/src/coreos_logger/coreos_installer_log_writer_test.go +++ b/src/coreos_logger/coreos_installer_log_writer_test.go @@ -3,15 +3,13 @@ package coreos_logger import ( "io" - "github.com/openshift/assisted-installer/src/inventory_client" - "github.com/openshift/assisted-service/models" - gomock "go.uber.org/mock/gomock" - - "github.com/sirupsen/logrus/hooks/test" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/openshift/assisted-installer/src/inventory_client" + "github.com/openshift/assisted-service/models" "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus/hooks/test" + gomock "go.uber.org/mock/gomock" ) var _ = Describe("Verify CoreosInstallerLogger", func() { diff --git a/src/installer/installer.go b/src/installer/installer.go index 7160687f3d..6d75217519 100644 --- a/src/installer/installer.go +++ b/src/installer/installer.go @@ -9,31 +9,28 @@ import ( "strings" "time" - mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" - - "golang.org/x/sync/errgroup" - v1 "k8s.io/api/core/v1" - "github.com/go-openapi/swag" "github.com/google/uuid" - "github.com/openshift/assisted-installer/src/main/drymock" - "github.com/openshift/assisted-service/pkg/secretdump" - "github.com/openshift/assisted-service/pkg/validations" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "github.com/thoas/go-funk" - "github.com/openshift/assisted-installer/src/common" "github.com/openshift/assisted-installer/src/config" "github.com/openshift/assisted-installer/src/coreos_logger" "github.com/openshift/assisted-installer/src/ignition" "github.com/openshift/assisted-installer/src/inventory_client" "github.com/openshift/assisted-installer/src/k8s_client" + "github.com/openshift/assisted-installer/src/main/drymock" "github.com/openshift/assisted-installer/src/ops" "github.com/openshift/assisted-installer/src/ops/execute" "github.com/openshift/assisted-installer/src/utils" "github.com/openshift/assisted-service/models" + "github.com/openshift/assisted-service/pkg/secretdump" + "github.com/openshift/assisted-service/pkg/validations" + mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + "github.com/pkg/errors" preinstallUtils "github.com/rh-ecosystem-edge/preinstall-utils/pkg" + "github.com/sirupsen/logrus" + "github.com/thoas/go-funk" + "golang.org/x/sync/errgroup" + v1 "k8s.io/api/core/v1" ) // In dry run mode we prefer to get quick feedback about errors rather diff --git a/src/installer/installer_test.go b/src/installer/installer_test.go index a87e402db2..6575260396 100644 --- a/src/installer/installer_test.go +++ b/src/installer/installer_test.go @@ -11,11 +11,6 @@ import ( "testing" "time" - preinstallUtils "github.com/rh-ecosystem-edge/preinstall-utils/pkg" - - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/go-openapi/strfmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -29,8 +24,11 @@ import ( "github.com/openshift/assisted-service/pkg/validations" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" "github.com/pkg/errors" + preinstallUtils "github.com/rh-ecosystem-edge/preinstall-utils/pkg" "github.com/sirupsen/logrus" gomock "go.uber.org/mock/gomock" + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestValidator(t *testing.T) { diff --git a/src/main/assisted-installer-controller/assisted_installer_main.go b/src/main/assisted-installer-controller/assisted_installer_main.go index 0eb8fa9dd2..4e7ffe8ba7 100644 --- a/src/main/assisted-installer-controller/assisted_installer_main.go +++ b/src/main/assisted-installer-controller/assisted_installer_main.go @@ -8,17 +8,15 @@ import ( "sync" "time" - "github.com/openshift/assisted-installer/src/common" - - "github.com/openshift/assisted-installer/src/ops/execute" - "github.com/kelseyhightower/envconfig" assistedinstallercontroller "github.com/openshift/assisted-installer/src/assisted_installer_controller" + "github.com/openshift/assisted-installer/src/common" "github.com/openshift/assisted-installer/src/config" "github.com/openshift/assisted-installer/src/inventory_client" "github.com/openshift/assisted-installer/src/k8s_client" "github.com/openshift/assisted-installer/src/main/drymock" "github.com/openshift/assisted-installer/src/ops" + "github.com/openshift/assisted-installer/src/ops/execute" "github.com/openshift/assisted-installer/src/utils" "github.com/openshift/assisted-service/client/installer" "github.com/openshift/assisted-service/models" diff --git a/src/main/assisted-installer-controller/assisted_installer_main_test.go b/src/main/assisted-installer-controller/assisted_installer_main_test.go index 450820f508..36052b6c83 100644 --- a/src/main/assisted-installer-controller/assisted_installer_main_test.go +++ b/src/main/assisted-installer-controller/assisted_installer_main_test.go @@ -8,19 +8,18 @@ import ( "testing" "time" - "github.com/openshift/assisted-installer/src/k8s_client" - v1 "k8s.io/api/core/v1" - "github.com/go-openapi/swag" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" configv1 "github.com/openshift/api/config/v1" assistedinstallercontroller "github.com/openshift/assisted-installer/src/assisted_installer_controller" "github.com/openshift/assisted-installer/src/inventory_client" + "github.com/openshift/assisted-installer/src/k8s_client" "github.com/openshift/assisted-service/client/installer" "github.com/openshift/assisted-service/models" "github.com/sirupsen/logrus" gomock "go.uber.org/mock/gomock" + v1 "k8s.io/api/core/v1" ) func TestValidator(t *testing.T) { diff --git a/src/ops/ops.go b/src/ops/ops.go index 0d8c74c588..5ce2a05872 100644 --- a/src/ops/ops.go +++ b/src/ops/ops.go @@ -24,18 +24,15 @@ import ( config_latest "github.com/coreos/ignition/v2/config/v3_2" "github.com/go-openapi/swag" - mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" - "github.com/thoas/go-funk" - "github.com/vincent-petithory/dataurl" - - "github.com/openshift/assisted-service/models" - - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "github.com/openshift/assisted-installer/src/config" "github.com/openshift/assisted-installer/src/ops/execute" "github.com/openshift/assisted-installer/src/utils" + "github.com/openshift/assisted-service/models" + mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "github.com/thoas/go-funk" + "github.com/vincent-petithory/dataurl" ) const ( @@ -596,7 +593,7 @@ func (o *ops) GetMustGatherLogs(workDir, kubeconfigPath string, images ...string if len(files) == 0 { lerr := fmt.Errorf("Failed to find must-gather output") - o.log.Errorf(lerr.Error()) + o.log.Error(lerr.Error()) return "", lerr } logsDir := filepath.Base(files[0]) diff --git a/src/ops/ops_test.go b/src/ops/ops_test.go index 5f5421c322..9095553948 100644 --- a/src/ops/ops_test.go +++ b/src/ops/ops_test.go @@ -14,14 +14,13 @@ import ( "os" "reflect" - "github.com/openshift/assisted-installer/src/ops/execute" - "github.com/coreos/ignition/v2/config/v3_2/types" "github.com/go-openapi/swag" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/ghttp" "github.com/openshift/assisted-installer/src/config" + "github.com/openshift/assisted-installer/src/ops/execute" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" "github.com/sirupsen/logrus" "github.com/thoas/go-funk" diff --git a/src/utils/utils.go b/src/utils/utils.go index c67a3d15b0..17f05b860b 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -12,19 +12,16 @@ import ( "sync" "time" - "github.com/openshift/assisted-service/pkg/requestid" - - "github.com/openshift/assisted-installer-agent/pkg/journalLogger" - "github.com/pkg/errors" - "golang.org/x/net/http/httpproxy" - ignition "github.com/coreos/ignition/v2/config" - "github.com/openshift/assisted-service/models" - configv1 "github.com/openshift/api/config/v1" + "github.com/openshift/assisted-installer-agent/pkg/journalLogger" + "github.com/openshift/assisted-service/models" + "github.com/openshift/assisted-service/pkg/requestid" operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/vincent-petithory/dataurl" + "golang.org/x/net/http/httpproxy" ) var ( diff --git a/src/utils/utils_test.go b/src/utils/utils_test.go index 0966b7ee5d..7ae4d8088b 100644 --- a/src/utils/utils_test.go +++ b/src/utils/utils_test.go @@ -10,7 +10,6 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pkg/errors" "github.com/sirupsen/logrus" )