Skip to content

Commit ec6e6e3

Browse files
authored
Merge pull request #4 from webhookrelay/feature/lint
Feature/lint
2 parents 5985dc2 + 1e713cb commit ec6e6e3

15 files changed

+179
-56
lines changed

Diff for: .drone.yml

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ steps:
2323
commands:
2424
- make build
2525

26+
- name: lint-code
27+
pull: default
28+
image: golang
29+
commands:
30+
- make golangci-lint
31+
- make lint
32+
2633
- name: lint-charts
2734
pull: default
2835
image: quay.io/helmpack/chart-testing:v3.0.0-rc.1

Diff for: .golangci.yml

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
linters-settings:
2+
depguard:
3+
list-type: blacklist
4+
packages:
5+
# logging is allowed only by logutils.Log, logrus
6+
# is allowed to use only in logutils package
7+
- github.com/sirupsen/logrus
8+
packages-with-error-message:
9+
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
10+
dupl:
11+
threshold: 300
12+
exhaustive:
13+
default-signifies-exhaustive: false
14+
funlen:
15+
lines: 100
16+
statements: 50
17+
goconst:
18+
min-len: 2
19+
min-occurrences: 2
20+
gocritic:
21+
enabled-tags:
22+
- diagnostic
23+
- experimental
24+
- opinionated
25+
- performance
26+
- style
27+
disabled-checks:
28+
- dupImport # https://github.com/go-critic/go-critic/issues/845
29+
- ifElseChain
30+
- octalLiteral
31+
- whyNoLint
32+
- wrapperFunc
33+
gocyclo:
34+
min-complexity: 20
35+
goimports:
36+
local-prefixes: github.com/golangci/golangci-lint
37+
golint:
38+
min-confidence: 0
39+
gomnd:
40+
settings:
41+
mnd:
42+
# don't include the "operation" and "assign"
43+
checks: argument,case,condition,return
44+
govet:
45+
check-shadowing: true
46+
settings:
47+
printf:
48+
funcs:
49+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
50+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
51+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
52+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
53+
lll:
54+
line-length: 180
55+
maligned:
56+
suggest-new: true
57+
misspell:
58+
locale: US
59+
nolintlint:
60+
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
61+
allow-unused: false # report any unused nolint directives
62+
require-explanation: false # don't require an explanation for nolint directives
63+
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
64+
65+
linters:
66+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
67+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
68+
disable-all: true
69+
enable:
70+
- bodyclose
71+
- deadcode
72+
- depguard
73+
- dogsled
74+
- dupl
75+
- errcheck
76+
- funlen
77+
# - gochecknoinits
78+
- goconst
79+
- gocritic
80+
- gocyclo
81+
- gofmt
82+
- goimports
83+
- golint
84+
- gomnd
85+
- goprintffuncname
86+
- gosec
87+
- gosimple
88+
- govet
89+
- ineffassign
90+
- interfacer
91+
- lll
92+
- misspell
93+
- nakedret
94+
- nolintlint
95+
- rowserrcheck
96+
- scopelint
97+
- staticcheck
98+
- structcheck
99+
- stylecheck
100+
- typecheck
101+
- unconvert
102+
- unparam
103+
- unused
104+
- varcheck
105+
# - whitespace
106+
107+
# don't enable:
108+
# - asciicheck
109+
# - exhaustive (TODO: enable after next release; current release at time of writing is v1.27)
110+
# - gochecknoglobals
111+
# - gocognit
112+
# - godot
113+
# - godox
114+
# - goerr113
115+
# - maligned
116+
# - nestif
117+
# - noctx (TODO: enable after next release; current release at time of writing is v1.27)
118+
# - prealloc
119+
# - testpackage
120+
# - wsl
121+
122+
issues:
123+
# Excluding configuration per-path, per-linter, per-text and per-source
124+
exclude-rules:
125+
- path: _test\.go
126+
linters:
127+
- gomnd
128+
129+
# https://github.com/go-critic/go-critic/issues/926
130+
- linters:
131+
- gocritic
132+
text: "unnecessaryDefer:"
133+
134+
run:
135+
skip-dirs:
136+
- test/
137+
138+
# golangci.com configuration
139+
# https://github.com/golangci/golangci/wiki/Configuration
140+
service:
141+
golangci-lint-version: 1.23.x # use the fixed version to not introduce new linters unexpectedly
142+
prepare:
143+
- echo "here I can run custom commands, but no preparation needed for this repo"

Diff for: Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ build:
2626
-o ./build/_output/bin/webhookrelay-operator \
2727
./cmd/manager
2828

29+
##############################
30+
# DEV #
31+
##############################
32+
2933
# Generate APIs, CRD specs and CRD clientset.
3034
go-gen:
3135
$(OPERATOR_SDK) generate k8s
@@ -49,6 +53,9 @@ add-cr:
4953
image-operator:
5054
docker build . -f build/Dockerfile -t $(OPERATOR_IMAGE)
5155

