Skip to content

Commit 88e8762

Browse files
authored
chore: makes linter happy (#17)
Signed-off-by: Leonardo Cecchi <[email protected]>
1 parent cbefe26 commit 88e8762

File tree

16 files changed

+184
-47
lines changed

16 files changed

+184
-47
lines changed

.golangci.yml

Lines changed: 115 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,127 @@ linters-settings:
88
- prefix(github.com/cloudnative-pg/plugin-barman-cloud)
99
- blank
1010
- dot
11-
nlreturn:
12-
# Size of the block (including return statement that is still "OK")
13-
# so no return split required.
14-
# Default: 1
15-
block-size: 3
11+
gosec:
12+
excludes:
13+
- G101 # remove this exclude when https://github.com/securego/gosec/issues/1001 is fixed
14+
15+
linters:
16+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
17+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
18+
disable-all: true
19+
enable:
20+
- asciicheck
21+
- bodyclose
22+
- dogsled
23+
- dupl
24+
- durationcheck
25+
- errcheck
26+
- copyloopvar
27+
- gci
28+
- gocognit
29+
- goconst
30+
- gocritic
31+
- gocyclo
32+
- gofmt
33+
- gofumpt
34+
- goheader
35+
- goimports
36+
- gomoddirectives
37+
- gomodguard
38+
- goprintffuncname
39+
- gosec
40+
- gosimple
41+
- govet
42+
- ginkgolinter
43+
- importas
44+
- ineffassign
45+
- lll
46+
- makezero
47+
- misspell
48+
- nakedret
49+
- nestif
50+
- prealloc
51+
- predeclared
52+
- revive
53+
- rowserrcheck
54+
- sqlclosecheck
55+
- staticcheck
56+
- stylecheck
57+
- thelper
58+
- tparallel
59+
- typecheck
60+
- unconvert
61+
- unparam
62+
- unused
63+
- wastedassign
64+
- whitespace
65+
66+
# to be checked:
67+
# - errorlint
68+
# - forbidigo
69+
# - forcetypeassert
70+
# - goerr113
71+
# - ifshort
72+
# - nilerr
73+
# - nlreturn
74+
# - noctx
75+
# - nolintlint
76+
# - paralleltest
77+
# - promlinter
78+
# - tagliatelle
79+
# - wrapcheck
80+
81+
# don't enable:
82+
# - cyclop
83+
# - depguard
84+
# - exhaustive
85+
# - exhaustivestruct
86+
# - funlen
87+
# - gochecknoglobals
88+
# - gochecknoinits
89+
# - godot
90+
# - godox
91+
# - gomnd
92+
# - testpackage
93+
# - wsl
94+
95+
# deprecated:
96+
# - deadcode
97+
# - golint
98+
# - interfacer
99+
# - maligned
100+
# - scopelint
101+
# - structcheck
102+
# - varcheck
103+
104+
run:
105+
timeout: 5m
16106

17107
issues:
18108
exclude-rules:
19109
# Allow dot imports for ginkgo and gomega
20110
- source: ginkgo|gomega
21111
linters:
22-
- revive
112+
- revive
23113
text: "should not use dot imports"
114+
# Exclude some linters from running on tests files.
115+
- path: _test\.go
116+
linters:
117+
- goconst
118+
# Exclude lll issues for lines with long annotations
24119
- linters:
25-
- stylecheck
26-
text: "should not use dot imports"
120+
- lll
121+
source: "//\\s*\\+"
122+
# We have no control of this in zz_generated files and it looks like that excluding those files is not enough
123+
# so we disable "ST1016: methods on the same type should have the same receiver name" in api directory
124+
- linters:
125+
- stylecheck
126+
text: "ST1016:"
127+
path: api/
128+
exclude-use-default: false
27129
exclude-dirs:
28-
- vendor
29-
30-
linters:
31-
enable-all: true
32-
disable:
33-
- depguard
34-
- err113
35-
- exhaustruct
36-
- execinquery
37-
- exportloopref
38-
- funlen
39-
- gochecknoglobals
40-
- gochecknoinits
41-
- godox
42-
- gomnd
43-
- paralleltest
44-
- testpackage
45-
- varnamelen
46-
- wsl
47-
48-
run:
49-
timeout: 10m
50-
allow-parallel-runners: true
130+
# This tests are generated by kubebuilder
131+
- test
132+
exclude-files:
133+
- zz_generated.*
134+
- internal/controller/suite_test.go

cmd/instance/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main is the implementation of the CNPG-i PostgreSQL sidecar
12
package main
23

34
import (
@@ -9,7 +10,6 @@ import (
910
"k8s.io/apimachinery/pkg/runtime"
1011
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1112
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
12-
controllerruntime "sigs.k8s.io/controller-runtime"
1313
ctrl "sigs.k8s.io/controller-runtime"
1414
"sigs.k8s.io/controller-runtime/pkg/cache"
1515
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -37,7 +37,7 @@ func main() {
3737
clusterName := mustGetEnv("CLUSTER_NAME")
3838
instanceName := mustGetEnv("INSTANCE_NAME")
3939

40-
mgr, err := controllerruntime.NewManager(controllerruntime.GetConfigOrDie(), controllerruntime.Options{
40+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
4141
Scheme: scheme,
4242
Cache: cache.Options{
4343
ByObject: map[client.Object]cache.ByObject{

cmd/operator/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package main contains the implementation of the CNPG-i operator plugin
1718
package main
1819

1920
import (

internal/cnpgi/instance/backup.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import (
66
"github.com/cloudnative-pg/cnpg-i/pkg/backup"
77
)
88

9+
// BackupServiceImplementation is the implementation
10+
// of the Backup CNPG capability
911
type BackupServiceImplementation struct {
1012
backup.UnimplementedBackupServer
1113
}
1214

15+
// GetCapabilities implements the BackupService interface
1316
func (b BackupServiceImplementation) GetCapabilities(
1417
_ context.Context, _ *backup.BackupCapabilitiesRequest,
1518
) (*backup.BackupCapabilitiesResult, error) {
@@ -26,6 +29,7 @@ func (b BackupServiceImplementation) GetCapabilities(
2629
}, nil
2730
}
2831

32+
// Backup implements the Backup interface
2933
func (b BackupServiceImplementation) Backup(_ context.Context, _ *backup.BackupRequest) (*backup.BackupResult, error) {
3034
// TODO implement me
3135
panic("implement me")

internal/cnpgi/instance/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package instance
22

33
import "github.com/cloudnative-pg/cnpg-i/pkg/identity"
44

5+
// PluginName is the name of the plugin from the instance manager
6+
// Point-of-view
57
const PluginName = "instance.barman-cloud.cloudnative-pg.io"
68

79
// Data is the metadata of this plugin.

internal/cnpgi/instance/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package instance implements the capabilities used by the operator sidecar
2+
package instance

internal/cnpgi/instance/identity.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ import (
1010
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
1111
)
1212

13+
// IdentityImplementation implements IdentityServer
1314
type IdentityImplementation struct {
1415
identity.UnimplementedIdentityServer
1516
BarmanObjectKey client.ObjectKey
1617
Client client.Client
1718
}
1819

20+
// GetPluginMetadata implements IdentityServer
1921
func (i IdentityImplementation) GetPluginMetadata(
2022
_ context.Context,
2123
_ *identity.GetPluginMetadataRequest,
2224
) (*identity.GetPluginMetadataResponse, error) {
2325
return &Data, nil
2426
}
2527

28+
// GetPluginCapabilities implements IdentityServer
2629
func (i IdentityImplementation) GetPluginCapabilities(
2730
_ context.Context,
2831
_ *identity.GetPluginCapabilitiesRequest,
@@ -47,6 +50,7 @@ func (i IdentityImplementation) GetPluginCapabilities(
4750
}, nil
4851
}
4952

53+
// Probe implements IdentityServer
5054
func (i IdentityImplementation) Probe(
5155
ctx context.Context,
5256
_ *identity.ProbeRequest,

internal/cnpgi/instance/start.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sigs.k8s.io/controller-runtime/pkg/client"
1111
)
1212

13+
// CNPGI is the implementation of the PostgreSQL sidecar
1314
type CNPGI struct {
1415
Client client.Client
1516
BarmanObjectKey client.ObjectKey
@@ -27,6 +28,7 @@ type CNPGI struct {
2728
InstanceName string
2829
}
2930

31+
// Start starts the GRPC service
3032
func (c *CNPGI) Start(ctx context.Context) error {
3133
enrich := func(server *grpc.Server) error {
3234
wal.RegisterWALServer(server, WALServiceImplementation{

internal/cnpgi/instance/wal.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
2323
)
2424

25+
// WALServiceImplementation is the implementation of the WAL Service
2526
type WALServiceImplementation struct {
2627
BarmanObjectKey client.ObjectKey
2728
ClusterObjectKey client.ObjectKey
@@ -33,7 +34,11 @@ type WALServiceImplementation struct {
3334
wal.UnimplementedWALServer
3435
}
3536

36-
func (w WALServiceImplementation) GetCapabilities(ctx context.Context, request *wal.WALCapabilitiesRequest) (*wal.WALCapabilitiesResult, error) {
37+
// GetCapabilities implements the WALService interface
38+
func (w WALServiceImplementation) GetCapabilities(
39+
_ context.Context,
40+
_ *wal.WALCapabilitiesRequest,
41+
) (*wal.WALCapabilitiesResult, error) {
3742
return &wal.WALCapabilitiesResult{
3843
Capabilities: []*wal.WALCapability{
3944
{
@@ -54,7 +59,11 @@ func (w WALServiceImplementation) GetCapabilities(ctx context.Context, request *
5459
}, nil
5560
}
5661

57-
func (w WALServiceImplementation) Archive(ctx context.Context, request *wal.WALArchiveRequest) (*wal.WALArchiveResult, error) {
62+
// Archive implements the WALService interface
63+
func (w WALServiceImplementation) Archive(
64+
ctx context.Context,
65+
request *wal.WALArchiveRequest,
66+
) (*wal.WALArchiveResult, error) {
5867
var objectStore barmancloudv1.ObjectStore
5968
if err := w.Client.Get(ctx, w.BarmanObjectKey, &objectStore); err != nil {
6069
return nil, err
@@ -90,7 +99,11 @@ func (w WALServiceImplementation) Archive(ctx context.Context, request *wal.WALA
9099
return &wal.WALArchiveResult{}, nil
91100
}
92101

93-
func (w WALServiceImplementation) Restore(ctx context.Context, request *wal.WALRestoreRequest) (*wal.WALRestoreResult, error) {
102+
// Restore implements the WALService interface
103+
func (w WALServiceImplementation) Restore(
104+
ctx context.Context,
105+
request *wal.WALRestoreRequest,
106+
) (*wal.WALRestoreResult, error) {
94107
contextLogger := log.FromContext(ctx)
95108
startTime := time.Now()
96109

@@ -181,7 +194,7 @@ func (w WALServiceImplementation) Restore(ctx context.Context, request *wal.WALR
181194
return nil, walStatus[0].Err
182195
}
183196

184-
//We skip this step if streaming connection is not available
197+
// We skip this step if streaming connection is not available
185198
endOfWALStream := isEndOfWALStream(walStatus)
186199
if isStreamingAvailable(cluster, w.InstanceName) && endOfWALStream {
187200
contextLogger.Info(
@@ -213,12 +226,20 @@ func (w WALServiceImplementation) Restore(ctx context.Context, request *wal.WALR
213226
return &wal.WALRestoreResult{}, nil
214227
}
215228

216-
func (w WALServiceImplementation) Status(ctx context.Context, request *wal.WALStatusRequest) (*wal.WALStatusResult, error) {
229+
// Status implements the WALService interface
230+
func (w WALServiceImplementation) Status(
231+
_ context.Context,
232+
_ *wal.WALStatusRequest,
233+
) (*wal.WALStatusResult, error) {
217234
// TODO implement me
218235
panic("implement me")
219236
}
220237

221-
func (w WALServiceImplementation) SetFirstRequired(ctx context.Context, request *wal.SetFirstRequiredRequest) (*wal.SetFirstRequiredResult, error) {
238+
// SetFirstRequired implements the WALService interface
239+
func (w WALServiceImplementation) SetFirstRequired(
240+
_ context.Context,
241+
_ *wal.SetFirstRequiredRequest,
242+
) (*wal.SetFirstRequiredResult, error) {
222243
// TODO implement me
223244
panic("implement me")
224245
}
@@ -325,7 +346,7 @@ func gatherWALFilesToRestore(walName string, parallel int) (walList []string, er
325346
return walList, err
326347
}
327348

328-
// ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive
349+
// ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive.
329350
var ErrEndOfWALStreamReached = errors.New("end of WAL reached")
330351

331352
// checkEndOfWALStreamFlag returns ErrEndOfWALStreamReached if the flag is set in the restorer.

internal/cnpgi/instance/wal_import.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ var (
7575
WALSegmentNameRe +
7676
`$`)
7777

78-
// ErrorBadWALSegmentName is raised when parsing an invalid segment name.
79-
ErrorBadWALSegmentName = errors.New("invalid WAL segment name")
78+
// ErrBadWALSegmentName is raised when parsing an invalid segment name.
79+
ErrBadWALSegmentName = errors.New("invalid WAL segment name")
8080
)
8181

8282
// Segment contains the information inside a WAL segment name.
@@ -109,23 +109,23 @@ func SegmentFromName(name string) (Segment, error) {
109109
// We could have used WALSegmentRe directly, but we wanted to adhere to barman code
110110
subMatches := WALRe.FindStringSubmatch(baseName)
111111
if len(subMatches) != 4 {
112-
return Segment{}, ErrorBadWALSegmentName
112+
return Segment{}, ErrBadWALSegmentName
113113
}
114114

115115
if len(subMatches[0]) != 24 {
116-
return Segment{}, ErrorBadWALSegmentName
116+
return Segment{}, ErrBadWALSegmentName
117117
}
118118

119119
if tli, err = strconv.ParseInt(subMatches[1], 16, 32); err != nil {
120-
return Segment{}, ErrorBadWALSegmentName
120+
return Segment{}, ErrBadWALSegmentName
121121
}
122122

123123
if log, err = strconv.ParseInt(subMatches[2], 16, 32); err != nil {
124-
return Segment{}, ErrorBadWALSegmentName
124+
return Segment{}, ErrBadWALSegmentName
125125
}
126126

127127
if seg, err = strconv.ParseInt(subMatches[3], 16, 32); err != nil {
128-
return Segment{}, ErrorBadWALSegmentName
128+
return Segment{}, ErrBadWALSegmentName
129129
}
130130

131131
return Segment{

0 commit comments

Comments
 (0)