Skip to content

Commit b9f2389

Browse files
authored
Merge pull request #3120 from benmoss/bump-linters
🌱 Update golint-ci, fix warnings
2 parents 58455c9 + 88e65e0 commit b9f2389

File tree

24 files changed

+160
-75
lines changed

24 files changed

+160
-75
lines changed

.golangci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ linters:
1212
- gocognit
1313
- gomnd
1414
- interfacer
15+
- godot
16+
- goerr113
17+
- nestif
1518
# Run with --fast=false for more extensive checks
1619
fast: true
1720
issues:

cmd/clusterctl/client/cluster/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ type Proxy interface {
215215
}
216216

217217
// retryWithExponentialBackoff repeats an operation until it passes or the exponential backoff times out.
218-
func retryWithExponentialBackoff(opts wait.Backoff, operation func() error) error { //nolint:unparam
218+
func retryWithExponentialBackoff(opts wait.Backoff, operation func() error) error {
219219
log := logf.Log
220220

221221
i := 0

cmd/clusterctl/client/cluster/objectgraph_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ func getDetachedObjectGraphWihObjs(objs []runtime.Object) (*objectGraph, error)
858858
graph := newObjectGraph(nil) // detached from any cluster
859859
for _, o := range objs {
860860
u := &unstructured.Unstructured{}
861-
if err := test.FakeScheme.Convert(o, u, nil); err != nil { //nolint
861+
if err := test.FakeScheme.Convert(o, u, nil); err != nil {
862862
return nil, errors.Wrap(err, "failed to convert object in unstructured")
863863
}
864864
graph.addObj(u)

cmd/clusterctl/client/cluster/proxy_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestProxyGetConfig(t *testing.T) {
6767
g.Expect(err).NotTo(HaveOccurred())
6868
defer os.RemoveAll(dir)
6969
configFile := filepath.Join(dir, ".test-kubeconfig.yaml")
70-
g.Expect(ioutil.WriteFile(configFile, []byte(tt.kubeconfigContents), 0640)).To(Succeed())
70+
g.Expect(ioutil.WriteFile(configFile, []byte(tt.kubeconfigContents), 0600)).To(Succeed())
7171

7272
proxy := newProxy(Kubeconfig{Path: configFile, Context: tt.context})
7373
conf, err := proxy.GetConfig()
@@ -94,7 +94,7 @@ func TestProxyGetConfig(t *testing.T) {
9494
g.Expect(err).NotTo(HaveOccurred())
9595
defer os.RemoveAll(dir)
9696
configFile := filepath.Join(dir, ".test-kubeconfig.yaml")
97-
g.Expect(ioutil.WriteFile(configFile, []byte(kubeconfig("management", "default")), 0640)).To(Succeed())
97+
g.Expect(ioutil.WriteFile(configFile, []byte(kubeconfig("management", "default")), 0600)).To(Succeed())
9898

9999
proxy := newProxy(Kubeconfig{Path: configFile, Context: "management"}, InjectProxyTimeout(23*time.Second))
100100
conf, err := proxy.GetConfig()
@@ -121,7 +121,7 @@ func TestKUBECONFIGEnvVar(t *testing.T) {
121121
g.Expect(err).NotTo(HaveOccurred())
122122
defer os.RemoveAll(dir)
123123
configFile := filepath.Join(dir, ".test-kubeconfig.yaml")
124-
g.Expect(ioutil.WriteFile(configFile, []byte(kubeconfigContents), 0640)).To(Succeed())
124+
g.Expect(ioutil.WriteFile(configFile, []byte(kubeconfigContents), 0600)).To(Succeed())
125125

126126
proxy := newProxy(
127127
// dont't give an explicit path but rather define the file in the
@@ -149,7 +149,7 @@ func TestKUBECONFIGEnvVar(t *testing.T) {
149149
g.Expect(err).NotTo(HaveOccurred())
150150
defer os.RemoveAll(dir)
151151
configFile := filepath.Join(dir, ".test-kubeconfig.yaml")
152-
g.Expect(ioutil.WriteFile(configFile, []byte(kubeconfigContents), 0640)).To(Succeed())
152+
g.Expect(ioutil.WriteFile(configFile, []byte(kubeconfigContents), 0600)).To(Succeed())
153153

154154
proxy := newProxy(
155155
// dont't give an explicit path but rather define the file in the
@@ -226,7 +226,7 @@ func TestProxyCurrentNamespace(t *testing.T) {
226226
g.Expect(err).NotTo(HaveOccurred())
227227
defer os.RemoveAll(dir)
228228
configFile = filepath.Join(dir, ".test-kubeconfig.yaml")
229-
g.Expect(ioutil.WriteFile(configFile, []byte(tt.kubeconfigContents), 0640)).To(Succeed())
229+
g.Expect(ioutil.WriteFile(configFile, []byte(tt.kubeconfigContents), 0600)).To(Succeed())
230230
}
231231

232232
proxy := newProxy(Kubeconfig{Path: configFile, Context: tt.kubeconfigContext})

cmd/clusterctl/client/cluster/template_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func Test_templateClient_getLocalFileContent(t *testing.T) {
230230
defer os.RemoveAll(tmpDir)
231231

232232
path := filepath.Join(tmpDir, "cluster-template.yaml")
233-
g.Expect(ioutil.WriteFile(path, []byte(template), 0644)).To(Succeed())
233+
g.Expect(ioutil.WriteFile(path, []byte(template), 0600)).To(Succeed())
234234

235235
type args struct {
236236
rURL *url.URL
@@ -302,7 +302,7 @@ func Test_templateClient_GetFromURL(t *testing.T) {
302302
})
303303

304304
path := filepath.Join(tmpDir, "cluster-template.yaml")
305-
g.Expect(ioutil.WriteFile(path, []byte(template), 0644)).To(Succeed())
305+
g.Expect(ioutil.WriteFile(path, []byte(template), 0600)).To(Succeed())
306306

307307
type args struct {
308308
templateURL string

cmd/clusterctl/client/config/reader_viper_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ func Test_viperReader_Init(t *testing.T) {
4141
defer os.RemoveAll(dir)
4242

4343
configFile := filepath.Join(dir, "clusterctl.yaml")
44-
g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0640)).To(Succeed())
44+
g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed())
4545

4646
configFileBadContents := filepath.Join(dir, "clusterctl-bad.yaml")
47-
g.Expect(ioutil.WriteFile(configFileBadContents, []byte("bad-contents"), 0640)).To(Succeed())
47+
g.Expect(ioutil.WriteFile(configFileBadContents, []byte("bad-contents"), 0600)).To(Succeed())
4848

4949
tests := []struct {
5050
name string
@@ -102,7 +102,7 @@ func Test_viperReader_Get(t *testing.T) {
102102
os.Setenv("FOO", "foo")
103103

104104
configFile := filepath.Join(dir, "clusterctl.yaml")
105-
g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0640)).To(Succeed())
105+
g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed())
106106

107107
type args struct {
108108
key string
@@ -185,7 +185,7 @@ func Test_viperReader_Set(t *testing.T) {
185185

186186
configFile := filepath.Join(dir, "clusterctl.yaml")
187187

188-
g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0640)).To(Succeed())
188+
g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed())
189189

190190
type args struct {
191191
key string
@@ -230,7 +230,7 @@ func Test_viperReader_checkDefaultConfig(t *testing.T) {
230230
dir = strings.TrimSuffix(dir, "/")
231231

232232
configFile := filepath.Join(dir, "clusterctl.yaml")
233-
g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0640)).To(Succeed())
233+
g.Expect(ioutil.WriteFile(configFile, []byte("bar: bar"), 0600)).To(Succeed())
234234

235235
type fields struct {
236236
configPaths []string

cmd/clusterctl/client/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
424424
defer os.RemoveAll(tmpDir)
425425

426426
path := filepath.Join(tmpDir, "cluster-template.yaml")
427-
g.Expect(ioutil.WriteFile(path, rawTemplate, 0644)).To(Succeed())
427+
g.Expect(ioutil.WriteFile(path, rawTemplate, 0600)).To(Succeed())
428428

429429
// Template on a repository & in a ConfigMap
430430
configMap := &corev1.ConfigMap{

cmd/clusterctl/client/repository/repository_github.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func (g *gitHubRepository) downloadFilesFromRelease(release *github.RepositoryRe
304304
return nil, g.handleGithubErr(err, "failed to download file %q from %q release", *release.TagName, fileName)
305305
}
306306
if redirect != "" {
307-
response, err := http.Get(redirect) //nolint:bodyclose (NB: The reader is actually closed in a defer)
307+
response, err := http.Get(redirect) //nolint:bodyclose // (NB: The reader is actually closed in a defer)
308308
if err != nil {
309309
return nil, errors.Wrapf(err, "failed to download file %q from %q release via redirect location %q", *release.TagName, fileName, redirect)
310310
}

cmd/clusterctl/client/repository/repository_local_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func createLocalTestProviderFile(t *testing.T, tmpDir, path, msg string) string
139139
dst := filepath.Join(tmpDir, path)
140140
// Create all directories in the standard layout
141141
g.Expect(os.MkdirAll(filepath.Dir(dst), 0755)).To(Succeed())
142-
g.Expect(ioutil.WriteFile(dst, []byte(msg), 0644)).To(Succeed())
142+
g.Expect(ioutil.WriteFile(dst, []byte(msg), 0600)).To(Succeed())
143143

144144
return dst
145145
}

cmd/clusterctl/cmd/config_repositories_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Test_runGetRepositories(t *testing.T) {
3535
defer os.RemoveAll(tmpDir)
3636

3737
path := filepath.Join(tmpDir, "clusterctl.yaml")
38-
g.Expect(ioutil.WriteFile(path, []byte(template), 0644)).To(Succeed())
38+
g.Expect(ioutil.WriteFile(path, []byte(template), 0600)).To(Succeed())
3939

4040
buf := bytes.NewBufferString("")
4141

@@ -71,7 +71,7 @@ func Test_runGetRepositories(t *testing.T) {
7171
defer os.RemoveAll(tmpDir)
7272

7373
path := filepath.Join(tmpDir, "clusterctl.yaml")
74-
g.Expect(ioutil.WriteFile(path, []byte("providers: foobar"), 0644)).To(Succeed())
74+
g.Expect(ioutil.WriteFile(path, []byte("providers: foobar"), 0600)).To(Succeed())
7575

7676
buf := bytes.NewBufferString("")
7777
g.Expect(runGetRepositories(path, buf)).ToNot(Succeed())

cmd/clusterctl/cmd/upgrade_plan.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func runUpgradePlan() error {
105105
if upgradeAvailable {
106106
fmt.Println("You can now apply the upgrade by executing the following command:")
107107
fmt.Println("")
108-
fmt.Println(fmt.Sprintf(" upgrade apply --management-group %s --contract %s", plan.CoreProvider.InstanceName(), plan.Contract))
108+
fmt.Printf(" upgrade apply --management-group %s --contract %s\n", plan.CoreProvider.InstanceName(), plan.Contract)
109109
} else {
110110
fmt.Println("You are already up to date!")
111111
}

cmd/clusterctl/internal/util/yaml.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func JoinYaml(yamls ...[]byte) []byte {
5555

5656
// ToUnstructured takes a YAML and converts it to a list of Unstructured objects
5757
func ToUnstructured(rawyaml []byte) ([]unstructured.Unstructured, error) {
58-
var ret []unstructured.Unstructured //nolint
58+
var ret []unstructured.Unstructured
5959

6060
reader := utilyaml.NewYAMLReader(bufio.NewReader(bytes.NewReader(rawyaml)))
6161
count := 1

controllers/mdutil/util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func getIntFromAnnotation(ms *clusterv1.MachineSet, annotationKey string, logger
193193
if !ok {
194194
return int32(0), false
195195
}
196-
intValue, err := strconv.Atoi(annotationValue)
196+
intValue, err := strconv.ParseInt(annotationValue, 10, 32)
197197
if err != nil {
198198
logger.V(2).Info("Cannot convert the value to integer", "annotationValue", annotationValue)
199199
return int32(0), false
@@ -563,7 +563,7 @@ func IsSaturated(deployment *clusterv1.MachineDeployment, ms *clusterv1.MachineS
563563
return false
564564
}
565565
desiredString := ms.Annotations[clusterv1.DesiredReplicasAnnotation]
566-
desired, err := strconv.Atoi(desiredString)
566+
desired, err := strconv.ParseInt(desiredString, 10, 32)
567567
if err != nil {
568568
return false
569569
}

controlplane/kubeadm/controllers/controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
554554
"test0": &clusterv1.Machine{
555555
ObjectMeta: metav1.ObjectMeta{
556556
Namespace: cluster.Namespace,
557-
Name: fmt.Sprintf("test0"),
557+
Name: "test0",
558558
Labels: internal.ControlPlaneLabelsForCluster(cluster.Name),
559559
},
560560
Spec: clusterv1.MachineSpec{

controlplane/kubeadm/internal/machine_collection.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ func NewFilterableMachineCollection(machines ...*clusterv1.Machine) FilterableMa
4848
// NewFilterableMachineCollectionFromMachineList creates a FilterableMachineCollection from the given MachineList
4949
func NewFilterableMachineCollectionFromMachineList(machineList *clusterv1.MachineList) FilterableMachineCollection {
5050
ss := make(FilterableMachineCollection, len(machineList.Items))
51-
if machineList != nil {
52-
for i := range machineList.Items {
53-
ss.Insert(&machineList.Items[i])
54-
}
51+
for i := range machineList.Items {
52+
ss.Insert(&machineList.Items[i])
5553
}
5654
return ss
5755
}

hack/tools/go.mod

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ go 1.13
55
require (
66
github.com/blang/semver v3.5.1+incompatible
77
github.com/go-bindata/go-bindata v3.1.2+incompatible
8-
github.com/golangci/golangci-lint v1.23.8
8+
github.com/golangci/golangci-lint v1.27.0
99
github.com/joelanford/go-apidiff v0.0.0-20191206194835-106bcff5f060
10-
github.com/onsi/ginkgo v1.11.0
10+
github.com/onsi/ginkgo v1.12.0
1111
github.com/raviqqe/liche v0.0.0-20200229003944-f57a5d1c5be4
12-
golang.org/x/tools v0.0.0-20200204192400-7124308813f3
12+
golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770
13+
honnef.co/go/tools v0.0.1-2020.1.4 // indirect
1314
k8s.io/code-generator v0.18.0
1415
sigs.k8s.io/controller-tools v0.2.9
1516
sigs.k8s.io/kubebuilder/docs/book/utils v0.0.0-20200226075303-ed8438ec10a4

0 commit comments

Comments
 (0)