Skip to content

Commit

Permalink
fix golanglint goerr113 (#558)
Browse files Browse the repository at this point in the history
Signed-off-by: Ziming Zhang <zziming@vmware.com>
  • Loading branch information
bitsf committed Apr 19, 2021
1 parent f907821 commit 297c04f
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ linters:
- gocritic
- gocyclo
- godot
# - goerr113
- goerr113
- gofmt
- gofumpt
- goheader
Expand Down Expand Up @@ -73,7 +73,7 @@ linters:
- paralleltest
- wrapcheck
# - errorlint
- goerr113
# - goerr113
# - gomnd
# - nestif
# - funlen
Expand Down
4 changes: 2 additions & 2 deletions apis/goharbor.io/v1alpha3/harbor_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package v1alpha3

import (
"context"
"fmt"
"net/url"

"github.com/goharbor/harbor-operator/pkg/version"
"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -54,7 +54,7 @@ func (h *Harbor) ValidateUpdate(old runtime.Object) error {

obj, ok := old.(*Harbor)
if !ok {
return fmt.Errorf("failed type assertion on kind: %s", old.GetObjectKind().GroupVersionKind().String())
return errors.Errorf("failed type assertion on kind: %s", old.GetObjectKind().GroupVersionKind().String())
}

return h.Validate(obj)
Expand Down
3 changes: 2 additions & 1 deletion apis/goharbor.io/v1alpha3/harborcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"github.com/goharbor/harbor-operator/pkg/version"
"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (hc *HarborCluster) ValidateUpdate(old runtime.Object) error {

obj, ok := old.(*HarborCluster)
if !ok {
return fmt.Errorf("failed type assertion on kind: %s", old.GetObjectKind().GroupVersionKind().String())
return errors.Errorf("failed type assertion on kind: %s", old.GetObjectKind().GroupVersionKind().String())
}

return hc.validate(obj)
Expand Down
7 changes: 4 additions & 3 deletions controllers/goharbor/configuration/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/goharbor/harbor-operator/pkg/harbor"
"github.com/goharbor/harbor-operator/pkg/utils/strings"
"github.com/ovh/configstore"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -180,7 +181,7 @@ func (r *Reconciler) assembleConfig(ctx context.Context, cm *corev1.ConfigMap) (
// itemValue is secret name.
secretName, ok := itemValue.(string)
if !ok {
return nil, fmt.Errorf("config field %s's value %v, type is invalid, should be string", itemKey, itemValue)
return nil, errors.Errorf("config field %s's value %v, type is invalid, should be string", itemKey, itemValue)
}
// get secret.
if err = r.Client.Get(ctx, types.NamespacedName{Namespace: cm.Namespace, Name: secretName}, secret); err != nil {
Expand All @@ -197,12 +198,12 @@ func (r *Reconciler) assembleConfig(ctx context.Context, cm *corev1.ConfigMap) (
// getHarborClient gets harbor client.
func (r *Reconciler) getHarborClient(ctx context.Context, cluster *goharborv1.HarborCluster) (harbor.Client, error) {
if cluster == nil {
return nil, fmt.Errorf("harbor cluster can not be nil")
return nil, errors.Errorf("harbor cluster can not be nil")
}

url := cluster.Spec.ExternalURL
if len(url) == 0 {
return nil, fmt.Errorf("harbor url is invalid")
return nil, errors.Errorf("harbor url is invalid")
}

var opts []harbor.ClientOption
Expand Down
9 changes: 4 additions & 5 deletions controllers/goharbor/harborcluster/service_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ package harborcluster

import (
"context"
"errors"
"fmt"

goharborv1 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha3"
"github.com/goharbor/harbor-operator/pkg/cluster/controllers/harbor"
"github.com/goharbor/harbor-operator/pkg/cluster/lcm"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -119,10 +118,10 @@ func (s *ServiceManager) Apply() error { // nolint:funlen
}
// Only for wsl check
case goharborv1.ComponentHarbor:
return fmt.Errorf("%s is not supported", s.component)
return errors.Errorf("%s is not supported", s.component)
default:
// Should not happen, just in case
return fmt.Errorf("unrecognized component: %s", s.component)
return errors.Errorf("unrecognized component: %s", s.component)
}

if s.ctx == nil {
Expand Down Expand Up @@ -152,7 +151,7 @@ func (s *ServiceManager) validate() error {
if s.component != goharborv1.ComponentCache &&
s.component != goharborv1.ComponentStorage &&
s.component != goharborv1.ComponentDatabase {
return fmt.Errorf("invalid service component: %s", s.component)
return errors.Errorf("invalid service component: %s", s.component)
}

if s.cluster == nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/goharbor/harborcluster/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ package harborcluster

import (
"context"
"errors"
"sync"
"time"

"github.com/go-logr/logr"
goharborv1 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha3"
"github.com/goharbor/harbor-operator/pkg/cluster/lcm"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
4 changes: 2 additions & 2 deletions pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package builder

import (
"context"
"fmt"
"log"
"sync"
"time"

"github.com/go-logr/logr"
"github.com/pkg/errors"
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -227,7 +227,7 @@ func isCRDReady(getter apiextv1.CustomResourceDefinitionsGetter, name string) bo
}
case v1.NamesAccepted:
if cond.Status == v1.ConditionFalse {
return false, fmt.Errorf("name conflict: %v", cond.Reason) // conflicted, poll will return immediately
return false, errors.Errorf("name conflict: %v", cond.Reason) // conflicted, poll will return immediately
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/cluster/controllers/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package cache

import (
"context"
"fmt"

"github.com/go-logr/logr"
goharborv1 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha3"
"github.com/goharbor/harbor-operator/pkg/cluster/k8s"
"github.com/goharbor/harbor-operator/pkg/cluster/lcm"
"github.com/ovh/configstore"
"github.com/pkg/errors"
redisOp "github.com/spotahome/redis-operator/api/redisfailover/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (rc *RedisController) Apply(ctx context.Context, cluster *goharborv1.Harbor
crdClient := rc.DClient.DynamicClient(ctx, k8s.WithResource(redisFailoversGVR), k8s.WithNamespace(cluster.Namespace))

actualCR, err := crdClient.Get(rc.ResourceManager.GetCacheCRName(), metav1.GetOptions{})
if errors.IsNotFound(err) {
if apierrors.IsNotFound(err) {
return rc.Deploy(ctx, cluster)
} else if err != nil {
return cacheNotReadyStatus(ErrorGetRedisClient, err.Error()), err
Expand All @@ -82,11 +82,11 @@ func (rc *RedisController) Apply(ctx context.Context, cluster *goharborv1.Harbor

// Delete...
func (rc *RedisController) Delete(_ context.Context, _ *goharborv1.HarborCluster) (*lcm.CRStatus, error) {
return nil, fmt.Errorf("not implemented")
return nil, errors.Errorf("not implemented")
}

func (rc *RedisController) Upgrade(_ context.Context, _ *goharborv1.HarborCluster) (*lcm.CRStatus, error) {
return nil, fmt.Errorf("not implemented")
return nil, errors.Errorf("not implemented")
}

func cacheNotReadyStatus(reason, message string) *lcm.CRStatus {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/controllers/database/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package database

import (
"context"
"errors"
"fmt"

goharborv1 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha3"
harbormetav1 "github.com/goharbor/harbor-operator/apis/meta/v1alpha1"
"github.com/goharbor/harbor-operator/pkg/cluster/controllers/database/api"
"github.com/goharbor/harbor-operator/pkg/cluster/lcm"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down
3 changes: 2 additions & 1 deletion pkg/cluster/controllers/database/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
goharborv1 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha3"
"github.com/goharbor/harbor-operator/pkg/cluster/controllers/database/api"
"github.com/goharbor/harbor-operator/pkg/config"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)
Expand Down Expand Up @@ -136,7 +137,7 @@ func (p *PostgreSQLController) GetPostgreVersion(harborcluster *goharborv1.Harbo
}
}

return "", fmt.Errorf("postgresql version not found for harbor %s", harborcluster.Spec.Version)
return "", errors.Errorf("postgresql version not found for harbor %s", harborcluster.Spec.Version)
}

func (p *PostgreSQLController) GetPostgreParameters() map[string]string {
Expand Down
5 changes: 3 additions & 2 deletions pkg/cluster/gos/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package gos

import (
"context"
"fmt"
"strings"
"sync"

"github.com/pkg/errors"
)

// Group for running goroutines.
Expand Down Expand Up @@ -77,7 +78,7 @@ func (g *Group) Wait() error {
}

if len(errTexts) > 0 {
return fmt.Errorf("gos.Group error: %s", strings.Join(errTexts, ":"))
return errors.Errorf("gos.Group error: %s", strings.Join(errTexts, ":"))
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/errors_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config_test

import (
"fmt"
"github.com/pkg/errors"

. "github.com/goharbor/harbor-operator/pkg/config"
. "github.com/onsi/ginkgo"
Expand All @@ -20,7 +20,7 @@ var _ = Describe("IsNotFound", func() {
var err error

BeforeEach(func() {
err = fmt.Errorf("a random error")
err = errors.Errorf("a random error")
})

It("Should return false", func() {
Expand All @@ -34,7 +34,7 @@ var _ = Describe("IsNotFound", func() {

BeforeEach(func() {
key = "test"
err = fmt.Errorf("configstore: get '%s': no item found", key)
err = errors.Errorf("configstore: get '%s': no item found", key)
})

It("Should return false", func() {
Expand Down
4 changes: 3 additions & 1 deletion pkg/harbor/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io/ioutil"
"net/http"
"strings"

"github.com/pkg/errors"
)

// ApplyConfiguration applies configuration to harbor instance.
Expand Down Expand Up @@ -36,7 +38,7 @@ func (c *client) ApplyConfiguration(ctx context.Context, config []byte) error {
return fmt.Errorf("read http response body error: %w", err)
}

return fmt.Errorf("response status code is %d, body is %s", code, string(body))
return errors.Errorf("response status code is %d, body is %s", code, string(body))
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/goharbor/harbor-operator/pkg/config"
"github.com/goharbor/harbor-operator/pkg/version"
"github.com/ovh/configstore"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -261,7 +262,7 @@ func GetImage(ctx context.Context, component string, options ...Option) (string,

imageName, ok := knowCompoents.GetImageName(component, opts.harborVersion)
if !ok {
return "", fmt.Errorf("unknow component %s", component)
return "", errors.Errorf("unknow component %s", component)
}

repository := opts.repository
Expand Down
3 changes: 2 additions & 1 deletion pkg/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/ovh/configstore"
"github.com/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

Expand Down Expand Up @@ -109,7 +110,7 @@ var _ = Describe("Get image", func() {
It("Should pass", func() {
configStore := configstore.NewStore()
configStore.RegisterProvider("foo", func() (configstore.ItemList, error) {
return configstore.ItemList{}, fmt.Errorf("failed")
return configstore.ItemList{}, errors.Errorf("failed")
})

_, err := GetImage(ctx, "core", WithConfigstore(configStore))
Expand Down
10 changes: 5 additions & 5 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package version

import (
"fmt"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -41,7 +41,7 @@ func Default() string {
// Validate returns nil when version is the default version.
func Validate(version string) error {
if version != Default() {
return fmt.Errorf("version %s not support, please use version %s", version, Default())
return errors.Errorf("version %s not support, please use version %s", version, Default())
}

return nil
Expand All @@ -51,16 +51,16 @@ func Validate(version string) error {
func UpgradeAllowed(from, to string) error {
fromIndex, ok := knowVersionIndexes[from]
if !ok {
return fmt.Errorf("unknow version %s", from)
return errors.Errorf("unknow version %s", from)
}

toIndex, ok := knowVersionIndexes[to]
if !ok {
return fmt.Errorf("unknow version %s", to)
return errors.Errorf("unknow version %s", to)
}

if toIndex < fromIndex {
return fmt.Errorf("downgrade from version %s to %s is not allowed", from, to)
return errors.Errorf("downgrade from version %s to %s is not allowed", from, to)
}

return nil
Expand Down

0 comments on commit 297c04f

Please sign in to comment.