diff --git a/.golangci.yaml b/.golangci.yaml index 705238d..422a473 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -25,6 +25,7 @@ linters: - errchkjson - errorlint - exhaustive + - gci - ginkgolinter - goconst - gocritic @@ -53,6 +54,18 @@ linters: - whitespace linters-settings: + gci: + custom-order: true + sections: + - standard + - default + - prefix(k8s.io,sigs.k8s.io) + - prefix(github.com/kcp-dev) + - prefix(github.com/multicluster-runtime) + - prefix(github.com/kcp-dev/multicluster-provider) + - blank + - dot + skip-generated: true govet: enable-all: true disable: diff --git a/Makefile b/Makefile index b3b21c3..0493cac 100644 --- a/Makefile +++ b/Makefile @@ -37,16 +37,6 @@ $(GOLANGCI_LINT): golangci-lint \ ${GOLANGCI_LINT_VERSION} -GIMPS = _tools/gimps -GIMPS_VERSION = 0.6.0 - -.PHONY: $(GIMPS) -$(GIMPS): - @hack/download-tool.sh \ - https://github.com/xrstf/gimps/releases/download/v${GIMPS_VERSION}/gimps_${GIMPS_VERSION}_${GOOS}_${GOARCH}.tar.gz \ - gimps \ - ${GIMPS_VERSION} - WWHRD = _tools/wwhrd WWHRD_VERSION = 0.4.0 @@ -100,8 +90,15 @@ lint: $(GOLANGCI_LINT) ./... .PHONY: imports -imports: $(GIMPS) - $(GIMPS) . +imports: WHAT ?= +imports: $(GOLANGCI_LINT) + @if [ -n "$(WHAT)" ]; then \ + $(GOLANGCI_LINT) run --enable-only=gci --fix --fast $(WHAT); \ + else \ + for MOD in . $$(git ls-files '**/go.mod' | sed 's,/go.mod,,'); do \ + (cd $$MOD; $(GOLANGCI_LINT) run --enable-only=gci --fix --fast); \ + done; \ + fi .PHONY: verify verify: diff --git a/virtualworkspace/cache.go b/virtualworkspace/cache.go index 8c2480b..864d994 100644 --- a/virtualworkspace/cache.go +++ b/virtualworkspace/cache.go @@ -22,12 +22,12 @@ import ( "fmt" "time" - "github.com/kcp-dev/logicalcluster/v3" - "k8s.io/apimachinery/pkg/runtime/schema" toolscache "k8s.io/client-go/tools/cache" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/kcp-dev/logicalcluster/v3" ) var _ cache.Cache = &scopedCache{} diff --git a/virtualworkspace/cluster.go b/virtualworkspace/cluster.go index 15342c7..90029ad 100644 --- a/virtualworkspace/cluster.go +++ b/virtualworkspace/cluster.go @@ -23,8 +23,6 @@ import ( "net/http" "net/url" - "github.com/kcp-dev/logicalcluster/v3" - "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" @@ -33,6 +31,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/apiutil" "sigs.k8s.io/controller-runtime/pkg/cluster" + + "github.com/kcp-dev/logicalcluster/v3" ) func newScopedCluster(cfg *rest.Config, clusterName logicalcluster.Name, wildcardCA WildcardCache, scheme *runtime.Scheme) (*scopedCluster, error) { diff --git a/virtualworkspace/forked_cache_reader.go b/virtualworkspace/forked_cache_reader.go index 17c5be6..3cadd84 100644 --- a/virtualworkspace/forked_cache_reader.go +++ b/virtualworkspace/forked_cache_reader.go @@ -24,9 +24,6 @@ import ( "fmt" "reflect" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" - apierrors "k8s.io/apimachinery/pkg/api/errors" apimeta "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/fields" @@ -36,6 +33,9 @@ import ( "k8s.io/apimachinery/pkg/selection" "k8s.io/client-go/tools/cache" "sigs.k8s.io/controller-runtime/pkg/client" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" ) // cacheReader is a client.Reader. diff --git a/virtualworkspace/indexes.go b/virtualworkspace/indexes.go index 8cfeacd..114c73f 100644 --- a/virtualworkspace/indexes.go +++ b/virtualworkspace/indexes.go @@ -19,9 +19,9 @@ package virtualworkspace import ( "fmt" - "github.com/kcp-dev/logicalcluster/v3" - "k8s.io/apimachinery/pkg/api/meta" + + "github.com/kcp-dev/logicalcluster/v3" ) // ClusterIndexFunc indexes by cluster name. diff --git a/virtualworkspace/indexes_test.go b/virtualworkspace/indexes_test.go index 4504e9a..381f5ba 100644 --- a/virtualworkspace/indexes_test.go +++ b/virtualworkspace/indexes_test.go @@ -19,10 +19,11 @@ package virtualworkspace import ( "testing" - "github.com/kcp-dev/logicalcluster/v3" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/kcp-dev/logicalcluster/v3" ) func TestClusterIndexFunc(t *testing.T) { diff --git a/virtualworkspace/provider.go b/virtualworkspace/provider.go index bf6ba32..eaa3985 100644 --- a/virtualworkspace/provider.go +++ b/virtualworkspace/provider.go @@ -23,13 +23,8 @@ import ( "time" "github.com/go-logr/logr" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" "golang.org/x/sync/errgroup" - mcmanager "github.com/multicluster-runtime/multicluster-runtime/pkg/manager" - "github.com/multicluster-runtime/multicluster-runtime/pkg/multicluster" - "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" @@ -39,6 +34,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/cluster" "sigs.k8s.io/controller-runtime/pkg/log" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + mcmanager "github.com/multicluster-runtime/multicluster-runtime/pkg/manager" + "github.com/multicluster-runtime/multicluster-runtime/pkg/multicluster" ) var _ multicluster.Provider = &Provider{} diff --git a/virtualworkspace/wildcard.go b/virtualworkspace/wildcard.go index 89ea34f..9f3eb27 100644 --- a/virtualworkspace/wildcard.go +++ b/virtualworkspace/wildcard.go @@ -23,10 +23,6 @@ import ( "sync" "time" - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - apimeta "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -38,6 +34,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/apiutil" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + "github.com/kcp-dev/logicalcluster/v3" ) // WildcardCache is a cache that operates on a /clusters/* endpoint.