diff --git a/Makefile b/Makefile index f23004c2a..744ec17e6 100644 --- a/Makefile +++ b/Makefile @@ -140,7 +140,7 @@ allall: all # Tip: Run `eval $(minikube docker-env)` before calling make if you're developing on minikube. # -GOLANGCI_ENABLED=deadcode govet ineffassign staticcheck structcheck typecheck unconvert unparam unused varcheck +GOLANGCI_ENABLED=deadcode gosimple govet ineffassign staticcheck structcheck typecheck unconvert unparam unused varcheck #GOLANGCI_ENABLED=gocyclo goconst golint maligned errcheck interfacer megacheck #GOLANGCI_ENABLED+=dupl - disable dupl check diff --git a/pkg/apis/shared/errors.go b/pkg/apis/shared/errors.go index 2a347ed34..418ef2382 100644 --- a/pkg/apis/shared/errors.go +++ b/pkg/apis/shared/errors.go @@ -126,9 +126,7 @@ func WithErrors(errs ...error) error { switch errType := err.(type) { case MergedErrors: - for _, subError := range errType.errors { - filteredErrs = append(filteredErrs, subError) - } + filteredErrs = append(filteredErrs, errType.errors...) default: filteredErrs = append(filteredErrs, err) } diff --git a/pkg/deployment/pod/affinity.go b/pkg/deployment/pod/affinity.go index 277767987..0e36d1760 100644 --- a/pkg/deployment/pod/affinity.go +++ b/pkg/deployment/pod/affinity.go @@ -92,13 +92,11 @@ func MergePodAntiAffinity(a, b *core.PodAntiAffinity) { return } - for _, rule := range b.PreferredDuringSchedulingIgnoredDuringExecution { - a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution, rule) - } + a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution, + b.PreferredDuringSchedulingIgnoredDuringExecution...) - for _, rule := range b.RequiredDuringSchedulingIgnoredDuringExecution { - a.RequiredDuringSchedulingIgnoredDuringExecution = append(a.RequiredDuringSchedulingIgnoredDuringExecution, rule) - } + a.RequiredDuringSchedulingIgnoredDuringExecution = append(a.RequiredDuringSchedulingIgnoredDuringExecution, + b.RequiredDuringSchedulingIgnoredDuringExecution...) } func MergePodAffinity(a, b *core.PodAffinity) { @@ -106,13 +104,11 @@ func MergePodAffinity(a, b *core.PodAffinity) { return } - for _, rule := range b.PreferredDuringSchedulingIgnoredDuringExecution { - a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution, rule) - } + a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution, + b.PreferredDuringSchedulingIgnoredDuringExecution...) - for _, rule := range b.RequiredDuringSchedulingIgnoredDuringExecution { - a.RequiredDuringSchedulingIgnoredDuringExecution = append(a.RequiredDuringSchedulingIgnoredDuringExecution, rule) - } + a.RequiredDuringSchedulingIgnoredDuringExecution = append(a.RequiredDuringSchedulingIgnoredDuringExecution, + b.RequiredDuringSchedulingIgnoredDuringExecution...) } func MergeNodeAffinity(a, b *core.NodeAffinity) { @@ -120,9 +116,8 @@ func MergeNodeAffinity(a, b *core.NodeAffinity) { return } - for _, rule := range b.PreferredDuringSchedulingIgnoredDuringExecution { - a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution, rule) - } + a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution, + b.PreferredDuringSchedulingIgnoredDuringExecution...) var newSelectorTerms []core.NodeSelectorTerm diff --git a/pkg/deployment/reconcile/action_bootstrap_update.go b/pkg/deployment/reconcile/action_bootstrap_update.go index 33d528c4d..bfe0bc759 100644 --- a/pkg/deployment/reconcile/action_bootstrap_update.go +++ b/pkg/deployment/reconcile/action_bootstrap_update.go @@ -24,7 +24,6 @@ package reconcile import ( "context" - "fmt" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/rs/zerolog" @@ -53,8 +52,8 @@ type actionBootstrapUpdate struct { func (a actionBootstrapUpdate) Start(ctx context.Context) (bool, error) { if err := a.actionCtx.WithStatusUpdate(ctx, func(status *api.DeploymentStatus) bool { if errMessage, ok := a.action.GetParam("error"); ok { - status.Conditions.Update(api.ConditionTypeBootstrapCompleted, true, "Bootstrap failed", fmt.Sprintf("%s", errMessage)) - status.Conditions.Update(api.ConditionTypeBootstrapSucceded, false, "Bootstrap failed", fmt.Sprintf("%s", errMessage)) + status.Conditions.Update(api.ConditionTypeBootstrapCompleted, true, "Bootstrap failed", errMessage) + status.Conditions.Update(api.ConditionTypeBootstrapSucceded, false, "Bootstrap failed", errMessage) } else { status.Conditions.Update(api.ConditionTypeBootstrapCompleted, true, "Bootstrap successful", "The bootstrap process has been completed successfully") status.Conditions.Update(api.ConditionTypeBootstrapSucceded, true, "Bootstrap successful", "The bootstrap process has been completed successfully") diff --git a/pkg/deployment/reconcile/plan_builder_encryption.go b/pkg/deployment/reconcile/plan_builder_encryption.go index 7414bd700..60899ad13 100644 --- a/pkg/deployment/reconcile/plan_builder_encryption.go +++ b/pkg/deployment/reconcile/plan_builder_encryption.go @@ -176,11 +176,7 @@ func createEncryptionKeyStatusUpdateRequired(log zerolog.Logger, spec api.Deploy keyHashes := secretKeysToListWithPrefix(keyfolder) - if !util.CompareStringArray(keyHashes, status.Hashes.Encryption.Keys) { - return true - } - - return false + return !util.CompareStringArray(keyHashes, status.Hashes.Encryption.Keys) } func createEncryptionKeyCleanPlan(ctx context.Context, diff --git a/pkg/deployment/reconcile/plan_builder_jwt.go b/pkg/deployment/reconcile/plan_builder_jwt.go index c190081c1..71162f1ba 100644 --- a/pkg/deployment/reconcile/plan_builder_jwt.go +++ b/pkg/deployment/reconcile/plan_builder_jwt.go @@ -183,10 +183,7 @@ func createJWTStatusUpdateRequired(log zerolog.Logger, apiObject k8sutil.APIObje } if len(f.Data) == 0 { - if status.Hashes.JWT.Passive != nil { - return true - } - return false + return status.Hashes.JWT.Passive != nil } var keys []string @@ -200,20 +197,13 @@ func createJWTStatusUpdateRequired(log zerolog.Logger, apiObject k8sutil.APIObje } if len(keys) == 0 { - if status.Hashes.JWT.Passive != nil { - return true - } - return false + return status.Hashes.JWT.Passive != nil } sort.Strings(keys) keys = util.PrefixStringArray(keys, "sha256:") - if !util.CompareStringArray(keys, status.Hashes.JWT.Passive) { - return true - } - - return false + return !util.CompareStringArray(keys, status.Hashes.JWT.Passive) } func areJWTTokensUpToDate(ctx context.Context, log zerolog.Logger, status api.DeploymentStatus, diff --git a/pkg/util/k8sutil/pair.go b/pkg/util/k8sutil/pair.go index 5af85152a..406294387 100644 --- a/pkg/util/k8sutil/pair.go +++ b/pkg/util/k8sutil/pair.go @@ -115,10 +115,7 @@ func (o OptionPairs) Unique() OptionPairs { func (o OptionPairs) Copy() OptionPairs { r := make(OptionPairs, len(o)) - - for id, option := range o { - r[id] = option - } + copy(r, o) return r }