diff --git a/.golangci.yml b/.golangci.yml index 2094c52f..d58ee7c7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,12 +7,12 @@ linters: - bodyclose - containedctx - contextcheck + - copyloopvar - durationcheck - errchkjson - errname - errorlint - exhaustive - - exportloopref - forcetypeassert - gci - gocritic diff --git a/pkg/clusterstack/config.go b/pkg/clusterstack/config.go index 4d991bb1..950c21dc 100644 --- a/pkg/clusterstack/config.go +++ b/pkg/clusterstack/config.go @@ -18,6 +18,7 @@ limitations under the License. package clusterstack import ( + "errors" "fmt" "os" "path/filepath" @@ -58,11 +59,11 @@ func GetCsctlConfig(path string) (*CsctlConfig, error) { } if cs.Config.Provider.Type == "" { - return nil, fmt.Errorf("provider type must not be empty") + return nil, errors.New("provider type must not be empty") } if len(cs.Config.Provider.Type) > 253 { - return nil, fmt.Errorf("provider name must not be greater than 253") + return nil, errors.New("provider name must not be greater than 253") } match, err := regexp.MatchString(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`, cs.Config.Provider.Type) @@ -74,7 +75,7 @@ func GetCsctlConfig(path string) (*CsctlConfig, error) { } if cs.Config.ClusterStackName == "" { - return nil, fmt.Errorf("cluster stack name must not be empty") + return nil, errors.New("cluster stack name must not be empty") } // Validate kubernetes version diff --git a/pkg/clusterstack/version.go b/pkg/clusterstack/version.go index b0aeee0b..c22237dc 100644 --- a/pkg/clusterstack/version.go +++ b/pkg/clusterstack/version.go @@ -17,6 +17,7 @@ limitations under the License. package clusterstack import ( + "errors" "fmt" "regexp" "strconv" @@ -30,7 +31,7 @@ func BumpVersion(version string) (string, error) { // Check if a numeric part was found if len(matches) < 2 { - return "", fmt.Errorf("invalid version format") + return "", errors.New("invalid version format") } // Extract and convert the numeric part to an integer diff --git a/pkg/cmd/create.go b/pkg/cmd/create.go index 58cf6555..5d80c888 100644 --- a/pkg/cmd/create.go +++ b/pkg/cmd/create.go @@ -19,6 +19,7 @@ package cmd import ( "context" "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -185,13 +186,13 @@ func GetCreateOptions(ctx context.Context, clusterStackPath string) (*CreateOpti } case customMode: if clusterStackVersion == "" { - return nil, fmt.Errorf("please specify a semver for custom version with --cluster-stack-version flag") + return nil, errors.New("please specify a semver for custom version with --cluster-stack-version flag") } if clusterAddonVersion == "" { - return nil, fmt.Errorf("please specify a semver for custom version with --cluster-addon-version flag") + return nil, errors.New("please specify a semver for custom version with --cluster-addon-version flag") } if nodeImageVersion == "" { - return nil, fmt.Errorf("please specify a semver for custom version with --node-image-version flag") + return nil, errors.New("please specify a semver for custom version with --node-image-version flag") } createOption.Metadata, err = clusterstack.HandleCustomMode(createOption.Config.Config.KubernetesVersion, clusterStackVersion, clusterAddonVersion, nodeImageVersion) @@ -222,7 +223,7 @@ func createAction(cmd *cobra.Command, args []string) error { defer cleanTmpDirectory() if len(args) != 1 { - return fmt.Errorf("please provide a valid command, create only accept one argument to path to the cluster stacks") + return errors.New("please provide a valid command, create only accept one argument to path to the cluster stacks") } clusterStackPath := args[0] @@ -253,7 +254,7 @@ func (c *CreateOptions) validateHash() error { if c.CurrentReleaseHash.ClusterAddonDir == c.LatestReleaseHash.ClusterAddonDir && c.CurrentReleaseHash.ClusterAddonValues == c.LatestReleaseHash.ClusterAddonValues && c.CurrentReleaseHash.NodeImageDir == c.LatestReleaseHash.NodeImageDir { - return fmt.Errorf("no change in the cluster stack") + return errors.New("no change in the cluster stack") } return nil @@ -351,7 +352,7 @@ func (c *CreateOptions) generateRelease(ctx context.Context) error { if publish { if remote != "oci" { - return fmt.Errorf("not pushing assets. --publish is only implemented for remote OCI") + return errors.New("not pushing assets. --publish is only implemented for remote OCI") } ociClient, err := oci.NewClient() @@ -410,7 +411,7 @@ func overwriteVersionInFile(chartYaml, newVersion string) error { v := m["version"] oldVersion, ok := v.(string) if !ok { - return fmt.Errorf("failed to read version in yaml") + return errors.New("failed to read version in yaml") } m["version"] = newVersion diff --git a/pkg/hash/hash.go b/pkg/hash/hash.go index 1b432695..5e080d77 100644 --- a/pkg/hash/hash.go +++ b/pkg/hash/hash.go @@ -21,6 +21,7 @@ import ( "crypto/sha256" "encoding/base64" "encoding/json" + "errors" "fmt" "io" "os" @@ -111,7 +112,7 @@ func (r ReleaseHash) ValidateWithLatestReleaseHash(latestReleaseHash ReleaseHash if r.ClusterAddonDir == latestReleaseHash.ClusterAddonDir && r.ClusterAddonValues == latestReleaseHash.ClusterAddonValues && r.NodeImageDir == latestReleaseHash.NodeImageDir { - return fmt.Errorf("no change in the cluster stack") + return errors.New("no change in the cluster stack") } return nil