56+
lint:
57+
$(GOLANGCI_LINT) run
58+
5259
##############################
5360
# OLM #
5461
##############################

Diff for: cmd/manager/main.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,14 @@ func main() {
119119
os.Exit(1)
120120
}
121121

122-
mgr.AddHealthzCheck("up", func(req *http.Request) error {
122+
if err := mgr.AddHealthzCheck("up", func(req *http.Request) error {
123123
// OK
124124
return nil
125-
})
125+
}); err != nil {
126+
log.Error(err, "")
127+
os.Exit(1)
128+
return
129+
}
126130

127131
log.Info("Registering Components.")
128132

@@ -162,7 +166,8 @@ func addMetrics(ctx context.Context, cfg *rest.Config) {
162166
}
163167
}
164168

165-
if err := serveCRMetrics(cfg, operatorNs); err != nil {
169+
err = serveCRMetrics(cfg, operatorNs)
170+
if err != nil {
166171
log.Info("Could not generate and serve custom resource metrics", "error", err.Error())
167172
}
168173

Diff for: pkg/config/load.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func Load() (Config, error) {
99
return config, err
1010
}
1111

12-
// MustLoad loads the configuration from the environmnet
12+
// MustLoad loads the configuration from the environment
1313
// and panics if an error is encountered.
1414
func MustLoad() Config {
1515
config, err := Load()

Diff for: pkg/controller/webhookrelayforward/cache.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func (c *bucketsCache) AddOutput(o *webhookrelay.Output) {
6363
c.items[k] = bucket
6464
}
6565
}
66-
6766
}
6867

6968
// Add a bucket to the cache. Can be used after creation or bucket update
@@ -120,7 +119,7 @@ func (c *bucketsCache) List() []*webhookrelay.Bucket {
120119
cp := new(webhookrelay.Bucket)
121120
err = copier.Copy(v, cp)
122121
if err != nil {
123-
//
122+
continue
124123
}
125124
items = append(items, cp)
126125
}

Diff for: pkg/controller/webhookrelayforward/cache_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ func TestCache_AddOutput(t *testing.T) {
2828
})
2929

3030
t.Run("TestUpdateBucket", func(t *testing.T) {
31-
// c.Add(&webhookrelay.Bucket{ID: "foo", Name: "b-1"})
32-
3331
c.AddOutput(&webhookrelay.Output{ID: "foo", BucketID: "foo", Name: "o-1"})
3432

3533
name := c.items["b-1"].Outputs[0].Name
3634
assert.Equal(t, 1, len(c.items))
3735
assert.Equal(t, 1, len(c.items["b-1"].Outputs))
3836
assert.Equal(t, "o-1", name)
3937
})
40-
4138
}

Diff for: pkg/controller/webhookrelayforward/public_endpoints_status.go

-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
)
88

