Skip to content

🌱 Update golint-ci, fix warnings #3120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ linters:
- gocognit
- gomnd
- interfacer
- godot
- goerr113
- nestif
# Run with --fast=false for more extensive checks
fast: true
issues:
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ type Proxy interface {
}

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

i := 0
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/cluster/objectgraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ func getDetachedObjectGraphWihObjs(objs []runtime.Object) (*objectGraph, error)
graph := newObjectGraph(nil) // detached from any cluster
for _, o := range objs {
u := &unstructured.Unstructured{}
if err := test.FakeScheme.Convert(o, u, nil); err != nil { //nolint
if err := test.FakeScheme.Convert(o, u, nil); err != nil {
return nil, errors.Wrap(err, "failed to convert object in unstructured")
}
graph.addObj(u)
Expand Down
10 changes: 5 additions & 5 deletions cmd/clusterctl/client/cluster/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestProxyGetConfig(t *testing.T) {
g.Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(dir)
configFile := filepath.Join(dir, ".test-kubeconfig.yaml")
g.Expect(ioutil.WriteFile(configFile, []byte(tt.kubeconfigContents), 0640)).To(Succeed())
g.Expect(ioutil.WriteFile(configFile, []byte(tt.kubeconfigContents), 0600)).To(Succeed())

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

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

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

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

proxy := newProxy(Kubeconfig{Path: configFile, Context: tt.kubeconfigContext})
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/cluster/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func Test_templateClient_getLocalFileContent(t *testing.T) {
defer os.RemoveAll(tmpDir)

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

type args struct {
rURL *url.URL
Expand Down Expand Up @@ -302,7 +302,7 @@ func Test_templateClient_GetFromURL(t *testing.T) {
})

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

type args struct {
templateURL string
Expand Down
10 changes: 5 additions & 5 deletions cmd/clusterctl/client/config/reader_viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func Test_viperReader_Init(t *testing.T) {
defer os.RemoveAll(dir)

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

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

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

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

type args struct {
key string
Expand Down Expand Up @@ -185,7 +185,7 @@ func Test_viperReader_Set(t *testing.T) {

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

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

type args struct {
key string
Expand Down Expand Up @@ -230,7 +230,7 @@ func Test_viperReader_checkDefaultConfig(t *testing.T) {
dir = strings.TrimSuffix(dir, "/")

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

type fields struct {
configPaths []string
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
defer os.RemoveAll(tmpDir)

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

// Template on a repository & in a ConfigMap
configMap := &corev1.ConfigMap{
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/repository/repository_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (g *gitHubRepository) downloadFilesFromRelease(release *github.RepositoryRe
return nil, g.handleGithubErr(err, "failed to download file %q from %q release", *release.TagName, fileName)
}
if redirect != "" {
response, err := http.Get(redirect) //nolint:bodyclose (NB: The reader is actually closed in a defer)
response, err := http.Get(redirect) //nolint:bodyclose // (NB: The reader is actually closed in a defer)
if err != nil {
return nil, errors.Wrapf(err, "failed to download file %q from %q release via redirect location %q", *release.TagName, fileName, redirect)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/client/repository/repository_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func createLocalTestProviderFile(t *testing.T, tmpDir, path, msg string) string
dst := filepath.Join(tmpDir, path)
// Create all directories in the standard layout
g.Expect(os.MkdirAll(filepath.Dir(dst), 0755)).To(Succeed())
g.Expect(ioutil.WriteFile(dst, []byte(msg), 0644)).To(Succeed())
g.Expect(ioutil.WriteFile(dst, []byte(msg), 0600)).To(Succeed())

return dst
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/cmd/config_repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Test_runGetRepositories(t *testing.T) {
defer os.RemoveAll(tmpDir)

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

buf := bytes.NewBufferString("")

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

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

buf := bytes.NewBufferString("")
g.Expect(runGetRepositories(path, buf)).ToNot(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/cmd/upgrade_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func runUpgradePlan() error {
if upgradeAvailable {
fmt.Println("You can now apply the upgrade by executing the following command:")
fmt.Println("")
fmt.Println(fmt.Sprintf(" upgrade apply --management-group %s --contract %s", plan.CoreProvider.InstanceName(), plan.Contract))
fmt.Printf(" upgrade apply --management-group %s --contract %s\n", plan.CoreProvider.InstanceName(), plan.Contract)
} else {
fmt.Println("You are already up to date!")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterctl/internal/util/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func JoinYaml(yamls ...[]byte) []byte {

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

reader := utilyaml.NewYAMLReader(bufio.NewReader(bytes.NewReader(rawyaml)))
count := 1
Expand Down
4 changes: 2 additions & 2 deletions controllers/mdutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func getIntFromAnnotation(ms *clusterv1.MachineSet, annotationKey string, logger
if !ok {
return int32(0), false
}
intValue, err := strconv.Atoi(annotationValue)
intValue, err := strconv.ParseInt(annotationValue, 10, 32)
if err != nil {
logger.V(2).Info("Cannot convert the value to integer", "annotationValue", annotationValue)
return int32(0), false
Expand Down Expand Up @@ -563,7 +563,7 @@ func IsSaturated(deployment *clusterv1.MachineDeployment, ms *clusterv1.MachineS
return false
}
desiredString := ms.Annotations[clusterv1.DesiredReplicasAnnotation]
desired, err := strconv.Atoi(desiredString)
desired, err := strconv.ParseInt(desiredString, 10, 32)
if err != nil {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
"test0": &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Namespace: cluster.Namespace,
Name: fmt.Sprintf("test0"),
Name: "test0",
Labels: internal.ControlPlaneLabelsForCluster(cluster.Name),
},
Spec: clusterv1.MachineSpec{
Expand Down
6 changes: 2 additions & 4 deletions controlplane/kubeadm/internal/machine_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ func NewFilterableMachineCollection(machines ...*clusterv1.Machine) FilterableMa
// NewFilterableMachineCollectionFromMachineList creates a FilterableMachineCollection from the given MachineList
func NewFilterableMachineCollectionFromMachineList(machineList *clusterv1.MachineList) FilterableMachineCollection {
ss := make(FilterableMachineCollection, len(machineList.Items))
if machineList != nil {
for i := range machineList.Items {
ss.Insert(&machineList.Items[i])
}
for i := range machineList.Items {
ss.Insert(&machineList.Items[i])
}
return ss
}
Expand Down
7 changes: 4 additions & 3 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ go 1.13
require (
github.com/blang/semver v3.5.1+incompatible
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/golangci/golangci-lint v1.23.8
github.com/golangci/golangci-lint v1.27.0
github.com/joelanford/go-apidiff v0.0.0-20191206194835-106bcff5f060
github.com/onsi/ginkgo v1.11.0
github.com/onsi/ginkgo v1.12.0
github.com/raviqqe/liche v0.0.0-20200229003944-f57a5d1c5be4
golang.org/x/tools v0.0.0-20200204192400-7124308813f3
golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770
honnef.co/go/tools v0.0.1-2020.1.4 // indirect
k8s.io/code-generator v0.18.0
sigs.k8s.io/controller-tools v0.2.9
sigs.k8s.io/kubebuilder/docs/book/utils v0.0.0-20200226075303-ed8438ec10a4
Expand Down
Loading