Skip to content

Commit 0fb33bc

Browse files
committed
🌱 Update golangci-lint to v1.40.1, enable importas and revive
Signed-off-by: Vince Prignano <[email protected]>
1 parent 2bed3c3 commit 0fb33bc

40 files changed

+389
-283
lines changed

.github/workflows/golangci-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
- name: golangci-lint
1515
uses: golangci/golangci-lint-action@v2
1616
with:
17-
version: v1.38
17+
version: v1.40.1

.golangci.yml

+36-8
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ linters:
1111
- goconst
1212
- gocritic
1313
- gocyclo
14+
- godot
1415
- gofmt
1516
- goimports
16-
- golint
1717
- goprintffuncname
1818
- gosec
1919
- gosimple
2020
- govet
21+
- importas
2122
- ineffassign
2223
- misspell
2324
- nakedret
2425
- nolintlint
2526
- prealloc
27+
- revive
2628
- rowserrcheck
2729
- staticcheck
2830
- structcheck
@@ -31,9 +33,31 @@ linters:
3133
- unconvert
3234
- unparam
3335
- varcheck
34-
- godot
3536
- whitespace
3637

38+
linters-settings:
39+
staticcheck:
40+
go: "1.16"
41+
stylecheck:
42+
go: "1.16"
43+
importas:
44+
no-unaliased: true
45+
alias:
46+
# Kubernetes
47+
- pkg: k8s.io/api/core/v1
48+
alias: corev1
49+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
50+
alias: apiextensionsv1
51+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
52+
alias: metav1
53+
- pkg: k8s.io/apimachinery/pkg/api/errors
54+
alias: apierrors
55+
- pkg: k8s.io/apimachinery/pkg/util/errors
56+
alias: kerrors
57+
# Controller Runtime
58+
- pkg: sigs.k8s.io/controller-runtime
59+
alias: ctrl
60+
3761
issues:
3862
max-same-issues: 0
3963
max-issues-per-linter: 0
@@ -44,30 +68,30 @@ issues:
4468
exclude:
4569
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
4670
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
47-
- exported method `.*.(Reconcile|SetupWithManager|SetupWebhookWithManager)` should have comment or be unexported
71+
- "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
4872
# The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time.
4973
# If it is decided they will not be addressed they should be moved above this comment.
5074
- Subprocess launch(ed with variable|ing should be audited)
5175
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
5276
- (G104|G307)
5377
exclude-rules:
5478
# With Go 1.16, the new embed directive can be used with an un-named import,
55-
# golint only allows these to be imported in a main.go, which wouldn't work for us.
79+
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
5680
# This directive allows the embed package to be imported with an underscore everywhere.
5781
- linters:
58-
- golint
82+
- revive
5983
source: _ "embed"
6084
# Exclude some packages or code to require comments, for example test code, or fake clients.
6185
- linters:
62-
- golint
86+
- revive
6387
text: exported (method|function|type|const) (.+) should have comment or be unexported
6488
source: (func|type).*Fake.*
6589
- linters:
66-
- golint
90+
- revive
6791
text: exported (method|function|type|const) (.+) should have comment or be unexported
6892
path: fake_\.go
6993
- linters:
70-
- golint
94+
- revive
7195
text: exported (method|function|type|const) (.+) should have comment or be unexported
7296
path: .*test/(providers|framework|e2e).*.go
7397
# Disable unparam "always receives" which might not be really
@@ -83,6 +107,10 @@ issues:
83107
text: cyclomatic complexity
84108
- path: test/(framework|e2e).*.go
85109
text: should not use dot imports
110+
# Append should be able to assign to a different var/slice.
111+
- linters:
112+
- gocritic
113+
text: "appendAssign: append result not assigned to the same slice"
86114

87115
run:
88116
timeout: 10m

