chore: makes linter happy (#17)

Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
This commit is contained in:
Leonardo Cecchi 2024-10-01 11:54:07 +02:00 committed by GitHub
parent cbefe26440
commit 88e8762858
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 184 additions and 47 deletions

View File

@ -8,43 +8,127 @@ linters-settings:
- prefix(github.com/cloudnative-pg/plugin-barman-cloud)
- blank
- dot
nlreturn:
# Size of the block (including return statement that is still "OK")
# so no return split required.
# Default: 1
block-size: 3
gosec:
excludes:
- G101 # remove this exclude when https://github.com/securego/gosec/issues/1001 is fixed
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asciicheck
- bodyclose
- dogsled
- dupl
- durationcheck
- errcheck
- copyloopvar
- gci
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- ginkgolinter
- importas
- ineffassign
- lll
- makezero
- misspell
- nakedret
- nestif
- prealloc
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- wastedassign
- whitespace
# to be checked:
# - errorlint
# - forbidigo
# - forcetypeassert
# - goerr113
# - ifshort
# - nilerr
# - nlreturn
# - noctx
# - nolintlint
# - paralleltest
# - promlinter
# - tagliatelle
# - wrapcheck
# don't enable:
# - cyclop
# - depguard
# - exhaustive
# - exhaustivestruct
# - funlen
# - gochecknoglobals
# - gochecknoinits
# - godot
# - godox
# - gomnd
# - testpackage
# - wsl
# deprecated:
# - deadcode
# - golint
# - interfacer
# - maligned
# - scopelint
# - structcheck
# - varcheck
run:
timeout: 5m
issues:
exclude-rules:
# Allow dot imports for ginkgo and gomega
- source: ginkgo|gomega
linters:
- revive
- revive
text: "should not use dot imports"
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- goconst
# Exclude lll issues for lines with long annotations
- linters:
- stylecheck
text: "should not use dot imports"
- lll
source: "//\\s*\\+"
# We have no control of this in zz_generated files and it looks like that excluding those files is not enough
# so we disable "ST1016: methods on the same type should have the same receiver name" in api directory
- linters:
- stylecheck
text: "ST1016:"
path: api/
exclude-use-default: false
exclude-dirs:
- vendor
linters:
enable-all: true
disable:
- depguard
- err113
- exhaustruct
- execinquery
- exportloopref
- funlen
- gochecknoglobals
- gochecknoinits
- godox
- gomnd
- paralleltest
- testpackage
- varnamelen
- wsl
run:
timeout: 10m
allow-parallel-runners: true
# This tests are generated by kubebuilder
- test
exclude-files:
- zz_generated.*
- internal/controller/suite_test.go

View File

@ -1,3 +1,4 @@
// Package main is the implementation of the CNPG-i PostgreSQL sidecar
package main
import (
@ -9,7 +10,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
controllerruntime "sigs.k8s.io/controller-runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
@ -37,7 +37,7 @@ func main() {
clusterName := mustGetEnv("CLUSTER_NAME")
instanceName := mustGetEnv("INSTANCE_NAME")
mgr, err := controllerruntime.NewManager(controllerruntime.GetConfigOrDie(), controllerruntime.Options{
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Cache: cache.Options{
ByObject: map[client.Object]cache.ByObject{

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Package main contains the implementation of the CNPG-i operator plugin
package main
import (

View File

@ -6,10 +6,13 @@ import (
"github.com/cloudnative-pg/cnpg-i/pkg/backup"
)
// BackupServiceImplementation is the implementation
// of the Backup CNPG capability
type BackupServiceImplementation struct {
backup.UnimplementedBackupServer
}
// GetCapabilities implements the BackupService interface
func (b BackupServiceImplementation) GetCapabilities(
_ context.Context, _ *backup.BackupCapabilitiesRequest,
) (*backup.BackupCapabilitiesResult, error) {
@ -26,6 +29,7 @@ func (b BackupServiceImplementation) GetCapabilities(
}, nil
}
// Backup implements the Backup interface
func (b BackupServiceImplementation) Backup(_ context.Context, _ *backup.BackupRequest) (*backup.BackupResult, error) {
// TODO implement me
panic("implement me")

View File

@ -2,6 +2,8 @@ package instance
import "github.com/cloudnative-pg/cnpg-i/pkg/identity"
// PluginName is the name of the plugin from the instance manager
// Point-of-view
const PluginName = "instance.barman-cloud.cloudnative-pg.io"
// Data is the metadata of this plugin.

View File

@ -0,0 +1,2 @@
// Package instance implements the capabilities used by the operator sidecar
package instance

View File

@ -10,12 +10,14 @@ import (
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
)
// IdentityImplementation implements IdentityServer
type IdentityImplementation struct {
identity.UnimplementedIdentityServer
BarmanObjectKey client.ObjectKey
Client client.Client
}
// GetPluginMetadata implements IdentityServer
func (i IdentityImplementation) GetPluginMetadata(
_ context.Context,
_ *identity.GetPluginMetadataRequest,
@ -23,6 +25,7 @@ func (i IdentityImplementation) GetPluginMetadata(
return &Data, nil
}
// GetPluginCapabilities implements IdentityServer
func (i IdentityImplementation) GetPluginCapabilities(
_ context.Context,
_ *identity.GetPluginCapabilitiesRequest,
@ -47,6 +50,7 @@ func (i IdentityImplementation) GetPluginCapabilities(
}, nil
}
// Probe implements IdentityServer
func (i IdentityImplementation) Probe(
ctx context.Context,
_ *identity.ProbeRequest,

View File

@ -10,6 +10,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)
// CNPGI is the implementation of the PostgreSQL sidecar
type CNPGI struct {
Client client.Client
BarmanObjectKey client.ObjectKey
@ -27,6 +28,7 @@ type CNPGI struct {
InstanceName string
}
// Start starts the GRPC service
func (c *CNPGI) Start(ctx context.Context) error {
enrich := func(server *grpc.Server) error {
wal.RegisterWALServer(server, WALServiceImplementation{

View File

@ -22,6 +22,7 @@ import (
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
)
// WALServiceImplementation is the implementation of the WAL Service
type WALServiceImplementation struct {
BarmanObjectKey client.ObjectKey
ClusterObjectKey client.ObjectKey
@ -33,7 +34,11 @@ type WALServiceImplementation struct {
wal.UnimplementedWALServer
}
func (w WALServiceImplementation) GetCapabilities(ctx context.Context, request *wal.WALCapabilitiesRequest) (*wal.WALCapabilitiesResult, error) {
// GetCapabilities implements the WALService interface
func (w WALServiceImplementation) GetCapabilities(
_ context.Context,
_ *wal.WALCapabilitiesRequest,
) (*wal.WALCapabilitiesResult, error) {
return &wal.WALCapabilitiesResult{
Capabilities: []*wal.WALCapability{
{
@ -54,7 +59,11 @@ func (w WALServiceImplementation) GetCapabilities(ctx context.Context, request *
}, nil
}
func (w WALServiceImplementation) Archive(ctx context.Context, request *wal.WALArchiveRequest) (*wal.WALArchiveResult, error) {
// Archive implements the WALService interface
func (w WALServiceImplementation) Archive(
ctx context.Context,
request *wal.WALArchiveRequest,
) (*wal.WALArchiveResult, error) {
var objectStore barmancloudv1.ObjectStore
if err := w.Client.Get(ctx, w.BarmanObjectKey, &objectStore); err != nil {
return nil, err
@ -90,7 +99,11 @@ func (w WALServiceImplementation) Archive(ctx context.Context, request *wal.WALA
return &wal.WALArchiveResult{}, nil
}
func (w WALServiceImplementation) Restore(ctx context.Context, request *wal.WALRestoreRequest) (*wal.WALRestoreResult, error) {
// Restore implements the WALService interface
func (w WALServiceImplementation) Restore(
ctx context.Context,
request *wal.WALRestoreRequest,
) (*wal.WALRestoreResult, error) {
contextLogger := log.FromContext(ctx)
startTime := time.Now()
@ -181,7 +194,7 @@ func (w WALServiceImplementation) Restore(ctx context.Context, request *wal.WALR
return nil, walStatus[0].Err
}
//We skip this step if streaming connection is not available
// We skip this step if streaming connection is not available
endOfWALStream := isEndOfWALStream(walStatus)
if isStreamingAvailable(cluster, w.InstanceName) && endOfWALStream {
contextLogger.Info(
@ -213,12 +226,20 @@ func (w WALServiceImplementation) Restore(ctx context.Context, request *wal.WALR
return &wal.WALRestoreResult{}, nil
}
func (w WALServiceImplementation) Status(ctx context.Context, request *wal.WALStatusRequest) (*wal.WALStatusResult, error) {
// Status implements the WALService interface
func (w WALServiceImplementation) Status(
_ context.Context,
_ *wal.WALStatusRequest,
) (*wal.WALStatusResult, error) {
// TODO implement me
panic("implement me")
}
func (w WALServiceImplementation) SetFirstRequired(ctx context.Context, request *wal.SetFirstRequiredRequest) (*wal.SetFirstRequiredResult, error) {
// SetFirstRequired implements the WALService interface
func (w WALServiceImplementation) SetFirstRequired(
_ context.Context,
_ *wal.SetFirstRequiredRequest,
) (*wal.SetFirstRequiredResult, error) {
// TODO implement me
panic("implement me")
}
@ -325,7 +346,7 @@ func gatherWALFilesToRestore(walName string, parallel int) (walList []string, er
return walList, err
}
// ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive
// ErrEndOfWALStreamReached is returned when end of WAL is detected in the cloud archive.
var ErrEndOfWALStreamReached = errors.New("end of WAL reached")
// checkEndOfWALStreamFlag returns ErrEndOfWALStreamReached if the flag is set in the restorer.

View File

@ -75,8 +75,8 @@ var (
WALSegmentNameRe +
`$`)
// ErrorBadWALSegmentName is raised when parsing an invalid segment name.
ErrorBadWALSegmentName = errors.New("invalid WAL segment name")
// ErrBadWALSegmentName is raised when parsing an invalid segment name.
ErrBadWALSegmentName = errors.New("invalid WAL segment name")
)
// Segment contains the information inside a WAL segment name.
@ -109,23 +109,23 @@ func SegmentFromName(name string) (Segment, error) {
// We could have used WALSegmentRe directly, but we wanted to adhere to barman code
subMatches := WALRe.FindStringSubmatch(baseName)
if len(subMatches) != 4 {
return Segment{}, ErrorBadWALSegmentName
return Segment{}, ErrBadWALSegmentName
}
if len(subMatches[0]) != 24 {
return Segment{}, ErrorBadWALSegmentName
return Segment{}, ErrBadWALSegmentName
}
if tli, err = strconv.ParseInt(subMatches[1], 16, 32); err != nil {
return Segment{}, ErrorBadWALSegmentName
return Segment{}, ErrBadWALSegmentName
}
if log, err = strconv.ParseInt(subMatches[2], 16, 32); err != nil {
return Segment{}, ErrorBadWALSegmentName
return Segment{}, ErrBadWALSegmentName
}
if seg, err = strconv.ParseInt(subMatches[3], 16, 32); err != nil {
return Segment{}, ErrorBadWALSegmentName
return Segment{}, ErrBadWALSegmentName
}
return Segment{

View File

@ -2,6 +2,7 @@ package operator
import "github.com/cloudnative-pg/cnpg-i/pkg/identity"
// PluginName is the name of this plugin
const PluginName = "operator.barman-cloud.cloudnative-pg.io"
// Data is the metadata of this plugin.

View File

@ -0,0 +1,2 @@
// Package operator implements the capabilities used by CNPG
package operator

View File

@ -6,10 +6,13 @@ import (
"github.com/cloudnative-pg/cnpg-i/pkg/identity"
)
// IdentityImplementation is the implementation of the CNPG-i
// Identity entrypoint
type IdentityImplementation struct {
identity.UnimplementedIdentityServer
}
// GetPluginMetadata implements Identity
func (i IdentityImplementation) GetPluginMetadata(
_ context.Context,
_ *identity.GetPluginMetadataRequest,
@ -17,6 +20,7 @@ func (i IdentityImplementation) GetPluginMetadata(
return &Data, nil
}
// GetPluginCapabilities implements identity
func (i IdentityImplementation) GetPluginCapabilities(
_ context.Context,
_ *identity.GetPluginCapabilitiesRequest,
@ -41,6 +45,7 @@ func (i IdentityImplementation) GetPluginCapabilities(
}, nil
}
// Probe implements Identity
func (i IdentityImplementation) Probe(
_ context.Context,
_ *identity.ProbeRequest,

View File

@ -6,10 +6,12 @@ import (
"github.com/cloudnative-pg/cnpg-i/pkg/reconciler"
)
// ReconcilerImplementation implements the Reconciler capability
type ReconcilerImplementation struct {
reconciler.UnimplementedReconcilerHooksServer
}
// GetCapabilities implements the Reconciler interface
func (r ReconcilerImplementation) GetCapabilities(
_ context.Context,
_ *reconciler.ReconcilerHooksCapabilitiesRequest,
@ -26,6 +28,7 @@ func (r ReconcilerImplementation) GetCapabilities(
}, nil
}
// Pre implements the reconciler interface
func (r ReconcilerImplementation) Pre(
_ context.Context,
_ *reconciler.ReconcilerHooksRequest,
@ -35,6 +38,7 @@ func (r ReconcilerImplementation) Pre(
}, nil
}
// Post implements the reconciler interface
func (r ReconcilerImplementation) Post(
_ context.Context,
_ *reconciler.ReconcilerHooksRequest,

View File

@ -9,8 +9,10 @@ import (
"google.golang.org/grpc"
)
// CNPGI is the implementation of the Operator plugin
type CNPGI struct{}
// Start starts the GRPC server
func (c *CNPGI) Start(ctx context.Context) error {
cmd := http.CreateMainCmd(IdentityImplementation{}, func(server *grpc.Server) error {
// Register the declared implementations

View File

@ -0,0 +1,3 @@
// Package controller implements a controller for the CRDs as defined
// by this operator
package controller