Skip to content

Commit

Permalink
enable importas and stylecheck linters
Browse files Browse the repository at this point in the history
Prior to this commit is was possible for double imports to accidentally go
unnoticed.

This commit enables the `stylecheck` linter, which catches double imports as
well as other minor style issues; enables `importas`, to enforce consistent
importing of kubernetes' "versioned" packages; and corrects any discovered
issues.
  • Loading branch information
chrisseto committed Nov 25, 2024
1 parent 06312d2 commit f888ad1
Show file tree
Hide file tree
Showing 87 changed files with 319 additions and 235 deletions.
15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,30 @@ linters:
- gosec
- gosimple
- govet
- importas
- ineffassign
- misspell
- staticcheck
- stylecheck
- unused

linters-settings:
goimports:
local-prefixes: github.com/redpanda-data/redpanda-operator,github.com/redpanda-data/helm-charts

gosec:
excludes:
- G115 # integer overflows aren't super likely to be a problem for us and we're really just at the mercy of the APIs we use.

config:
G306: "0644" # Maximum allowed os.WriteFile Permissions

importas:
alias:
- pkg: k8s.io/api/(\w+)/(v\d)
alias: $1$2
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1

stylecheck:
checks: ["*", "-ST1005"]
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ tasks:
cmds:
# NB: go list -f takes a go template string, It needs to be escaped in
# taskfile land to get properly passed to go list.
- golangci-lint run $(go list -f '{{"{{.Dir}}"}}/...' -m) {{.ARGS}}
- golangci-lint run $(go list -f '{{"{{.Dir}}"}}/...' -m) {{.CLI_ARGS}}

lint-fix:
cmds:
- task: lint
vars:
ARGS: "--fix"
CLI_ARGS: "--fix"

fmt:
cmds:
Expand Down
5 changes: 3 additions & 2 deletions acceptance/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import (
"testing"

"github.com/go-logr/logr"
"github.com/stretchr/testify/require"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/redpanda-data/helm-charts/pkg/helm"
_ "github.com/redpanda-data/redpanda-operator/acceptance/steps"
framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha1 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha1"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
"github.com/stretchr/testify/require"
"sigs.k8s.io/controller-runtime/pkg/log"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions acceptance/steps/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
"context"
"time"

framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
)

