mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-11 13:23:09 +01:00
chore: makes linter happy (#17)
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
This commit is contained in:
parent
cbefe26440
commit
88e8762858
146
.golangci.yml
146
.golangci.yml
@ -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
|
||||
|
||||
@ -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{
|
||||
|
||||
@ -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 (
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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.
|
||||
|
||||
2
internal/cnpgi/instance/doc.go
Normal file
2
internal/cnpgi/instance/doc.go
Normal file
@ -0,0 +1,2 @@
|
||||
// Package instance implements the capabilities used by the operator sidecar
|
||||
package instance
|
||||
@ -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,
|
||||
|
||||
@ -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{
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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{
|
||||
|
||||
@ -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.
|
||||
|
||||
2
internal/cnpgi/operator/doc.go
Normal file
2
internal/cnpgi/operator/doc.go
Normal file
@ -0,0 +1,2 @@
|
||||
// Package operator implements the capabilities used by CNPG
|
||||
package operator
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
3
internal/controller/doc.go
Normal file
3
internal/controller/doc.go
Normal file
@ -0,0 +1,3 @@
|
||||
// Package controller implements a controller for the CRDs as defined
|
||||
// by this operator
|
||||
package controller
|
||||
Loading…
Reference in New Issue
Block a user