Skip to content

Commit d164ea4

Browse files
authored
Upgrade golangci-lint v1 to v2 (#714)
Signed-off-by: Yuki Iwai <[email protected]>
1 parent 375e1fa commit d164ea4

File tree

8 files changed

+752
-82
lines changed

8 files changed

+752
-82
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ SCHEDULER_PLUGINS_VERSION?=$(shell go list -m -f "{{.Version}}" sigs.k8s.io/sche
4242
VOLCANO_SCHEDULER_VERSION?=$(shell go list -m -f "{{.Version}}" volcano.sh/apis)
4343
GOTOOLS_VERSION?=$(shell go list -m -f "{{.Version}}" golang.org/x/tools)
4444
KIND_VERSION?=$(shell go list -m -f "{{.Version}}" sigs.k8s.io/kind)
45+
GOLANGCI_LINT_VERSION?=$(shell go list -m -f "{{.Version}}" github.com/golangci/golangci-lint/v2)
4546

4647
CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true"
4748

@@ -151,7 +152,7 @@ bin:
151152
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
152153
.PHONY: bin/golangci-lint
153154
bin/golangci-lint: bin
154-
@GOBIN=$(PROJECT_DIR)/bin go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8
155+
@GOBIN=$(PROJECT_DIR)/bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
155156

156157
ENVTEST = $(shell pwd)/bin/setup-envtest
157158
.PHONY: envtest

go.mod

Lines changed: 203 additions & 18 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 514 additions & 40 deletions
Large diffs are not rendered by default.

hack/python-sdk/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ func main() {
7272
}
7373

7474
func swaggify(name string) string {
75-
name = strings.Replace(name, "github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/", "", -1)
76-
name = strings.Replace(name, "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/", "", -1)
77-
name = strings.Replace(name, "k8s.io/api/core/", "", -1)
78-
name = strings.Replace(name, "k8s.io/apimachinery/pkg/apis/meta/", "", -1)
79-
name = strings.Replace(name, "k8s.io/apimachinery/pkg/runtime/", "", -1)
80-
name = strings.Replace(name, "k8s.io/apimachinery/pkg/api/", "", -1)
81-
name = strings.Replace(name, "k8s.io/kubernetes/pkg/controller/", "", -1)
82-
name = strings.Replace(name, "k8s.io/client-go/listers/core/", "", -1)
83-
name = strings.Replace(name, "k8s.io/client-go/util/workqueue", "", -1)
84-
name = strings.Replace(name, "/", ".", -1)
75+
name = strings.ReplaceAll(name, "github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/", "")
76+
name = strings.ReplaceAll(name, "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/", "")
77+
name = strings.ReplaceAll(name, "k8s.io/api/core/", "")
78+
name = strings.ReplaceAll(name, "k8s.io/apimachinery/pkg/apis/meta/", "")
79+
name = strings.ReplaceAll(name, "k8s.io/apimachinery/pkg/runtime/", "")
80+
name = strings.ReplaceAll(name, "k8s.io/apimachinery/pkg/api/", "")
81+
name = strings.ReplaceAll(name, "k8s.io/kubernetes/pkg/controller/", "")
82+
name = strings.ReplaceAll(name, "k8s.io/client-go/listers/core/", "")
83+
name = strings.ReplaceAll(name, "k8s.io/client-go/util/workqueue", "")
84+
name = strings.ReplaceAll(name, "/", ".")
8585
return name
8686
}

hack/tools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package tools
1818

1919
import (
20+
_ "github.com/golangci/golangci-lint/v2/cmd/golangci-lint"
2021
_ "golang.org/x/tools/cmd/goimports"
2122
_ "k8s.io/code-generator/cmd/client-gen"
2223
_ "k8s.io/code-generator/cmd/deepcopy-gen"

pkg/apis/kubeflow/validation/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func validateMPIJobName(job *kubeflow.MPIJob) field.ErrorList {
6262
}
6363
maximumPodHostname := fmt.Sprintf("%s-worker-%d", job.Name, replicas-1)
6464
if errs := apimachineryvalidation.IsDNS1035Label(maximumPodHostname); len(errs) > 0 {
65-
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), job.ObjectMeta.Name, fmt.Sprintf("will not able to create pod and service with invalid DNS label %q: %s", maximumPodHostname, strings.Join(errs, ", "))))
65+
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), job.Name, fmt.Sprintf("will not able to create pod and service with invalid DNS label %q: %s", maximumPodHostname, strings.Join(errs, ", "))))
6666
}
6767
return allErrs
6868
}

