Skip to content

Commit

Permalink
enable more linters (#282)
Browse files Browse the repository at this point in the history
* enable nestif

* enable gomoddirectives

* enable nilerr

* enable forbidigo

* enable gofmt

* enable gci

* enable goimports

* enable exhaustive

* enable loggercheck

* enable wastedassign

* enable dupword

* enable gofumpt

* update go.mod and go.sum
  • Loading branch information
k15r authored Dec 5, 2023
1 parent e44bccf commit d892cf6
Show file tree
Hide file tree
Showing 117 changed files with 758 additions and 795 deletions.
16 changes: 1 addition & 15 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ linters:
### disabled for now... will be enabled 1 by 1
- containedctx
- dupl
- dupword
- errorlint
- exhaustive
- forbidigo
- forcetypeassert
- funlen
- gci
- ginkgolinter
- gochecknoglobals
- gochecknoinits
Expand All @@ -36,18 +32,11 @@ linters:
- gocritic
- godox
- goerr113
- gofumpt
- gofmt
- gomnd
- gomoddirectives
- gosec
- inamedparam
- interfacebloat
- ireturn
- loggercheck
- maintidx
- nestif
- nilerr
- noctx
- nolintlint
- nonamedreturns
Expand All @@ -62,11 +51,8 @@ linters:
- unconvert
- unparam
- varnamelen
- wastedassign
- wrapcheck
- godot
- goimports
- mirror
- tagalign
- whitespace

Expand Down Expand Up @@ -133,7 +119,7 @@ linters-settings:
alias: eventingv1alpha2
- pkg: github.com/kyma-project/eventing-manager/api/operator/v1alpha1
alias: operatorv1alpha1
- pkg: github.com/kyma-incubator/api-gateway/api/v1beta1
- pkg: github.com/kyma-project/api-gateway/apis/gateway/v1beta1
alias: apigatewayv1beta1
- pkg: k8s.io/client-go/dynamic/fake
alias: kdynamicfake
Expand Down
5 changes: 3 additions & 2 deletions api/eventing/v1alpha1/condition_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"testing"
"time"

. "github.com/onsi/gomega"
kcorev1 "k8s.io/api/core/v1"
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kyma-project/eventing-manager/api/eventing/v1alpha1"

. "github.com/onsi/gomega"
)

