Skip to content

Commit

Permalink
Check import order and formatting during linting (#121)
Browse files Browse the repository at this point in the history
* Check import sort order during linting and fix issues.

* Add `fix-lint` target

* Clean up trailing whitespace

* Enable `gofmt` linter too
  • Loading branch information
charleskorn authored Jan 17, 2024
1 parent d0f636b commit f638da6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
run:
build-tags:
- requires_docker

linters:
enable:
- gci
- gofmt

linters-settings:
errcheck:
# Use exclude-functions instead of exclude, since the GitHub Action's caching is broken.
# When changing the file referenced by exclude, the GitHub Action may use an older cache
# entry and ignore the changes in said file (thus breaking CI).
exclude-functions:
- (github.com/go-kit/log.Logger).Log

gci:
skip-generated: true
custom-order: true
sections:
- standard
- default
- prefix(github.com/grafana/rollout-operator)
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ rollout-operator: $(GO_FILES) ## Build the rollout-operator binary
rollout-operator-boringcrypto: $(GO_FILES) ## Build the rollout-operator binary with boringcrypto
GOEXPERIMENT=boringcrypto GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -tags netgo ./cmd/rollout-operator

.PHONY: build-image
.PHONY: build-image
build-image: clean ## Build the rollout-operator image
docker buildx build --load --platform linux/amd64 --build-arg revision=$(GIT_REVISION) -t rollout-operator:latest -t rollout-operator:$(IMAGE_TAG) .

.PHONY: build-image-boringcrypto
build-image-boringcrypto: clean ## Build the rollout-operator image with boringcrypto
build-image-boringcrypto: clean ## Build the rollout-operator image with boringcrypto
# Tags with the regular image repo for integration testing
docker buildx build --load --platform linux/amd64 --build-arg revision=$(GIT_REVISION) --build-arg BUILDTARGET=rollout-operator-boringcrypto -t rollout-operator:latest -t rollout-operator:$(IMAGE_TAG) .

Expand Down Expand Up @@ -66,6 +66,10 @@ integration/mock-service/.uptodate:
lint: ## Run golangci-lint
golangci-lint run --timeout=5m

.PHONY: fix-lint
fix-lint: ## Automatically fix linting issues where possible
golangci-lint run --timeout=5m --fix

.PHONY: clean
clean: ## Run go clean and remove the rollout-operator binary
rm -f rollout-operator
Expand Down
4 changes: 2 additions & 2 deletions cmd/rollout-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (
"go.uber.org/atomic"
v1 "k8s.io/api/admission/v1"
"k8s.io/client-go/kubernetes"
// Required to get the GCP auth provider working.
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

"github.com/grafana/rollout-operator/pkg/admission"
"github.com/grafana/rollout-operator/pkg/controller"
"github.com/grafana/rollout-operator/pkg/instrumentation"
"github.com/grafana/rollout-operator/pkg/tlscert"
// Required to get the GCP auth provider working.
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

const defaultServerSelfSignedCertExpiration = model.Duration(365 * 24 * time.Hour)
Expand Down
8 changes: 4 additions & 4 deletions pkg/admission/zone_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"github.com/go-kit/log/level"
"github.com/grafana/dskit/spanlogger"
"github.com/opentracing/opentracing-go"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/kubernetes"

"github.com/grafana/rollout-operator/pkg/config"
v1 "k8s.io/api/admission/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

"github.com/grafana/rollout-operator/pkg/config"
)

type zoneTracker struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/admission/zone_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"testing"
"time"

"github.com/grafana/rollout-operator/pkg/config"
apps "k8s.io/api/apps/v1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"

"github.com/grafana/rollout-operator/pkg/config"
)

func TestZoneTracker(t *testing.T) {
Expand Down

0 comments on commit f638da6

Please sign in to comment.