99
func (r *ReconcileWebhookRelayForward) shouldUpdatePublicEndpoints(instance *forwardv1.WebhookRelayForward) (*forwardv1.WebhookRelayForward, bool) {
10-
1110
if len(instance.Spec.Buckets) == 0 && len(instance.Status.PublicEndpoints) == 0 {
1211
// nothing to do
1312
return nil, false
@@ -26,7 +25,6 @@ func (r *ReconcileWebhookRelayForward) shouldUpdatePublicEndpoints(instance *for
2625
sort.Strings(instance.Status.PublicEndpoints)
2726

2827
if !sliceEquals(desiredEndpoints, instance.Status.PublicEndpoints) {
29-
3028
patch := instance.DeepCopy()
3129
patch.Status.PublicEndpoints = desiredEndpoints
3230
return patch, true
@@ -36,7 +34,6 @@ func (r *ReconcileWebhookRelayForward) shouldUpdatePublicEndpoints(instance *for
3634
}
3735

3836
func computePublicEndpoints(instance *forwardv1.WebhookRelayForward, bucketsCache *bucketsCache) []string {
39-
4037
var (
4138
endpoints []string
4239
endpoint string

Diff for: pkg/controller/webhookrelayforward/sync_buckets.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func (r *ReconcileWebhookRelayForward) ensureBucketConfiguration(logger logr.Log
2424
r.apiClient.bucketsCache.Set(buckets)
2525

2626
for i := range instance.Spec.Buckets {
27-
2827
if instance.Spec.Buckets[i].Description == "" {
2928
instance.Spec.Buckets[i].Description = getBucketDescription(instance)
3029
}
@@ -64,7 +63,6 @@ func (r *ReconcileWebhookRelayForward) ensureBucketConfiguration(logger logr.Log
6463
"bucket_ref", instance.Spec.Buckets[i].Name,
6564
)
6665
}
67-
6866
}
6967

7068
if len(errors) > 0 {
@@ -87,6 +85,7 @@ func getBucketByName(name string, buckets []*webhookrelay.Bucket) (*webhookrelay
8785
return nil, false
8886
}
8987

88+
//nolint
9089
func bucketEqual(spec *forwardv1.BucketSpec, bucket *webhookrelay.Bucket) bool {
9190

9291
if spec.Description != bucket.Description {

Diff for: pkg/controller/webhookrelayforward/sync_inputs.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
)
1111

1212
// ensureBucketInputs checks and configures input specific information
13-
func (r *ReconcileWebhookRelayForward) ensureBucketInputs(logger logr.Logger, instance *forwardv1.WebhookRelayForward, bucketSpec *forwardv1.BucketSpec) error {
14-
13+
func (r *ReconcileWebhookRelayForward) ensureBucketInputs(logger logr.Logger, bucketSpec *forwardv1.BucketSpec) error {
1514
// If no inputs are defined, nothing to do
1615
if len(bucketSpec.Inputs) == 0 {
1716
return nil
@@ -81,7 +80,6 @@ func (r *ReconcileWebhookRelayForward) ensureBucketInputs(logger logr.Logger, in
8180
}
8281

8382
func desiredInputs(bucketSpec *forwardv1.BucketSpec, bucket *webhookrelay.Bucket) []*webhookrelay.Input {
84-
8583
var desired []*webhookrelay.Input
8684

8785
for i := range bucketSpec.Inputs {
@@ -92,7 +90,6 @@ func desiredInputs(bucketSpec *forwardv1.BucketSpec, bucket *webhookrelay.Bucket
9290
}
9391

9492
func inputSpecToInput(spec *forwardv1.InputSpec, bucket *webhookrelay.Bucket) *webhookrelay.Input {
95-
9693
// Ensuring that ResponseFromOutput is either empty, 'anyOutput' or an actual ID
9794
// of the output that is inside this bucket
9895
if spec.ResponseFromOutput != "" && spec.ResponseFromOutput != "anyOutput" {
@@ -123,7 +120,6 @@ func inputSpecToInput(spec *forwardv1.InputSpec, bucket *webhookrelay.Bucket) *w
123120
}
124121

125122
func getInputsDiff(current, desired []*webhookrelay.Input) *inputsDiff {
126-
127123
diff := &inputsDiff{}
128124

129125
currentMap := make(map[string]*webhookrelay.Input)

Diff for: pkg/controller/webhookrelayforward/sync_outputs.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
forwardv1 "github.com/webhookrelay/webhookrelay-operator/pkg/apis/forward/v1"
1010
)
1111

12-
func (r *ReconcileWebhookRelayForward) ensureBucketOutputs(logger logr.Logger, instance *forwardv1.WebhookRelayForward, bucketSpec *forwardv1.BucketSpec) error {
13-
12+
func (r *ReconcileWebhookRelayForward) ensureBucketOutputs(logger logr.Logger, bucketSpec *forwardv1.BucketSpec) error {
1413
// If no outputs are defined, nothing to do
1514
if len(bucketSpec.Outputs) == 0 {
1615
return nil
@@ -93,7 +92,6 @@ type outputsDiff struct {
9392
}
9493

9594
func getOutputsDiff(current, desired []*webhookrelay.Output) *outputsDiff {
96-
9795
diff := &outputsDiff{}
9896

9997
currentMap := make(map[string]*webhookrelay.Output)
@@ -134,7 +132,6 @@ func getOutputsDiff(current, desired []*webhookrelay.Output) *outputsDiff {
134132
}
135133

136134
func desiredOutputs(bucketSpec *forwardv1.BucketSpec, bucket *webhookrelay.Bucket) []*webhookrelay.Output {
137-
138135
var desired []*webhookrelay.Output
139136

140137
for i := range bucketSpec.Outputs {
@@ -173,7 +170,6 @@ func inputSpecToOutput(spec *forwardv1.OutputSpec, bucket *webhookrelay.Bucket)
173170
}
174171

175172
func outputsEqual(current, desired *webhookrelay.Output) bool {
176-
177173
if current.Name != desired.Name {
178174
return false
179175
}

Diff for: pkg/controller/webhookrelayforward/webhookrelayforward_api_client.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// Errors
1616
var (
17-
ErrCredentialsNotProvided = errors.New("Webhook Relay access token key and secret not provided")
17+
ErrCredentialsNotProvided = errors.New("access token key and secret not provided")
1818
)
1919

2020
// WebhookRelayClient is a wrapper for the Webhook Relay API client
@@ -37,15 +37,13 @@ type WebhookRelayClient struct {
3737
}
3838

3939
func (r *ReconcileWebhookRelayForward) setClientForCluster(instance *forwardv1.WebhookRelayForward) error {
40-
4140
// credentials to use
4241
var (
4342
relayKey string
4443
relaySecret string
4544
)
4645

4746
if instance.Spec.SecretRefName != "" {
48-
4947
namespace := instance.Spec.SecretRefNamespace
5048
if namespace == "" {
5149
// defaulting to CR namespace

0 commit comments

Comments
 (0)