Skip to content

Commit d890b97

Browse files
authored
standardized go import. (#457)
Signed-off-by: Morven Cao <lcao@redhat.com>
1 parent a22f895 commit d890b97

File tree

94 files changed

+226
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+226
-201
lines changed

.github/workflows/e2e.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ permissions:
1414
contents: read
1515

1616
jobs:
17+
verify:
18+
name: verify
19+
runs-on: ubuntu-22.04
20+
steps:
21+
- name: checkout code
22+
uses: actions/checkout@v4
23+
- name: install Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: ${{ env.GO_VERSION }}
27+
- name: verify
28+
run: make verify
1729
e2e:
1830
runs-on: ubuntu-22.04
1931
steps:

Makefile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ CGO_ENABLED := 1
66
# Enable users to override the golang used to accomodate custom installations
77
GO ?= go
88

9+
# Set GOPATH from go env if not already set
10+
GOPATH ?= $(shell $(GO) env GOPATH)
11+
export GOPATH
12+
913
# Allow overriding `oc` command.
1014
# Used by pr_check.py to ssh deploy inside private Hive cluster via bastion host.
1115
oc:=oc
@@ -156,15 +160,29 @@ ifndef TEST_SUMMARY_FORMAT
156160
TEST_SUMMARY_FORMAT=short-verbose
157161
endif
158162

159-
# Checks if a GOPATH is set, or emits an error message
163+
# Ensures GOPATH is set (now auto-configured at top of Makefile)
160164
check-gopath:
161-
ifndef GOPATH
162-
$(error GOPATH is not set)
163-
endif
165+
@echo "GOPATH is set to: $(GOPATH)"
164166
.PHONY: check-gopath
165167

168+
install-golang-gci:
169+
go install github.com/daixiang0/gci@v0.13.7
170+
171+
fmt-imports: install-golang-gci
172+
gci write --skip-generated -s standard -s default -s "prefix(github.com/openshift-online/maestro)" -s localmodule cmd pkg test
173+
174+
verify-fmt-imports: install-golang-gci
175+
@output=$$(gci diff --skip-generated -s standard -s default -s "prefix(github.com/openshift-online/maestro)" -s localmodule cmd pkg test); \
176+
if [ -n "$$output" ]; then \
177+
echo "Go import diff output is not empty: $$output"; \
178+
echo "Please run 'make fmt-imports' to format the golang files imports automatically."; \
179+
exit 1; \
180+
else \
181+
echo "Go import diff output is empty"; \
182+
fi
183+
166184
# Verifies that source passes standard checks.
167-
verify: check-gopath
185+
verify: check-gopath verify-fmt-imports
168186
${GO} vet \
169187
./cmd/... \
170188
./pkg/...

cmd/maestro/common/otlp_sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"time"
77

8+
errors "github.com/zgalor/weberr"
89
"go.opentelemetry.io/contrib/exporters/autoexport"
910
"go.opentelemetry.io/otel"
1011
"go.opentelemetry.io/otel/propagation"
@@ -14,7 +15,6 @@ import (
1415
"k8s.io/klog/v2"
1516

1617
"github.com/openshift-online/maestro/pkg/constants"
17-
errors "github.com/zgalor/weberr"
1818
)
1919

2020
// Without a specific configuration, a noop tracer is used by default.

cmd/maestro/environments/framework.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ import (
77
"strings"
88

99
"github.com/getsentry/sentry-go"
10-
"github.com/openshift-online/maestro/pkg/client/cloudevents"
11-
"github.com/openshift-online/maestro/pkg/client/grpcauthorizer"
12-
"github.com/openshift-online/maestro/pkg/client/ocm"
13-
"github.com/openshift-online/maestro/pkg/config"
14-
"github.com/openshift-online/maestro/pkg/errors"
1510
"github.com/spf13/pflag"
1611
"k8s.io/client-go/kubernetes"
1712
"k8s.io/client-go/rest"
1813
"k8s.io/client-go/tools/clientcmd"
1914
"k8s.io/klog/v2"
20-
21-
envtypes "github.com/openshift-online/maestro/cmd/maestro/environments/types"
2215
workpayload "open-cluster-management.io/sdk-go/pkg/cloudevents/clients/work/payload"
2316
"open-cluster-management.io/sdk-go/pkg/cloudevents/generic/options/builder"
17+
18+
envtypes "github.com/openshift-online/maestro/cmd/maestro/environments/types"
19+
"github.com/openshift-online/maestro/pkg/client/cloudevents"
20+
"github.com/openshift-online/maestro/pkg/client/grpcauthorizer"
21+
"github.com/openshift-online/maestro/pkg/client/ocm"
22+
"github.com/openshift-online/maestro/pkg/config"
23+
"github.com/openshift-online/maestro/pkg/errors"
2424
)
2525

2626
func init() {

cmd/maestro/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"log"
66
"os"
77

8+
"github.com/spf13/cobra"
9+
"k8s.io/klog/v2"
10+
811
"github.com/openshift-online/maestro/cmd/maestro/agent"
912
"github.com/openshift-online/maestro/cmd/maestro/migrate"
1013
"github.com/openshift-online/maestro/cmd/maestro/servecmd"
11-
"github.com/spf13/cobra"
12-
"k8s.io/klog/v2"
1314
)
1415

1516
// nolint

cmd/maestro/migrate/cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package migrate
22

33
import (
44
"context"
5-
"github.com/openshift-online/maestro/pkg/db/db_session"
5+
66
"github.com/spf13/cobra"
77
"k8s.io/klog/v2"
88

99
"github.com/openshift-online/maestro/pkg/config"
1010
"github.com/openshift-online/maestro/pkg/db"
11+
"github.com/openshift-online/maestro/pkg/db/db_session"
1112
)
1213

1314
var dbConfig = config.NewDatabaseConfig()

cmd/maestro/server/api_server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ import (
77
"net/http"
88
"time"
99

10-
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
11-
"k8s.io/klog/v2"
12-
1310
sentryhttp "github.com/getsentry/sentry-go/http"
1411
"github.com/ghodss/yaml"
1512
_ "github.com/golang-jwt/jwt/v4"
1613
"github.com/golang/glog"
1714
gorillahandlers "github.com/gorilla/handlers"
1815
sdk "github.com/openshift-online/ocm-sdk-go"
1916
"github.com/openshift-online/ocm-sdk-go/authentication"
17+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
18+
"k8s.io/klog/v2"
2019

2120
"github.com/openshift-online/maestro/cmd/maestro/common"
2221
"github.com/openshift-online/maestro/cmd/maestro/environments"

cmd/maestro/server/auth_interceptor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"fmt"
66
"strings"
77

8-
"github.com/openshift-online/maestro/pkg/client/grpcauthorizer"
98
"google.golang.org/grpc"
109
"google.golang.org/grpc/codes"
1110
"google.golang.org/grpc/credentials"
1211
"google.golang.org/grpc/metadata"
1312
"google.golang.org/grpc/peer"
1413
"google.golang.org/grpc/status"
1514
"k8s.io/klog/v2"
15+
16+
"github.com/openshift-online/maestro/pkg/client/grpcauthorizer"
1617
)
1718

1819
// Context key type defined to avoid collisions in other pkgs using context

cmd/maestro/server/controllers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package server
22

33
import (
44
"context"
5-
5+
66
"k8s.io/klog/v2"
77

88
"github.com/openshift-online/maestro/pkg/api"

cmd/maestro/server/event_server.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ import (
44
"context"
55
"fmt"
66

7+
"k8s.io/apimachinery/pkg/api/meta"
8+
"k8s.io/klog/v2"
9+
"open-cluster-management.io/sdk-go/pkg/cloudevents/clients/common"
10+
workpayload "open-cluster-management.io/sdk-go/pkg/cloudevents/clients/work/payload"
11+
"open-cluster-management.io/sdk-go/pkg/cloudevents/generic/types"
12+
sdkgologging "open-cluster-management.io/sdk-go/pkg/logging"
13+
714
"github.com/openshift-online/maestro/pkg/api"
815
"github.com/openshift-online/maestro/pkg/client/cloudevents"
916
"github.com/openshift-online/maestro/pkg/dao"
1017
"github.com/openshift-online/maestro/pkg/db"
1118
"github.com/openshift-online/maestro/pkg/dispatcher"
1219
"github.com/openshift-online/maestro/pkg/event"
1320
"github.com/openshift-online/maestro/pkg/services"
14-
"k8s.io/apimachinery/pkg/api/meta"
15-
"k8s.io/klog/v2"
16-
"open-cluster-management.io/sdk-go/pkg/cloudevents/clients/common"
17-
workpayload "open-cluster-management.io/sdk-go/pkg/cloudevents/clients/work/payload"
18-
"open-cluster-management.io/sdk-go/pkg/cloudevents/generic/types"
19-
sdkgologging "open-cluster-management.io/sdk-go/pkg/logging"
2021
)
2122

2223
// EventServer handles resource-related events:

0 commit comments

Comments
 (0)