func Test_InitializeSubscriptionConditions(t *testing.T) {
var tests = []struct {
tests := []struct {
name string
givenConditions []v1alpha1.Condition
}{
Expand Down
28 changes: 13 additions & 15 deletions api/eventing/v1alpha1/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package v1alpha1_test
import (
"fmt"

"github.com/kyma-project/eventing-manager/api/eventing/v1alpha1"
"github.com/kyma-project/eventing-manager/pkg/utils"
eventingtesting "github.com/kyma-project/eventing-manager/testing"

kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kyma-project/eventing-manager/api/eventing/v1alpha1"
"github.com/kyma-project/eventing-manager/api/eventing/v1alpha2"
"github.com/kyma-project/eventing-manager/pkg/utils"
eventingtesting "github.com/kyma-project/eventing-manager/testing"
)

const (
Expand All @@ -30,17 +29,16 @@ const (
defaultStatusReady = true
)

var (
v2DefaultConditions = []v1alpha2.Condition{
{
Type: v1alpha2.ConditionSubscriptionActive,
Status: "true",
},
{
Type: v1alpha2.ConditionSubscribed,
Status: "false",
}}
)
var v2DefaultConditions = []v1alpha2.Condition{
{
Type: v1alpha2.ConditionSubscriptionActive,
Status: "true",
},
{
Type: v1alpha2.ConditionSubscribed,
Status: "false",
},
}

func newDefaultSubscription(opts ...eventingtesting.SubscriptionV1alpha1Opt) *v1alpha1.Subscription {
var defaultConditions []v1alpha1.Condition
Expand Down
49 changes: 26 additions & 23 deletions api/eventing/v1alpha1/subscription_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"strconv"
"strings"

"github.com/kyma-project/eventing-manager/pkg/backend/eventtype"

"github.com/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/conversion"

"github.com/kyma-project/eventing-manager/api/eventing/v1alpha2"
"github.com/kyma-project/eventing-manager/pkg/backend/eventtype"
)

const (
Expand Down Expand Up @@ -62,7 +61,7 @@ func V1ToV2(src *Subscription, dst *v1alpha2.Subscription) error {
}

// ConvertFrom converts this Subscription from the Hub version (v2) to v1.
func (dst *Subscription) ConvertFrom(srcRaw conversion.Hub) error { //nolint:revive
func (dst *Subscription) ConvertFrom(srcRaw conversion.Hub) error {
src, ok := srcRaw.(*v1alpha2.Subscription)
if !ok {
return errors.Errorf(ErrorHubVersionMsg)
Expand Down Expand Up @@ -133,27 +132,31 @@ func (src *Subscription) setV2ProtocolFields(dst *v1alpha2.Subscription) {
}
// protocol settings
if src.Spec.ProtocolSettings != nil {
if src.Spec.ProtocolSettings.ContentMode != nil {
dst.Spec.Config[v1alpha2.ProtocolSettingsContentMode] = *src.Spec.ProtocolSettings.ContentMode
}
if src.Spec.ProtocolSettings.ExemptHandshake != nil {
dst.Spec.Config[v1alpha2.ProtocolSettingsExemptHandshake] = fmt.Sprint(*src.Spec.ProtocolSettings.ExemptHandshake)
}
if src.Spec.ProtocolSettings.Qos != nil {
dst.Spec.Config[v1alpha2.ProtocolSettingsQos] = *src.Spec.ProtocolSettings.Qos
src.setProtocolSettings(dst)
}
}

func (src *Subscription) setProtocolSettings(dst *v1alpha2.Subscription) {
if src.Spec.ProtocolSettings.ContentMode != nil {
dst.Spec.Config[v1alpha2.ProtocolSettingsContentMode] = *src.Spec.ProtocolSettings.ContentMode
}
if src.Spec.ProtocolSettings.ExemptHandshake != nil {
dst.Spec.Config[v1alpha2.ProtocolSettingsExemptHandshake] = fmt.Sprint(*src.Spec.ProtocolSettings.ExemptHandshake)
}
if src.Spec.ProtocolSettings.Qos != nil {
dst.Spec.Config[v1alpha2.ProtocolSettingsQos] = *src.Spec.ProtocolSettings.Qos
}
// webhookAuth fields
if src.Spec.ProtocolSettings.WebhookAuth != nil {
if src.Spec.ProtocolSettings.WebhookAuth.Type != "" {
dst.Spec.Config[v1alpha2.WebhookAuthType] = src.Spec.ProtocolSettings.WebhookAuth.Type
}
// webhookAuth fields
if src.Spec.ProtocolSettings.WebhookAuth != nil {
if src.Spec.ProtocolSettings.WebhookAuth.Type != "" {
dst.Spec.Config[v1alpha2.WebhookAuthType] = src.Spec.ProtocolSettings.WebhookAuth.Type
}
dst.Spec.Config[v1alpha2.WebhookAuthGrantType] = src.Spec.ProtocolSettings.WebhookAuth.GrantType
dst.Spec.Config[v1alpha2.WebhookAuthClientID] = src.Spec.ProtocolSettings.WebhookAuth.ClientID
dst.Spec.Config[v1alpha2.WebhookAuthClientSecret] = src.Spec.ProtocolSettings.WebhookAuth.ClientSecret
dst.Spec.Config[v1alpha2.WebhookAuthTokenURL] = src.Spec.ProtocolSettings.WebhookAuth.TokenURL
if src.Spec.ProtocolSettings.WebhookAuth.Scope != nil {
dst.Spec.Config[v1alpha2.WebhookAuthScope] = strings.Join(src.Spec.ProtocolSettings.WebhookAuth.Scope, ",")
}
dst.Spec.Config[v1alpha2.WebhookAuthGrantType] = src.Spec.ProtocolSettings.WebhookAuth.GrantType
dst.Spec.Config[v1alpha2.WebhookAuthClientID] = src.Spec.ProtocolSettings.WebhookAuth.ClientID
dst.Spec.Config[v1alpha2.WebhookAuthClientSecret] = src.Spec.ProtocolSettings.WebhookAuth.ClientSecret
dst.Spec.Config[v1alpha2.WebhookAuthTokenURL] = src.Spec.ProtocolSettings.WebhookAuth.TokenURL
if src.Spec.ProtocolSettings.WebhookAuth.Scope != nil {
dst.Spec.Config[v1alpha2.WebhookAuthScope] = strings.Join(src.Spec.ProtocolSettings.WebhookAuth.Scope, ",")
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions api/eventing/v1alpha1/subscription_conversion_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ package v1alpha1_test
import (
"testing"

"github.com/kyma-project/eventing-manager/pkg/logger"

"github.com/kyma-project/eventing-manager/pkg/backend/eventtype"

"github.com/kyma-project/eventing-manager/pkg/ems/api/events/types"

eventingtesting "github.com/kyma-project/eventing-manager/testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/kyma-project/eventing-manager/api/eventing/v1alpha1"
"github.com/kyma-project/eventing-manager/api/eventing/v1alpha2"
"github.com/kyma-project/eventing-manager/pkg/backend/eventtype"
"github.com/kyma-project/eventing-manager/pkg/ems/api/events/types"
"github.com/kyma-project/eventing-manager/pkg/logger"
eventingtesting "github.com/kyma-project/eventing-manager/testing"
)

func Test_Conversion(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions api/eventing/v1alpha1/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
var Finalizer = GroupVersion.Group

// WebhookAuth defines the Webhook called by an active subscription in BEB.
// TODO: Remove it when depreciating code of v1alpha1
// TODO: Remove it when depreciating code of v1alpha1.
type WebhookAuth struct {
// Defines the authentication type.
// +optional
Expand All @@ -42,7 +42,7 @@ type WebhookAuth struct {
}

// ProtocolSettings defines the CE protocol setting specification implementation.
// TODO: Remove it when depreciating code of v1alpha1
// TODO: Remove it when depreciating code of v1alpha1.
type ProtocolSettings struct {
// Defines the content mode for eventing based on BEB.
// The value is either `BINARY`, or `STRUCTURED`.
Expand All @@ -62,7 +62,7 @@ type ProtocolSettings struct {
WebhookAuth *WebhookAuth `json:"webhookAuth,omitempty"`
}

// TODO: Remove it when depreciating code of v1alpha1
// TODO: Remove it when depreciating code of v1alpha1.
const (
ProtocolSettingsContentModeBinary string = "BINARY"
ProtocolSettingsContentModeStructured string = "STRUCTURED"
Expand Down Expand Up @@ -267,7 +267,7 @@ func (s Subscription) MarshalJSON() ([]byte, error) {
type SubscriptionList struct {
kmetav1.TypeMeta `json:",inline"`
kmetav1.ListMeta `json:"metadata,omitempty"`
Items []Subscription `json:"items"`
Items []Subscription `json:"items"`
}

// InitializeCleanEventTypes initializes the SubscriptionStatus.CleanEventTypes with an empty slice of strings.
Expand Down
3 changes: 1 addition & 2 deletions api/eventing/v1alpha1/subscription_types_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (

"github.com/stretchr/testify/require"

"github.com/kyma-project/eventing-manager/pkg/env"

"github.com/kyma-project/eventing-manager/api/eventing/v1alpha1"
"github.com/kyma-project/eventing-manager/pkg/env"
)

func TestBEBFilters_Deduplicate(t *testing.T) {
Expand Down
10 changes: 4 additions & 6 deletions api/eventing/v1alpha2/condition_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ import (
"time"

"github.com/pkg/errors"

eventingtesting "github.com/kyma-project/eventing-manager/testing"

"github.com/stretchr/testify/require"

. "github.com/onsi/gomega"
kcorev1 "k8s.io/api/core/v1"
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kyma-project/eventing-manager/api/eventing/v1alpha2"
eventingtesting "github.com/kyma-project/eventing-manager/testing"

. "github.com/onsi/gomega"
)

func Test_InitializeSubscriptionConditions(t *testing.T) {
var tests = []struct {
tests := []struct {
name string
givenConditions []v1alpha2.Condition
}{
Expand Down
4 changes: 2 additions & 2 deletions api/eventing/v1alpha2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"strconv"

"github.com/kyma-project/eventing-manager/pkg/ems/api/events/types"

"k8s.io/apimachinery/pkg/util/validation/field"

"github.com/kyma-project/eventing-manager/pkg/ems/api/events/types"
)

//nolint:gochecknoglobals // these are required for testing
Expand Down
8 changes: 3 additions & 5 deletions api/eventing/v1alpha2/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"encoding/json"
"strconv"

"github.com/kyma-project/eventing-manager/pkg/env"

kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kunstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
kruntime "k8s.io/apimachinery/pkg/runtime"

"github.com/kyma-project/eventing-manager/pkg/env"
"github.com/kyma-project/eventing-manager/pkg/utils"

kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type TypeMatching string
Expand Down Expand Up @@ -135,7 +133,7 @@ func (s *Subscription) ToUnstructuredSub() (*kunstructured.Unstructured, error)
type SubscriptionList struct {
kmetav1.TypeMeta `json:",inline"`
kmetav1.ListMeta `json:"metadata,omitempty"`
Items []Subscription `json:"items"`
Items []Subscription `json:"items"`
}

func init() { //nolint:gochecknoinits
Expand Down
13 changes: 8 additions & 5 deletions api/eventing/v1alpha2/subscription_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package v1alpha2_test
import (
"testing"

"github.com/kyma-project/eventing-manager/api/eventing/v1alpha2"
"github.com/stretchr/testify/assert"

"github.com/kyma-project/eventing-manager/api/eventing/v1alpha2"
"github.com/kyma-project/eventing-manager/pkg/env"
"github.com/stretchr/testify/assert"
)

func TestGetMaxInFlightMessages(t *testing.T) {
Expand All @@ -30,7 +30,8 @@ func TestGetMaxInFlightMessages(t *testing.T) {
givenSubscription: &v1alpha2.Subscription{
Spec: v1alpha2.SubscriptionSpec{
Config: map[string]string{
"otherConfigKey": "20"},
"otherConfigKey": "20",
},
},
},
wantResult: defaultSubConfig.MaxInFlightMessages,
Expand All @@ -40,7 +41,8 @@ func TestGetMaxInFlightMessages(t *testing.T) {
givenSubscription: &v1alpha2.Subscription{
Spec: v1alpha2.SubscriptionSpec{
Config: map[string]string{
v1alpha2.MaxInFlightMessages: "20"},
v1alpha2.MaxInFlightMessages: "20",
},
},
},
wantResult: 20,
Expand All @@ -50,7 +52,8 @@ func TestGetMaxInFlightMessages(t *testing.T) {
givenSubscription: &v1alpha2.Subscription{
Spec: v1alpha2.SubscriptionSpec{
Config: map[string]string{
v1alpha2.MaxInFlightMessages: "nonInt"},
v1alpha2.MaxInFlightMessages: "nonInt",
},
},
},
wantResult: defaultSubConfig.MaxInFlightMessages,
Expand Down
7 changes: 3 additions & 4 deletions api/eventing/v1alpha2/subscription_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import (
"strconv"
"strings"

"github.com/kyma-project/eventing-manager/pkg/ems/api/events/types"

"github.com/kyma-project/eventing-manager/pkg/utils"

kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
kctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/kyma-project/eventing-manager/pkg/ems/api/events/types"
"github.com/kyma-project/eventing-manager/pkg/utils"
)

const (
Expand Down
Loading

0 comments on commit d892cf6

Please sign in to comment.