pkg/controller/mpi_job_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (f *fixture) runController(ctx context.Context, mpiJobName string, startInf
330330
// checkAction verifies that expected and actual actions are equal and both have
331331
// same attached resources
332332
func checkAction(expected, actual core.Action, t *testing.T) {
333-
if !(expected.Matches(actual.GetVerb(), actual.GetResource().Resource) && actual.GetSubresource() == expected.GetSubresource()) {
333+
if !expected.Matches(actual.GetVerb(), actual.GetResource().Resource) || actual.GetSubresource() != expected.GetSubresource() {
334334
t.Errorf("Expected\n\t%#v\ngot\n\t%#v", expected, actual)
335335
return
336336
}

test/e2e/mpi_job_test.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,10 @@ func waitForCompletion(ctx context.Context, mpiJob *kubeflow.MPIJob) *kubeflow.M
563563
return mpiJob.Status.CompletionTime != nil, nil
564564
})
565565
if err != nil {
566-
err := debugJob(ctx, mpiJob)
566+
err = debugJob(ctx, mpiJob)
567567
if err != nil {
568-
fmt.Fprintf(ginkgo.GinkgoWriter, "Failed to debug job: %v\n", err)
568+
_, err = fmt.Fprintf(ginkgo.GinkgoWriter, "Failed to debug job: %v\n", err)
569+
gomega.Expect(err).ToNot(gomega.HaveOccurred())
569570
}
570571
}
571572
gomega.Expect(err).ToNot(gomega.HaveOccurred())
@@ -650,20 +651,28 @@ func debugJob(ctx context.Context, mpiJob *kubeflow.MPIJob) error {
650651
return nil
651652
}
652653

653-
func podLogs(ctx context.Context, p *corev1.Pod) error {
654+
func podLogs(ctx context.Context, p *corev1.Pod) (err error) {
654655
req := k8sClient.CoreV1().Pods(p.Namespace).GetLogs(p.Name, &corev1.PodLogOptions{})
655-
stream, err := req.Stream(ctx)
656-
if err != nil {
657-
return fmt.Errorf("reading logs: %v", err)
656+
stream, streamErr := req.Stream(ctx)
657+
if streamErr != nil {
658+
err = fmt.Errorf("reading logs: %v", streamErr)
659+
return
660+
}
661+
defer func() {
662+
err = stream.Close()
663+
}()
664+
if _, err = fmt.Fprintf(ginkgo.GinkgoWriter, "== BEGIN %s pod logs ==\n", p.Name); err != nil {
665+
return
658666
}
659-
defer stream.Close()
660-
fmt.Fprintf(ginkgo.GinkgoWriter, "== BEGIN %s pod logs ==\n", p.Name)
661667
_, err = io.Copy(ginkgo.GinkgoWriter, stream)
662668
if err != nil {
663-
return fmt.Errorf("writing logs: %v", err)
669+
err = fmt.Errorf("writing logs: %v", err)
670+
return
664671
}
665-
fmt.Fprintf(ginkgo.GinkgoWriter, "\n== END %s pod logs ==\n", p.Name)
666-
return nil
672+
if _, err = fmt.Fprintf(ginkgo.GinkgoWriter, "\n== END %s pod logs ==\n", p.Name); err != nil {
673+
return
674+
}
675+
return
667676
}
668677

669678
func expectConditionToBeTrue(mpiJob *kubeflow.MPIJob, condType kubeflow.JobConditionType) {

0 commit comments

Comments
 (0)