Skip to content

Commit 7819402

Browse files
authored
Add linter rule to organize imports into sections (#335)
1 parent 4b73694 commit 7819402

20 files changed

+95
-85
lines changed

.golangci.yml

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@ run:
22
deadline: 5m
33
allow-parallel-runners: true
44

5+
# Settings of specific linters
6+
linters-settings:
7+
gci:
8+
sections:
9+
- standard
10+
- default
11+
- prefix(github.com/project-codeflare/appwrapper)
12+
- blank
13+
- dot
14+
skip-generated: true # Skip generated files.
15+
16+
linters:
17+
disable-all: true
18+
enable:
19+
- copyloopvar
20+
- dupl
21+
- dupword
22+
- errcheck
23+
- gci
24+
- ginkgolinter
25+
- goconst
26+
- gocyclo
27+
- gofmt
28+
- goimports
29+
- gosimple
30+
- govet
31+
- ineffassign
32+
- lll
33+
- misspell
34+
- nakedret
35+
- prealloc
36+
- staticcheck
37+
- typecheck
38+
- unconvert
39+
- unparam
40+
- unused
41+
542
issues:
643
# don't skip warning about doc comments
744
# don't exclude the default set of lint
@@ -28,25 +65,3 @@ issues:
2865
- path: "pkg/*"
2966
linters:
3067
- lll
31-
linters:
32-
disable-all: true
33-
enable:
34-
- copyloopvar
35-
- dupl
36-
- errcheck
37-
- goconst
38-
- gocyclo
39-
- gofmt
40-
- goimports
41-
- gosimple
42-
- govet
43-
- ineffassign
44-
- lll
45-
- misspell
46-
- nakedret
47-
- prealloc
48-
- staticcheck
49-
- typecheck
50-
- unconvert
51-
- unparam
52-
- unused

cmd/main.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,16 @@ import (
2424
"os"
2525
"strings"
2626

27-
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
28-
// to ensure that exec-entrypoint and run can make use of them.
29-
_ "k8s.io/client-go/plugin/pkg/client/auth"
30-
3127
zaplog "go.uber.org/zap"
3228
"go.uber.org/zap/zapcore"
33-
"k8s.io/utils/ptr"
34-
3529
corev1 "k8s.io/api/core/v1"
3630
apierrors "k8s.io/apimachinery/pkg/api/errors"
3731
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3832
"k8s.io/apimachinery/pkg/runtime"
3933
"k8s.io/apimachinery/pkg/types"
4034
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
4135
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
36+
"k8s.io/utils/ptr"
4237
ctrl "sigs.k8s.io/controller-runtime"
4338
"sigs.k8s.io/controller-runtime/pkg/client"
4439
"sigs.k8s.io/controller-runtime/pkg/log/zap"
@@ -52,7 +47,10 @@ import (
5247
"github.com/project-codeflare/appwrapper/pkg/config"
5348
"github.com/project-codeflare/appwrapper/pkg/controller"
5449
"github.com/project-codeflare/appwrapper/pkg/logger"
55-
//+kubebuilder:scaffold:imports
50+
51+
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
52+
// to ensure that exec-entrypoint and run can make use of them.
53+
_ "k8s.io/client-go/plugin/pkg/client/auth"
5654
)
5755

5856
var (

internal/controller/appwrapper/appwrapper_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"k8s.io/apimachinery/pkg/types"
3434
"k8s.io/apimachinery/pkg/util/sets"
3535
"k8s.io/client-go/tools/record"
36-
3736
ctrl "sigs.k8s.io/controller-runtime"
3837
"sigs.k8s.io/controller-runtime/pkg/client"
3938
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

internal/controller/appwrapper/appwrapper_controller_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package appwrapper
1919
import (
2020
"time"
2121

22-
. "github.com/onsi/ginkgo/v2"
23-
. "github.com/onsi/gomega"
2422
v1 "k8s.io/api/core/v1"
2523
"k8s.io/apimachinery/pkg/api/meta"
2624
"k8s.io/apimachinery/pkg/api/resource"
@@ -33,6 +31,9 @@ import (
3331
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
3432
"github.com/project-codeflare/appwrapper/pkg/config"
3533
"github.com/project-codeflare/appwrapper/pkg/utils"
34+
35+
. "github.com/onsi/ginkgo/v2"
36+
. "github.com/onsi/gomega"
3637
)
3738

3839
var _ = Describe("AppWrapper Controller", func() {

internal/controller/appwrapper/fixtures_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"math/rand"
2222
"time"
2323

24-
. "github.com/onsi/gomega"
25-
2624
v1 "k8s.io/api/core/v1"
2725
"k8s.io/apimachinery/pkg/api/resource"
2826
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -33,6 +31,8 @@ import (
3331
"sigs.k8s.io/yaml"
3432

3533
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
34+
35+
. "github.com/onsi/gomega"
3636
)
3737

3838
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"

internal/controller/appwrapper/node_health_monitor.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"k8s.io/apimachinery/pkg/api/errors"
2626
"k8s.io/apimachinery/pkg/api/resource"
2727
"k8s.io/apimachinery/pkg/util/sets"
28-
2928
ctrl "sigs.k8s.io/controller-runtime"
3029
"sigs.k8s.io/controller-runtime/pkg/client"
3130
"sigs.k8s.io/controller-runtime/pkg/handler"

internal/controller/appwrapper/node_health_monitor_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ limitations under the License.
1717
package appwrapper
1818

1919
import (
20-
. "github.com/onsi/ginkgo/v2"
21-
. "github.com/onsi/gomega"
22-
"github.com/project-codeflare/appwrapper/pkg/config"
2320
v1 "k8s.io/api/core/v1"
2421
"k8s.io/apimachinery/pkg/api/resource"
2522
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2623
"k8s.io/apimachinery/pkg/types"
2724
"sigs.k8s.io/controller-runtime/pkg/reconcile"
25+
26+
"github.com/project-codeflare/appwrapper/pkg/config"
27+
28+
. "github.com/onsi/ginkgo/v2"
29+
. "github.com/onsi/gomega"
2830
)
2931

3032
var _ = Describe("NodeMonitor Controller", func() {
@@ -74,7 +76,7 @@ var _ = Describe("NodeMonitor Controller", func() {
7476
Expect(err).NotTo(HaveOccurred())
7577

7678
By("Healthy cluster has no unhealthy nodes")
77-
Expect(len(noExecuteNodes)).Should(Equal(0))
79+
Expect(noExecuteNodes).Should(BeEmpty())
7880

7981
By("A node labeled EVICT is detected as unhealthy")
8082
node := getNode(node1Name.Name)
@@ -84,7 +86,7 @@ var _ = Describe("NodeMonitor Controller", func() {
8486
Expect(err).NotTo(HaveOccurred())
8587
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node2Name})
8688
Expect(err).NotTo(HaveOccurred())
87-
Expect(len(noExecuteNodes)).Should(Equal(1))
89+
Expect(noExecuteNodes).Should(HaveLen(1))
8890
Expect(noExecuteNodes).Should(HaveKey(node1Name.Name))
8991
Expect(noExecuteNodes[node1Name.Name]).Should(HaveKey("nvidia.com/gpu"))
9092

@@ -93,7 +95,7 @@ var _ = Describe("NodeMonitor Controller", func() {
9395
Expect(err).NotTo(HaveOccurred())
9496
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node2Name})
9597
Expect(err).NotTo(HaveOccurred())
96-
Expect(len(noExecuteNodes)).Should(Equal(1))
98+
Expect(noExecuteNodes).Should(HaveLen(1))
9799
Expect(noExecuteNodes).Should(HaveKey(node1Name.Name))
98100
Expect(noExecuteNodes[node1Name.Name]).Should(HaveKey("nvidia.com/gpu"))
99101

@@ -102,7 +104,7 @@ var _ = Describe("NodeMonitor Controller", func() {
102104
Expect(k8sClient.Update(ctx, node)).Should(Succeed())
103105
_, err = nodeMonitor.Reconcile(ctx, reconcile.Request{NamespacedName: node1Name})
104106
Expect(err).NotTo(HaveOccurred())
105-
Expect(len(noExecuteNodes)).Should(Equal(0))
107+
Expect(noExecuteNodes).Should(BeEmpty())
106108

107109
deleteNode(node1Name.Name)
108110
deleteNode(node2Name.Name)

internal/controller/appwrapper/resource_management.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ import (
2222
"fmt"
2323
"time"
2424

25-
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
26-
utilmaps "github.com/project-codeflare/appwrapper/internal/util"
27-
"github.com/project-codeflare/appwrapper/pkg/utils"
2825
v1 "k8s.io/api/core/v1"
2926
apierrors "k8s.io/apimachinery/pkg/api/errors"
3027
"k8s.io/apimachinery/pkg/api/meta"
@@ -35,6 +32,10 @@ import (
3532
"sigs.k8s.io/controller-runtime/pkg/client"
3633
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3734
"sigs.k8s.io/controller-runtime/pkg/log"
35+
36+
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
37+
utilmaps "github.com/project-codeflare/appwrapper/internal/util"
38+
"github.com/project-codeflare/appwrapper/pkg/utils"
3839
)
3940

4041
func parseComponent(raw []byte, expectedNamespace string) (*unstructured.Unstructured, error) {

internal/controller/appwrapper/suite_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ import (
2323
"runtime"
2424
"testing"
2525

26-
. "github.com/onsi/ginkgo/v2"
27-
. "github.com/onsi/gomega"
28-
29-
//+kubebuilder:scaffold:imports
30-
3126
admissionv1 "k8s.io/api/admission/v1"
3227
rbacv1 "k8s.io/api/rbac/v1"
3328
apimachineryruntime "k8s.io/apimachinery/pkg/runtime"
@@ -39,6 +34,9 @@ import (
3934
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4035

4136
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
37+
38+
. "github.com/onsi/ginkgo/v2"
39+
. "github.com/onsi/gomega"
4240
)
4341

4442
// These tests use Ginkgo (BDD-style Go testing framework). Refer to

internal/webhook/appwrapper_fixtures_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ import (
2121
"math/rand"
2222
"time"
2323

24-
. "github.com/onsi/gomega"
25-
26-
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
2724
"k8s.io/apimachinery/pkg/api/resource"
2825
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2926
"k8s.io/apimachinery/pkg/runtime"
3027
"k8s.io/apimachinery/pkg/types"
3128
"k8s.io/utils/ptr"
3229
"sigs.k8s.io/yaml"
30+
31+
awv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
32+
33+
. "github.com/onsi/gomega"
3334
)
3435

3536
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"

0 commit comments

Comments
 (0)