Skip to content

Commit

Permalink
🌱 add a verify rule for golang files import order (#177)
Browse files Browse the repository at this point in the history
* 🌱 add a verify rule for golang files import order

This PR uses the [gci tool](https://github.com/daixiang0/gci) to make all go files' import section with a specific order, it will organize import with group with order:
1. standard library modules
2. 3rd party modules
3. modules in OCM org, like the `open-cluster-management.io/api`
4. current project `open-cluster-management.io/ocm` modules

developers can use the `make fmt-imports` to format the import automatically and the `make verify-fmt-imports` to check for any violation.

Signed-off-by: zhujian <jiazhu@redhat.com>

* 🌱 format the go files import

Signed-off-by: zhujian <jiazhu@redhat.com>

---------

Signed-off-by: zhujian <jiazhu@redhat.com>
  • Loading branch information
zhujian7 authored Jun 12, 2023
1 parent 3c9bfea commit 7332a58
Show file tree
Hide file tree
Showing 266 changed files with 815 additions and 583 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/pre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,10 @@ jobs:
go-version: ${{ env.GO_VERSION }}
- name: verify
run: make verify

verify-deps:
name: verify-deps
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v3
- name: install Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: verify-deps
run: make verify-deps
- name: verify-fmt-imports
run: make verify-fmt-imports

build:
name: build
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ verify-gocilint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
golangci-lint run --timeout=3m --modules-download-mode vendor ./...

install-golang-gci:
go install github.com/daixiang0/gci@v0.10.1

fmt-imports: install-golang-gci
gci write --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s "prefix(open-cluster-management.io/ocm)" cmd pkg test dependencymagnet

verify-fmt-imports: install-golang-gci
@output=$$(gci diff --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s "prefix(open-cluster-management.io/ocm)" cmd pkg test dependencymagnet); \
if [ -n "$$output" ]; then \
echo "Diff output is not empty: $$output"; \
exit 1; \
else \
echo "Diff output is empty"; \
fi

verify: verify-crds

ensure-operator-sdk:
Expand Down
3 changes: 1 addition & 2 deletions cmd/placement/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import (
goflag "flag"
"fmt"
"math/rand"
"open-cluster-management.io/ocm/pkg/cmd/hub"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"

"open-cluster-management.io/ocm/pkg/cmd/hub"
"open-cluster-management.io/ocm/pkg/version"
)

Expand Down
5 changes: 2 additions & 3 deletions cmd/registration-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import (
goflag "flag"
"fmt"
"math/rand"
"open-cluster-management.io/ocm/pkg/cmd/hub"
"open-cluster-management.io/ocm/pkg/cmd/spoke"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"

"open-cluster-management.io/ocm/pkg/cmd/hub"
"open-cluster-management.io/ocm/pkg/cmd/spoke"
"open-cluster-management.io/ocm/pkg/version"
)

Expand Down
5 changes: 2 additions & 3 deletions cmd/registration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import (
goflag "flag"
"fmt"
"math/rand"
"open-cluster-management.io/ocm/pkg/cmd/hub"
"open-cluster-management.io/ocm/pkg/cmd/spoke"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"

"open-cluster-management.io/ocm/pkg/cmd/hub"
"open-cluster-management.io/ocm/pkg/cmd/spoke"
"open-cluster-management.io/ocm/pkg/cmd/webhook"
"open-cluster-management.io/ocm/pkg/version"
)
Expand Down
5 changes: 2 additions & 3 deletions cmd/work/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import (
goflag "flag"
"fmt"
"math/rand"
"open-cluster-management.io/ocm/pkg/cmd/hub"
"open-cluster-management.io/ocm/pkg/cmd/spoke"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"

"open-cluster-management.io/ocm/pkg/cmd/hub"
"open-cluster-management.io/ocm/pkg/cmd/spoke"
"open-cluster-management.io/ocm/pkg/cmd/webhook"
"open-cluster-management.io/ocm/pkg/version"
)
Expand Down
1 change: 1 addition & 0 deletions dependencymagnet/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package dependencymagnet

import (
_ "github.com/openshift/build-machinery-go"

_ "open-cluster-management.io/api/addon/v1alpha1"
_ "open-cluster-management.io/api/cluster/v1"
_ "open-cluster-management.io/api/cluster/v1alpha1"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/hub/operator.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package hub

import (
"github.com/spf13/cobra"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/spf13/cobra"

"open-cluster-management.io/ocm/pkg/operator/operators/clustermanager"
"open-cluster-management.io/ocm/pkg/version"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/hub/placement.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package hub

import (
"github.com/spf13/cobra"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/spf13/cobra"

controllers "open-cluster-management.io/ocm/pkg/placement/controllers"
"open-cluster-management.io/ocm/pkg/version"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/hub/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package hub
import (
"time"

"github.com/spf13/cobra"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/spf13/cobra"

"open-cluster-management.io/ocm/pkg/registration/hub"
"open-cluster-management.io/ocm/pkg/version"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/hub/work.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package hub

import (
"github.com/spf13/cobra"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/spf13/cobra"

"open-cluster-management.io/ocm/pkg/version"
"open-cluster-management.io/ocm/pkg/work/hub"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/spoke/operator.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package spoke

import (
"github.com/spf13/cobra"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/spf13/cobra"

"open-cluster-management.io/ocm/pkg/operator/operators/klusterlet"
"open-cluster-management.io/ocm/pkg/version"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/spoke/registration.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package spoke

import (
"github.com/spf13/cobra"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/spf13/cobra"

"open-cluster-management.io/ocm/pkg/registration/spoke"
"open-cluster-management.io/ocm/pkg/version"
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/spoke/work.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package spoke

import (
"github.com/spf13/cobra"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/spf13/cobra"

"open-cluster-management.io/ocm/pkg/version"
"open-cluster-management.io/ocm/pkg/work/spoke"
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/webhook/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webhook

import (
"github.com/spf13/cobra"

"open-cluster-management.io/ocm/pkg/features"
"open-cluster-management.io/ocm/pkg/registration/webhook"
)
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/webhook/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webhook

import (
"github.com/spf13/cobra"

"open-cluster-management.io/ocm/pkg/features"
_ "open-cluster-management.io/ocm/pkg/features"
"open-cluster-management.io/ocm/pkg/work/webhook"
Expand Down
3 changes: 2 additions & 1 deletion pkg/common/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package options

import (
"fmt"
"strings"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/spf13/pflag"
apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"strings"
)

// AgentOptions is the common agent options
Expand Down
1 change: 1 addition & 0 deletions pkg/common/patcher/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"

jsonpatch "github.com/evanphx/json-patch"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down
5 changes: 4 additions & 1 deletion pkg/common/patcher/patcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package patcher
import (
"context"
"encoding/json"
"testing"

"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clienttesting "k8s.io/client-go/testing"

clusterfake "open-cluster-management.io/api/client/cluster/clientset/versioned/fake"
clusterv1 "open-cluster-management.io/api/cluster/v1"

testingcommon "open-cluster-management.io/ocm/pkg/common/testing"
testinghelpers "open-cluster-management.io/ocm/pkg/registration/helpers/testing"
"testing"
)

func TestAddFinalizer(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/common/testing/assertion.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package testing

import (
"strings"
"testing"

"github.com/davecgh/go-spew/spew"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
clienttesting "k8s.io/client-go/testing"
"strings"
"testing"
)

// AssertError asserts the actual error representation is the same with the expected,
Expand Down
3 changes: 2 additions & 1 deletion pkg/common/testing/fake_sync_context.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package testing

import (
"testing"

"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/events/eventstesting"
"k8s.io/client-go/util/workqueue"
"testing"
)

type FakeSyncContext struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/features/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package features
import (
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/component-base/featuregate"

ocmfeature "open-cluster-management.io/api/feature"
)

Expand Down
7 changes: 3 additions & 4 deletions pkg/operator/certrotation/cabundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import (
"fmt"
"reflect"

"github.com/openshift/library-go/pkg/crypto"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/util/cert"

"github.com/openshift/library-go/pkg/crypto"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
)

// CABundleRotation maintains a CA bundle config map, but adding new CA certs and removing expired old ones.
Expand Down
9 changes: 4 additions & 5 deletions pkg/operator/certrotation/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (
"fmt"
"time"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/openshift/library-go/pkg/certs"
"github.com/openshift/library-go/pkg/crypto"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/util/cert"
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/klog/v2"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
apiregistrationclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/typed/apiregistration/v1"

operatorv1client "open-cluster-management.io/api/client/operator/clientset/versioned/typed/operator/v1"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
)
Expand Down
7 changes: 4 additions & 3 deletions pkg/operator/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import (
"testing"
"time"

"k8s.io/component-base/featuregate"
ocmfeature "open-cluster-management.io/api/feature"

"github.com/google/go-cmp/cmp"
"github.com/openshift/library-go/pkg/assets"
"github.com/openshift/library-go/pkg/operator/events"
Expand All @@ -33,9 +30,13 @@ import (
clienttesting "k8s.io/client-go/testing"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
clientcmdlatest "k8s.io/client-go/tools/clientcmd/api/latest"
"k8s.io/component-base/featuregate"
fakeapiregistration "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/fake"

opereatorfake "open-cluster-management.io/api/client/operator/clientset/versioned/fake"
ocmfeature "open-cluster-management.io/api/feature"
operatorapiv1 "open-cluster-management.io/api/operator/v1"

"open-cluster-management.io/ocm/manifests"
)

Expand Down
3 changes: 1 addition & 2 deletions pkg/operator/helpers/queuekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"fmt"
"strings"

"github.com/openshift/library-go/pkg/controller/factory"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"

"github.com/openshift/library-go/pkg/controller/factory"

operatorlister "open-cluster-management.io/api/client/operator/listers/operator/v1"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/helpers/testing/assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

opratorapiv1 "open-cluster-management.io/api/operator/v1"

"open-cluster-management.io/ocm/pkg/operator/helpers"
)

Expand Down
Loading

0 comments on commit 7332a58

Please sign in to comment.