From 127f94adafa95b49c4a4feb10ff03f3baf6a15c2 Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Thu, 5 Dec 2024 15:25:48 +0100 Subject: [PATCH] chore: linter Signed-off-by: Leonardo Cecchi --- api/v1/objectstore_types.go | 2 +- internal/cnpgi/common/errors.go | 3 +-- internal/cnpgi/common/wal.go | 4 ++-- internal/cnpgi/instance/identity.go | 2 +- internal/cnpgi/instance/internal/client/client.go | 4 ++-- internal/cnpgi/operator/config/config.go | 9 +++++++-- internal/cnpgi/operator/lifecycle.go | 3 +-- internal/cnpgi/operator/lifecycle_test.go | 8 ++++---- internal/cnpgi/operator/reconciler.go | 2 +- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/api/v1/objectstore_types.go b/api/v1/objectstore_types.go index 16fc1ba..e281269 100644 --- a/api/v1/objectstore_types.go +++ b/api/v1/objectstore_types.go @@ -24,7 +24,7 @@ import ( // InstanceSidecarConfiguration defines the configuration for the sidecar that runs in the instance pods. type InstanceSidecarConfiguration struct { - // The environment to be explicitely passed to the sidecar + // The environment to be explicitly passed to the sidecar // +optional Env []corev1.EnvVar `json:"env,omitempty"` } diff --git a/internal/cnpgi/common/errors.go b/internal/cnpgi/common/errors.go index 6e056f9..53ce085 100644 --- a/internal/cnpgi/common/errors.go +++ b/internal/cnpgi/common/errors.go @@ -1,8 +1,7 @@ package common // WALNotFoundError is raised when a WAL file has not been found in the object store -type WALNotFoundError struct { -} +type WALNotFoundError struct{} // ShouldPrintStackTrace tells whether the sidecar log stream should contain the stack trace func (e WALNotFoundError) ShouldPrintStackTrace() bool { diff --git a/internal/cnpgi/common/wal.go b/internal/cnpgi/common/wal.go index d532e0e..412fed3 100644 --- a/internal/cnpgi/common/wal.go +++ b/internal/cnpgi/common/wal.go @@ -242,9 +242,9 @@ func (w WALServiceImplementation) restoreFromBarmanObjectStore( if walStatus[0].Err != nil { if errors.Is(walStatus[0].Err, barmanRestorer.ErrWALNotFound) { return WALNotFoundError{} - } else { - return walStatus[0].Err } + + return walStatus[0].Err } // We skip this step if streaming connection is not available diff --git a/internal/cnpgi/instance/identity.go b/internal/cnpgi/instance/identity.go index d156e69..ef9c845 100644 --- a/internal/cnpgi/instance/identity.go +++ b/internal/cnpgi/instance/identity.go @@ -50,7 +50,7 @@ func (i IdentityImplementation) GetPluginCapabilities( // Probe implements IdentityServer func (i IdentityImplementation) Probe( - ctx context.Context, + _ context.Context, _ *identity.ProbeRequest, ) (*identity.ProbeResponse, error) { return &identity.ProbeResponse{ diff --git a/internal/cnpgi/instance/internal/client/client.go b/internal/cnpgi/instance/internal/client/client.go index e3d45b0..6b5dbd3 100644 --- a/internal/cnpgi/instance/internal/client/client.go +++ b/internal/cnpgi/instance/internal/client/client.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// The default TTL in seconds of cache entries +// DefaultTTLSeconds is the default TTL in seconds of cache entries const DefaultTTLSeconds = 10 type cachedEntry struct { @@ -114,7 +114,7 @@ func (e *ExtendedClient) getCachedObject( return nil } - if err := e.Client.Get(ctx, key, obj); err != nil { + if err := e.Client.Get(ctx, key, obj, opts...); err != nil { return err } diff --git a/internal/cnpgi/operator/config/config.go b/internal/cnpgi/operator/config/config.go index 944aafa..8380886 100644 --- a/internal/cnpgi/operator/config/config.go +++ b/internal/cnpgi/operator/config/config.go @@ -59,6 +59,7 @@ type PluginConfiguration struct { ReplicaSourceServerName string } +// GetBarmanObjectKey gets the namespaced name of the barman object func (config *PluginConfiguration) GetBarmanObjectKey() types.NamespacedName { return types.NamespacedName{ Namespace: config.Cluster.Namespace, @@ -66,6 +67,7 @@ func (config *PluginConfiguration) GetBarmanObjectKey() types.NamespacedName { } } +// GetRecoveryBarmanObjectKey gets the namespaced name of the recovery barman object func (config *PluginConfiguration) GetRecoveryBarmanObjectKey() types.NamespacedName { return types.NamespacedName{ Namespace: config.Cluster.Namespace, @@ -73,6 +75,7 @@ func (config *PluginConfiguration) GetRecoveryBarmanObjectKey() types.Namespaced } } +// GetReplicaSourceBarmanObjectKey gets the namespaced name of the replica source barman object func (config *PluginConfiguration) GetReplicaSourceBarmanObjectKey() types.NamespacedName { return types.NamespacedName{ Namespace: config.Cluster.Namespace, @@ -80,6 +83,8 @@ func (config *PluginConfiguration) GetReplicaSourceBarmanObjectKey() types.Names } } +// GetReferredBarmanObjectsKey gets the list of barman objects referred by this +// plugin configuration func (config *PluginConfiguration) GetReferredBarmanObjectsKey() []types.NamespacedName { result := make([]types.NamespacedName, 0, 3) @@ -237,10 +242,10 @@ func getReplicaSourcePlugin(cluster *cnpgv1.Cluster) *cnpgv1.PluginConfiguration } // Validate checks if the barmanObjectName is set -func (p *PluginConfiguration) Validate() error { +func (config *PluginConfiguration) Validate() error { err := NewConfigurationError() - if len(p.BarmanObjectName) == 0 && len(p.RecoveryBarmanObjectName) == 0 { + if len(config.BarmanObjectName) == 0 && len(config.RecoveryBarmanObjectName) == 0 { return err.WithMessage("no reference to barmanObjectName have been included") } diff --git a/internal/cnpgi/operator/lifecycle.go b/internal/cnpgi/operator/lifecycle.go index 170b67c..736b1d7 100644 --- a/internal/cnpgi/operator/lifecycle.go +++ b/internal/cnpgi/operator/lifecycle.go @@ -168,14 +168,13 @@ func (impl LifecycleImplementation) reconcileJob( return nil, nil } - return reconcileJob(ctx, cluster, request, pluginConfiguration, env) + return reconcileJob(ctx, cluster, request, env) } func reconcileJob( ctx context.Context, cluster *cnpgv1.Cluster, request *lifecycle.OperatorLifecycleRequest, - pluginConfiguration *config.PluginConfiguration, env []corev1.EnvVar, ) (*lifecycle.OperatorLifecycleResponse, error) { contextLogger := log.FromContext(ctx).WithName("lifecycle") diff --git a/internal/cnpgi/operator/lifecycle_test.go b/internal/cnpgi/operator/lifecycle_test.go index 29285eb..a8b964b 100644 --- a/internal/cnpgi/operator/lifecycle_test.go +++ b/internal/cnpgi/operator/lifecycle_test.go @@ -107,7 +107,7 @@ var _ = Describe("LifecycleImplementation", func() { ObjectDefinition: jobJSON, } - response, err := reconcileJob(ctx, cluster, request, pluginConfiguration, nil) + response, err := reconcileJob(ctx, cluster, request, nil) Expect(err).NotTo(HaveOccurred()) Expect(response).NotTo(BeNil()) Expect(response.JsonPatch).NotTo(BeEmpty()) @@ -128,7 +128,7 @@ var _ = Describe("LifecycleImplementation", func() { ObjectDefinition: jobJSON, } - response, err := reconcileJob(ctx, cluster, request, pluginConfiguration, nil) + response, err := reconcileJob(ctx, cluster, request, nil) Expect(err).NotTo(HaveOccurred()) Expect(response).To(BeNil()) }) @@ -138,7 +138,7 @@ var _ = Describe("LifecycleImplementation", func() { ObjectDefinition: []byte("invalid-json"), } - response, err := reconcileJob(ctx, cluster, request, pluginConfiguration, nil) + response, err := reconcileJob(ctx, cluster, request, nil) Expect(err).To(HaveOccurred()) Expect(response).To(BeNil()) }) @@ -165,7 +165,7 @@ var _ = Describe("LifecycleImplementation", func() { ObjectDefinition: jobJSON, } - response, err := reconcileJob(ctx, cluster, request, pluginConfiguration, nil) + response, err := reconcileJob(ctx, cluster, request, nil) Expect(err).NotTo(HaveOccurred()) Expect(response).To(BeNil()) }) diff --git a/internal/cnpgi/operator/reconciler.go b/internal/cnpgi/operator/reconciler.go index 0a57036..67a96c4 100644 --- a/internal/cnpgi/operator/reconciler.go +++ b/internal/cnpgi/operator/reconciler.go @@ -75,7 +75,7 @@ func (r ReconcilerImplementation) Pre( contextLogger.Debug("parsing barman object configuration") - var barmanObjects []barmancloudv1.ObjectStore + barmanObjects := make([]barmancloudv1.ObjectStore, 0, len(pluginConfiguration.GetReferredBarmanObjectsKey())) for _, barmanObjectKey := range pluginConfiguration.GetReferredBarmanObjectsKey() { var barmanObject barmancloudv1.ObjectStore if err := r.Client.Get(ctx, barmanObjectKey, &barmanObject); err != nil {