bootstrap/kubeadm/controllers/token.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/pkg/errors"
24-
v1 "k8s.io/api/core/v1"
24+
corev1 "k8s.io/api/core/v1"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
bootstrapapi "k8s.io/cluster-bootstrap/token/api"
2727
bootstraputil "k8s.io/cluster-bootstrap/token/util"
@@ -48,7 +48,7 @@ func createToken(ctx context.Context, c client.Client) (string, error) {
4848
tokenSecret := substrs[2]
4949

5050
secretName := bootstraputil.BootstrapTokenSecretName(tokenID)
51-
secretToken := &v1.Secret{
51+
secretToken := &corev1.Secret{
5252
ObjectMeta: metav1.ObjectMeta{
5353
Name: secretName,
5454
Namespace: metav1.NamespaceSystem,
@@ -72,15 +72,15 @@ func createToken(ctx context.Context, c client.Client) (string, error) {
7272
}
7373

7474
// getToken fetches the token Secret and returns an error if it is invalid.
75-
func getToken(ctx context.Context, c client.Client, token string) (*v1.Secret, error) {
75+
func getToken(ctx context.Context, c client.Client, token string) (*corev1.Secret, error) {
7676
substrs := bootstraputil.BootstrapTokenRegexp.FindStringSubmatch(token)
7777
if len(substrs) != 3 {
7878
return nil, errors.Errorf("the bootstrap token %q was not of the form %q", token, bootstrapapi.BootstrapTokenPattern)
7979
}
8080
tokenID := substrs[1]
8181

8282
secretName := bootstraputil.BootstrapTokenSecretName(tokenID)
83-
secret := &v1.Secret{}
83+
secret := &corev1.Secret{}
8484
if err := c.Get(ctx, client.ObjectKey{Name: secretName, Namespace: metav1.NamespaceSystem}, secret); err != nil {
8585
return secret, err
8686
}

bootstrap/kubeadm/internal/locking/control_plane_init_mutex.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
"github.com/go-logr/logr"
2626
"github.com/pkg/errors"
27-
apicorev1 "k8s.io/api/core/v1"
27+
corev1 "k8s.io/api/core/v1"
2828
apierrors "k8s.io/apimachinery/pkg/api/errors"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
@@ -133,11 +133,11 @@ type information struct {
133133
}
134134

135135
type semaphore struct {
136-
*apicorev1.ConfigMap
136+
*corev1.ConfigMap
137137
}
138138

139139
func newSemaphore() *semaphore {
140-
return &semaphore{&apicorev1.ConfigMap{}}
140+
return &semaphore{&corev1.ConfigMap{}}
141141
}
142142

143143
func configMapName(clusterName string) string {

bootstrap/kubeadm/types/v1beta1/types.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20-
v1 "k8s.io/api/core/v1"
20+
corev1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
)
2323

@@ -222,7 +222,7 @@ type NodeRegistrationOptions struct {
222222
// it will be defaulted to []v1.Taint{'node-role.kubernetes.io/master=""'}. If you don't want to taint your control-plane node, set this field to an
223223
// empty slice, i.e. `taints: {}` in the YAML file. This field is solely used for Node registration.
224224
// +optional
225-
Taints []v1.Taint `json:"taints,omitempty"`
225+
Taints []corev1.Taint `json:"taints,omitempty"`
226226

227227
// KubeletExtraArgs passes through extra arguments to the kubelet. The arguments here are passed to the kubelet command line via the environment file
228228
// kubeadm writes at runtime for the kubelet to source. This overrides the generic base-level configuration in the kubelet-config-1.X ConfigMap
@@ -422,5 +422,5 @@ type HostPathMount struct {
422422
// ReadOnly controls write access to the volume
423423
ReadOnly bool `json:"readOnly,omitempty"`
424424
// PathType is the type of the HostPath.
425-
PathType v1.HostPathType `json:"pathType,omitempty"`
425+
PathType corev1.HostPathType `json:"pathType,omitempty"`
426426
}

cmd/clusterctl/client/cluster/cert_manager.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,7 @@ func (cm *certManagerClient) install() error {
177177
}
178178

179179
// Wait for the cert-manager API to be ready to accept requests
180-
if err := cm.waitForAPIReady(ctx, true); err != nil {
181-
return err
182-
}
183-
184-
return nil
180+
return cm.waitForAPIReady(ctx, true)
185181
}
186182

187183
// PlanUpgrade retruns a CertManagerUpgradePlan with information regarding
@@ -438,11 +434,7 @@ func (cm *certManagerClient) deleteObj(obj unstructured.Unstructured) error {
438434
return err
439435
}
440436

441-
if err := cl.Delete(ctx, &obj); err != nil {
442-
return err
443-
}
444-
445-
return nil
437+
return cl.Delete(ctx, &obj)
446438
}
447439

448440
// waitForAPIReady will attempt to create the cert-manager 'test assets' (i.e. a basic

cmd/clusterctl/client/cluster/installer.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,7 @@ func installComponentsAndUpdateInventory(components repository.Components, provi
114114
}
115115

116116
log.V(1).Info("Creating inventory entry", "Provider", components.ManifestLabel(), "Version", components.Version(), "TargetNamespace", components.TargetNamespace())
117-
if err := providerInventory.Create(inventoryObject); err != nil {
118-
return err
119-
}
120-
121-
return nil
117+
return providerInventory.Create(inventoryObject)
122118
}
123119

124120
// shouldInstallSharedComponents checks if it is required to install shared components for a provider.

cmd/clusterctl/client/cluster/mover.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ func (o *objectMover) Move(namespace string, toCluster Client, dryRun bool) erro
9999
proxy = toCluster.Proxy()
100100
}
101101

102-
if err := o.move(objectGraph, proxy); err != nil {
103-
return err
104-
}
105-
106-
return nil
102+
return o.move(objectGraph, proxy)
107103
}
108104

109105
func newObjectMover(fromProxy Proxy, fromProviderInventory InventoryClient) *objectMover {
@@ -250,11 +246,7 @@ func (o *objectMover) move(graph *objectGraph, toProxy Proxy) error {
250246

251247
// Reset the pause field on the Cluster object in the target management cluster, so the controllers start reconciling it.
252248
log.V(1).Info("Resuming the target cluster")
253-
if err := setClusterPause(toProxy, clusters, false, o.dryRun); err != nil {
254-
return err
255-
}
256-
257-
return nil
249+
return setClusterPause(toProxy, clusters, false, o.dryRun)
258250
}
259251

260252
// moveSequence defines a list of group of moveGroups.

cmd/clusterctl/client/config/reader_viper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func downloadFile(url string, filepath string) error {
148148
return errors.Wrapf(err, "failed to download the clusterctl config file from %s", url)
149149
}
150150
if resp.StatusCode != http.StatusOK {
151-
return errors.New(fmt.Sprintf("failed to download the clusterctl config file from %s got %d", url, resp.StatusCode))
151+
return errors.Errorf("failed to download the clusterctl config file from %s got %d", url, resp.StatusCode)
152152
}
153153
defer resp.Body.Close()
154154

cmd/clusterctl/client/init_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ func templateYAML(ns string, clusterName string) []byte {
781781
// infraComponentsYAML defines a namespace and deployment with container
782782
// images and a variable.
783783
func infraComponentsYAML(namespace string) []byte {
784-
var infraComponentsYAML string = `---
784+
var infraComponentsYAML = `---
785785
apiVersion: v1
786786
kind: Namespace
787787
metadata:

cmd/clusterctl/client/move.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,5 @@ func (c *clusterctlClient) Move(options MoveOptions) error {
8383
options.Namespace = currentNamespace
8484
}
8585

86-
if err := fromCluster.ObjectMover().Move(options.Namespace, toCluster, options.DryRun); err != nil {
87-
return err
88-
}
89-
90-
return nil
86+
return fromCluster.ObjectMover().Move(options.Namespace, toCluster, options.DryRun)
9187
}

cmd/clusterctl/client/upgrade.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,11 @@ func (c *clusterctlClient) ApplyUpgrade(options ApplyUpgradeOptions) error {
170170
}
171171

172172
// Execute the upgrade using the custom upgrade items
173-
if err := clusterClient.ProviderUpgrader().ApplyCustomPlan(upgradeItems...); err != nil {
174-
return err
175-
}
176-
177-
return nil
173+
return clusterClient.ProviderUpgrader().ApplyCustomPlan(upgradeItems...)
178174
}
179175

180176
// Otherwise we are upgrading a whole management cluster according to a clusterctl generated upgrade plan.
181-
if err := clusterClient.ProviderUpgrader().ApplyPlan(options.Contract); err != nil {
182-
return err
183-
}
184-
185-
return nil
177+
return clusterClient.ProviderUpgrader().ApplyPlan(options.Contract)
186178
}
187179

188180
func addUpgradeItems(upgradeItems []cluster.UpgradeItem, providerType clusterctlv1.ProviderType, providers ...string) ([]cluster.UpgradeItem, error) {

cmd/clusterctl/cmd/delete.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func runDelete() error {
127127
return errors.New("At least one of --core, --bootstrap, --control-plane, --infrastructure should be specified or the --all flag should be set")
128128
}
129129

130-
if err := c.Delete(client.DeleteOptions{
130+
return c.Delete(client.DeleteOptions{
131131
Kubeconfig: client.Kubeconfig{Path: dd.kubeconfig, Context: dd.kubeconfigContext},
132132
IncludeNamespace: dd.includeNamespace,
133133
IncludeCRDs: dd.includeCRDs,
@@ -136,9 +136,5 @@ func runDelete() error {
136136
InfrastructureProviders: dd.infrastructureProviders,
137137
ControlPlaneProviders: dd.controlPlaneProviders,
138138
DeleteAll: dd.deleteAll,
139-
}); err != nil {
140-
return err
141-
}
142-
143-
return nil
139+
})
144140
}

cmd/clusterctl/cmd/move.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,10 @@ func runMove() error {
7878
return err
7979
}
8080

81-
if err := c.Move(client.MoveOptions{
81+
return c.Move(client.MoveOptions{
8282
FromKubeconfig: client.Kubeconfig{Path: mo.fromKubeconfig, Context: mo.fromKubeconfigContext},
8383
ToKubeconfig: client.Kubeconfig{Path: mo.toKubeconfig, Context: mo.toKubeconfigContext},
8484
Namespace: mo.namespace,
8585
DryRun: mo.dryRun,
86-
}); err != nil {
87-
return err
88-
}
89-
return nil
86+
})
9087
}

cmd/clusterctl/cmd/rollout/pause.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,9 @@ func runPause(cfgFile string, args []string) error {
7474
return err
7575
}
7676

77-
if err := c.RolloutPause(client.RolloutOptions{
77+
return c.RolloutPause(client.RolloutOptions{
7878
Kubeconfig: client.Kubeconfig{Path: pauseOpt.kubeconfig, Context: pauseOpt.kubeconfigContext},
7979
Namespace: pauseOpt.namespace,
8080
Resources: pauseOpt.resources,
81-
}); err != nil {
82-
return err
83-
}
84-
return nil
81+
})
8582
}

cmd/clusterctl/cmd/rollout/restart.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,9 @@ func runRestart(cfgFile string, _ *cobra.Command, args []string) error {
7272
return err
7373
}
7474

75-
if err := c.RolloutRestart(client.RolloutOptions{
75+
return c.RolloutRestart(client.RolloutOptions{
7676
Kubeconfig: client.Kubeconfig{Path: restartOpt.kubeconfig, Context: restartOpt.kubeconfigContext},
7777
Namespace: restartOpt.namespace,
7878
Resources: restartOpt.resources,
79-
}); err != nil {
80-
return err
81-
}
82-
return nil
79+
})
8380
}

cmd/clusterctl/cmd/rollout/resume.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,9 @@ func runResume(cfgFile string, args []string) error {
7272
return err
7373
}
7474

75-
if err := c.RolloutResume(client.RolloutOptions{
75+
return c.RolloutResume(client.RolloutOptions{
7676
Kubeconfig: client.Kubeconfig{Path: resumeOpt.kubeconfig, Context: resumeOpt.kubeconfigContext},
7777
Namespace: resumeOpt.namespace,
7878
Resources: resumeOpt.resources,
79-
}); err != nil {
80-
return err
81-
}
82-
return nil
79+
})
8380
}

0 commit comments

Comments
 (0)