func checkClusterAvailability(ctx context.Context, t framework.TestingT, clusterName string) {
Expand Down
13 changes: 7 additions & 6 deletions acceptance/steps/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ import (

"github.com/cucumber/godog"
"github.com/redpanda-data/common-go/rpadmin"
"github.com/redpanda-data/helm-charts/pkg/kube"
framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
"github.com/redpanda-data/redpanda-operator/operator/pkg/client"
"github.com/redpanda-data/redpanda-operator/operator/pkg/client/acls"
"github.com/redpanda-data/redpanda-operator/operator/pkg/client/users"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/twmb/franz-go/pkg/kadm"
Expand All @@ -34,6 +28,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/redpanda-data/helm-charts/pkg/kube"
framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
"github.com/redpanda-data/redpanda-operator/operator/pkg/client"
"github.com/redpanda-data/redpanda-operator/operator/pkg/client/acls"
"github.com/redpanda-data/redpanda-operator/operator/pkg/client/users"
)

type clusterClients struct {
Expand Down
3 changes: 2 additions & 1 deletion acceptance/steps/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"os"

"github.com/cucumber/godog"
framework "github.com/redpanda-data/redpanda-operator/harpoon"
"github.com/stretchr/testify/require"

framework "github.com/redpanda-data/redpanda-operator/harpoon"
)

func iApplyKubernetesManifest(ctx context.Context, t framework.TestingT, manifest *godog.DocString) {
Expand Down
5 changes: 3 additions & 2 deletions acceptance/steps/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ package steps
import (
"context"

framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
)

func schemaIsSuccessfullySynced(ctx context.Context, t framework.TestingT, schema string) {
Expand Down
5 changes: 3 additions & 2 deletions acceptance/steps/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ package steps
import (
"context"

framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
"github.com/stretchr/testify/require"
"github.com/twmb/franz-go/pkg/kgo"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
)

func topicIsSuccessfullySynced(ctx context.Context, t framework.TestingT, topic string) {
Expand Down
7 changes: 4 additions & 3 deletions acceptance/steps/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"fmt"

"github.com/cucumber/godog"
framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
"github.com/redpanda-data/redpanda-operator/operator/pkg/client"
"github.com/stretchr/testify/require"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

framework "github.com/redpanda-data/redpanda-operator/harpoon"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
"github.com/redpanda-data/redpanda-operator/operator/pkg/client"
)

func userIsSuccessfullySynced(ctx context.Context, t framework.TestingT, user string) {
Expand Down
3 changes: 2 additions & 1 deletion harpoon/internal/testing/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ package testing
import (
"context"

"github.com/redpanda-data/helm-charts/pkg/helm"
"github.com/stretchr/testify/require"
"k8s.io/client-go/rest"

"github.com/redpanda-data/helm-charts/pkg/helm"
)

func (t *TestingT) InstallHelmChart(ctx context.Context, url, repo, chart string, options helm.InstallOptions) {
Expand Down
1 change: 1 addition & 0 deletions harpoon/internal/tracking/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cucumber/godog"
"github.com/cucumber/godog/formatters"
messages "github.com/cucumber/messages/go/v21"

internaltesting "github.com/redpanda-data/redpanda-operator/harpoon/internal/testing"
)

Expand Down
1 change: 1 addition & 0 deletions harpoon/internal/tracking/scenarios.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"sync"

"github.com/cucumber/godog"

internaltesting "github.com/redpanda-data/redpanda-operator/harpoon/internal/testing"
)

Expand Down
1 change: 1 addition & 0 deletions harpoon/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"reflect"

"github.com/cucumber/godog"

internaltesting "github.com/redpanda-data/redpanda-operator/harpoon/internal/testing"
)

Expand Down
3 changes: 2 additions & 1 deletion harpoon/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (

"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
"k8s.io/apimachinery/pkg/runtime"

"github.com/redpanda-data/helm-charts/pkg/helm"
internaltesting "github.com/redpanda-data/redpanda-operator/harpoon/internal/testing"
"github.com/redpanda-data/redpanda-operator/harpoon/internal/tracking"
"k8s.io/apimachinery/pkg/runtime"
)

func setShortTimeout(timeout *time.Duration, short time.Duration) {
Expand Down
5 changes: 3 additions & 2 deletions harpoon/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"

"github.com/redpanda-data/helm-charts/pkg/helm"
internaltesting "github.com/redpanda-data/redpanda-operator/harpoon/internal/testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/redpanda-data/helm-charts/pkg/helm"
internaltesting "github.com/redpanda-data/redpanda-operator/harpoon/internal/testing"
)

// Redefine the interfaces from the internal package
Expand Down
3 changes: 2 additions & 1 deletion operator/api/apiutil/apiutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"fmt"
"testing"

"github.com/redpanda-data/redpanda-operator/operator/api/apiutil"
"github.com/stretchr/testify/require"

"github.com/redpanda-data/redpanda-operator/operator/api/apiutil"
)

func TestJSONBoolean(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion operator/api/redpanda/v1alpha2/redpanda_clusterspec_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ package v1alpha2

import (
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/redpanda-data/redpanda-operator/operator/api/apiutil"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/redpanda-data/redpanda-operator/operator/api/apiutil"
)

// RedpandaClusterSpec defines the desired state of a Redpanda cluster. These settings are the same as those defined in the Redpanda Helm chart. The values in these settings are passed to the Redpanda Helm chart through Flux. For all default values and links to more documentation, see https://docs.redpanda.com/current/reference/redpanda-helm-spec/.
Expand Down
7 changes: 4 additions & 3 deletions operator/api/redpanda/v1alpha2/redpanda_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ import (
"github.com/cockroachdb/errors"
helmv2beta2 "github.com/fluxcd/helm-controller/api/v2beta2"
"github.com/fluxcd/pkg/apis/meta"
redpandachart "github.com/redpanda-data/helm-charts/charts/redpanda"
"github.com/redpanda-data/helm-charts/pkg/gotohelm/helmette"
"github.com/redpanda-data/helm-charts/pkg/kube"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"k8s.io/utils/ptr"

redpandachart "github.com/redpanda-data/helm-charts/charts/redpanda"
"github.com/redpanda-data/helm-charts/pkg/gotohelm/helmette"
"github.com/redpanda-data/helm-charts/pkg/kube"

"github.com/redpanda-data/redpanda-operator/operator/api/vectorized/v1alpha1"
)

Expand Down
15 changes: 8 additions & 7 deletions operator/api/redpanda/v1alpha2/redpanda_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ import (
"testing"
"time"

"github.com/redpanda-data/helm-charts/charts/connectors"
"github.com/redpanda-data/helm-charts/charts/console"
"github.com/redpanda-data/helm-charts/charts/redpanda"
"github.com/redpanda-data/redpanda-operator/operator/api/apiutil"
"github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
crds "github.com/redpanda-data/redpanda-operator/operator/config/crd/bases"
"github.com/redpanda-data/redpanda-operator/operator/internal/testutils"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -34,6 +27,14 @@ import (
"k8s.io/utils/ptr"
"pgregory.net/rapid"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/redpanda-data/helm-charts/charts/connectors"
"github.com/redpanda-data/helm-charts/charts/console"
"github.com/redpanda-data/helm-charts/charts/redpanda"
"github.com/redpanda-data/redpanda-operator/operator/api/apiutil"
"github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
crds "github.com/redpanda-data/redpanda-operator/operator/config/crd/bases"
"github.com/redpanda-data/redpanda-operator/operator/internal/testutils"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion operator/api/redpanda/v1alpha2/schema_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
"fmt"
"hash/fnv"

"github.com/redpanda-data/redpanda-operator/operator/pkg/functional"
"github.com/twmb/franz-go/pkg/sr"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

"github.com/redpanda-data/redpanda-operator/operator/pkg/functional"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion operator/api/redpanda/v1alpha2/schema_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"testing"
"time"

"github.com/redpanda-data/redpanda-operator/operator/internal/testutils"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/redpanda-data/redpanda-operator/operator/internal/testutils"
)

func TestSchemaValidation(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion operator/api/redpanda/v1alpha2/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
"errors"
"slices"

"github.com/redpanda-data/redpanda-operator/operator/pkg/functional"
"github.com/twmb/franz-go/pkg/kmsg"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/redpanda-data/redpanda-operator/operator/pkg/functional"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion operator/cmd/configurator/configurator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ package configurator
import (
"testing"

"github.com/redpanda-data/redpanda-operator/operator/pkg/resources"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config"
"github.com/stretchr/testify/assert"

"github.com/redpanda-data/redpanda-operator/operator/pkg/resources"
)

func TestPopulateRack(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion operator/cmd/envsubst/envsubst_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
"os"
"testing"

"github.com/stretchr/testify/require"

"github.com/redpanda-data/redpanda-operator/operator/cmd/envsubst"
"github.com/redpanda-data/redpanda-operator/operator/pkg/utils/testutils"
"github.com/stretchr/testify/require"
)

func TestCommand(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions operator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
"os"

"github.com/fluxcd/pkg/runtime/logger"
"github.com/spf13/cobra"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/redpanda-data/redpanda-operator/operator/cmd/configurator"
"github.com/redpanda-data/redpanda-operator/operator/cmd/envsubst"
"github.com/redpanda-data/redpanda-operator/operator/cmd/run"
"github.com/redpanda-data/redpanda-operator/operator/cmd/syncclusterconfig"
"github.com/redpanda-data/redpanda-operator/operator/cmd/version"
"github.com/spf13/cobra"
ctrl "sigs.k8s.io/controller-runtime"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion operator/cmd/syncclusterconfig/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (

"github.com/go-logr/logr/testr"
"github.com/redpanda-data/common-go/rpadmin"
"github.com/redpanda-data/redpanda-operator/operator/pkg/utils/testutils"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/redpanda"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/yaml"

"github.com/redpanda-data/redpanda-operator/operator/pkg/utils/testutils"
)

func TestSync(t *testing.T) {
Expand Down
Loading

0 comments on commit f888ad1

Please sign in to comment.