mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-11 13:23:09 +01:00
feat: introduce logLevel setting to control verbosity (#536)
This commit adds a new `logLevel` field to the plugin configuration, allowing users to select the desired log verbosity for the instances (e.g. error, warning, info, debug, trace). Closes #514 Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com> Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
This commit is contained in:
parent
77aa6e04ff
commit
0501e185ba
@ -13,6 +13,7 @@ DigitalOcean
|
|||||||
Docusaurus
|
Docusaurus
|
||||||
EDB
|
EDB
|
||||||
EKS
|
EKS
|
||||||
|
Enum
|
||||||
EnvVar
|
EnvVar
|
||||||
GCP
|
GCP
|
||||||
GKE
|
GKE
|
||||||
|
|||||||
@ -41,8 +41,15 @@ type InstanceSidecarConfiguration struct {
|
|||||||
// AdditionalContainerArgs is an optional list of command-line arguments
|
// AdditionalContainerArgs is an optional list of command-line arguments
|
||||||
// to be passed to the sidecar container when it starts.
|
// to be passed to the sidecar container when it starts.
|
||||||
// The provided arguments are appended to the container’s default arguments.
|
// The provided arguments are appended to the container’s default arguments.
|
||||||
|
// +kubebuilder:validation:XValidation:rule="!self.exists(a, a.startsWith('--log-level'))",reason="FieldValueForbidden",message="do not set --log-level in additionalContainerArgs; use spec.instanceSidecarConfiguration.logLevel"
|
||||||
// +optional
|
// +optional
|
||||||
AdditionalContainerArgs []string `json:"additionalContainerArgs,omitempty"`
|
AdditionalContainerArgs []string `json:"additionalContainerArgs,omitempty"`
|
||||||
|
|
||||||
|
// The log level for PostgreSQL instances. Valid values are: `error`, `warning`, `info` (default), `debug`, `trace`
|
||||||
|
// +kubebuilder:default:=info
|
||||||
|
// +kubebuilder:validation:Enum:=error;warning;info;debug;trace
|
||||||
|
// +optional
|
||||||
|
LogLevel string `json:"logLevel,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectStoreSpec defines the desired state of ObjectStore.
|
// ObjectStoreSpec defines the desired state of ObjectStore.
|
||||||
|
|||||||
@ -399,6 +399,11 @@ spec:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
|
x-kubernetes-validations:
|
||||||
|
- message: do not set --log-level in additionalContainerArgs;
|
||||||
|
use spec.instanceSidecarConfiguration.logLevel
|
||||||
|
reason: FieldValueForbidden
|
||||||
|
rule: '!self.exists(a, a.startsWith(''--log-level''))'
|
||||||
env:
|
env:
|
||||||
description: The environment to be explicitly passed to the sidecar
|
description: The environment to be explicitly passed to the sidecar
|
||||||
items:
|
items:
|
||||||
@ -557,6 +562,17 @@ spec:
|
|||||||
- name
|
- name
|
||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
|
logLevel:
|
||||||
|
default: info
|
||||||
|
description: 'The log level for PostgreSQL instances. Valid values
|
||||||
|
are: `error`, `warning`, `info` (default), `debug`, `trace`'
|
||||||
|
enum:
|
||||||
|
- error
|
||||||
|
- warning
|
||||||
|
- info
|
||||||
|
- debug
|
||||||
|
- trace
|
||||||
|
type: string
|
||||||
resources:
|
resources:
|
||||||
description: Resources define cpu/memory requests and limits for
|
description: Resources define cpu/memory requests and limits for
|
||||||
the sidecar that runs in the instance pods.
|
the sidecar that runs in the instance pods.
|
||||||
|
|||||||
@ -5,6 +5,7 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
retentionPolicy: "1m"
|
retentionPolicy: "1m"
|
||||||
instanceSidecarConfiguration:
|
instanceSidecarConfiguration:
|
||||||
|
logLevel: "debug"
|
||||||
retentionPolicyIntervalSeconds: 1800
|
retentionPolicyIntervalSeconds: 1800
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
@ -13,8 +14,6 @@ spec:
|
|||||||
limits:
|
limits:
|
||||||
memory: "512Mi"
|
memory: "512Mi"
|
||||||
cpu: "500m"
|
cpu: "500m"
|
||||||
additionalContainerArgs:
|
|
||||||
- --log-level=debug
|
|
||||||
configuration:
|
configuration:
|
||||||
endpointCA:
|
endpointCA:
|
||||||
name: minio-server-tls
|
name: minio-server-tls
|
||||||
|
|||||||
@ -236,6 +236,19 @@ func (impl LifecycleImplementation) collectAdditionalInstanceArgs(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
pluginConfiguration *config.PluginConfiguration,
|
pluginConfiguration *config.PluginConfiguration,
|
||||||
) ([]string, error) {
|
) ([]string, error) {
|
||||||
|
collectTypedAdditionalArgs := func(store *barmancloudv1.ObjectStore) []string {
|
||||||
|
if store == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var args []string
|
||||||
|
if len(store.Spec.InstanceSidecarConfiguration.LogLevel) > 0 {
|
||||||
|
args = append(args, fmt.Sprintf("--log-level=%s", store.Spec.InstanceSidecarConfiguration.LogLevel))
|
||||||
|
}
|
||||||
|
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
// Prefer the cluster object store (backup/archive). If not set, fallback to the recovery object store.
|
// Prefer the cluster object store (backup/archive). If not set, fallback to the recovery object store.
|
||||||
// If neither is configured, no additional args are provided.
|
// If neither is configured, no additional args are provided.
|
||||||
if len(pluginConfiguration.BarmanObjectName) > 0 {
|
if len(pluginConfiguration.BarmanObjectName) > 0 {
|
||||||
@ -244,7 +257,12 @@ func (impl LifecycleImplementation) collectAdditionalInstanceArgs(
|
|||||||
return nil, fmt.Errorf("while getting barman object store %s: %w",
|
return nil, fmt.Errorf("while getting barman object store %s: %w",
|
||||||
pluginConfiguration.GetBarmanObjectKey().String(), err)
|
pluginConfiguration.GetBarmanObjectKey().String(), err)
|
||||||
}
|
}
|
||||||
return barmanObjectStore.Spec.InstanceSidecarConfiguration.AdditionalContainerArgs, nil
|
args := barmanObjectStore.Spec.InstanceSidecarConfiguration.AdditionalContainerArgs
|
||||||
|
args = append(
|
||||||
|
args,
|
||||||
|
collectTypedAdditionalArgs(&barmanObjectStore)...,
|
||||||
|
)
|
||||||
|
return args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(pluginConfiguration.RecoveryBarmanObjectName) > 0 {
|
if len(pluginConfiguration.RecoveryBarmanObjectName) > 0 {
|
||||||
@ -253,7 +271,12 @@ func (impl LifecycleImplementation) collectAdditionalInstanceArgs(
|
|||||||
return nil, fmt.Errorf("while getting recovery barman object store %s: %w",
|
return nil, fmt.Errorf("while getting recovery barman object store %s: %w",
|
||||||
pluginConfiguration.GetRecoveryBarmanObjectKey().String(), err)
|
pluginConfiguration.GetRecoveryBarmanObjectKey().String(), err)
|
||||||
}
|
}
|
||||||
return barmanObjectStore.Spec.InstanceSidecarConfiguration.AdditionalContainerArgs, nil
|
args := barmanObjectStore.Spec.InstanceSidecarConfiguration.AdditionalContainerArgs
|
||||||
|
args = append(
|
||||||
|
args,
|
||||||
|
collectTypedAdditionalArgs(&barmanObjectStore)...,
|
||||||
|
)
|
||||||
|
return args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|||||||
@ -313,6 +313,60 @@ var _ = Describe("LifecycleImplementation", func() {
|
|||||||
Expect(err.Error()).To(ContainSubstring(ns + "/" + pc.RecoveryBarmanObjectName))
|
Expect(err.Error()).To(ContainSubstring(ns + "/" + pc.RecoveryBarmanObjectName))
|
||||||
Expect(args).To(BeNil())
|
Expect(args).To(BeNil())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("includes --log-level from primary object store when set", func(ctx SpecContext) {
|
||||||
|
ns := "test-ns"
|
||||||
|
cluster := &cnpgv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "c", Namespace: ns}}
|
||||||
|
pc := &config.PluginConfiguration{
|
||||||
|
Cluster: cluster,
|
||||||
|
BarmanObjectName: "primary-store",
|
||||||
|
}
|
||||||
|
store := &barmancloudv1.ObjectStore{
|
||||||
|
TypeMeta: metav1.TypeMeta{Kind: "ObjectStore", APIVersion: barmancloudv1.GroupVersion.String()},
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: pc.BarmanObjectName, Namespace: ns},
|
||||||
|
Spec: barmancloudv1.ObjectStoreSpec{
|
||||||
|
InstanceSidecarConfiguration: barmancloudv1.InstanceSidecarConfiguration{
|
||||||
|
AdditionalContainerArgs: []string{"--alpha"},
|
||||||
|
LogLevel: "debug",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
s := runtime.NewScheme()
|
||||||
|
_ = barmancloudv1.AddToScheme(s)
|
||||||
|
cli := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(store).Build()
|
||||||
|
|
||||||
|
impl := LifecycleImplementation{Client: cli}
|
||||||
|
args, err := impl.collectAdditionalInstanceArgs(ctx, pc)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(args).To(Equal([]string{"--alpha", "--log-level=debug"}))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("includes --log-level from recovery object store when primary not set", func(ctx SpecContext) {
|
||||||
|
ns := "test-ns"
|
||||||
|
cluster := &cnpgv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "c", Namespace: ns}}
|
||||||
|
pc := &config.PluginConfiguration{
|
||||||
|
Cluster: cluster,
|
||||||
|
BarmanObjectName: "",
|
||||||
|
RecoveryBarmanObjectName: "reco-store",
|
||||||
|
}
|
||||||
|
store := &barmancloudv1.ObjectStore{
|
||||||
|
TypeMeta: metav1.TypeMeta{Kind: "ObjectStore", APIVersion: barmancloudv1.GroupVersion.String()},
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: pc.RecoveryBarmanObjectName, Namespace: ns},
|
||||||
|
Spec: barmancloudv1.ObjectStoreSpec{
|
||||||
|
InstanceSidecarConfiguration: barmancloudv1.InstanceSidecarConfiguration{
|
||||||
|
LogLevel: "info",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
s := runtime.NewScheme()
|
||||||
|
_ = barmancloudv1.AddToScheme(s)
|
||||||
|
cli := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(store).Build()
|
||||||
|
|
||||||
|
impl := LifecycleImplementation{Client: cli}
|
||||||
|
args, err := impl.collectAdditionalInstanceArgs(ctx, pc)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(args).To(Equal([]string{"--log-level=info"}))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -398,6 +398,11 @@ spec:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
|
x-kubernetes-validations:
|
||||||
|
- message: do not set --log-level in additionalContainerArgs;
|
||||||
|
use spec.instanceSidecarConfiguration.logLevel
|
||||||
|
reason: FieldValueForbidden
|
||||||
|
rule: '!self.exists(a, a.startsWith(''--log-level''))'
|
||||||
env:
|
env:
|
||||||
description: The environment to be explicitly passed to the sidecar
|
description: The environment to be explicitly passed to the sidecar
|
||||||
items:
|
items:
|
||||||
@ -556,6 +561,17 @@ spec:
|
|||||||
- name
|
- name
|
||||||
type: object
|
type: object
|
||||||
type: array
|
type: array
|
||||||
|
logLevel:
|
||||||
|
default: info
|
||||||
|
description: 'The log level for PostgreSQL instances. Valid values
|
||||||
|
are: `error`, `warning`, `info` (default), `debug`, `trace`'
|
||||||
|
enum:
|
||||||
|
- error
|
||||||
|
- warning
|
||||||
|
- info
|
||||||
|
- debug
|
||||||
|
- trace
|
||||||
|
type: string
|
||||||
resources:
|
resources:
|
||||||
description: Resources define cpu/memory requests and limits for
|
description: Resources define cpu/memory requests and limits for
|
||||||
the sidecar that runs in the instance pods.
|
the sidecar that runs in the instance pods.
|
||||||
|
|||||||
@ -30,6 +30,7 @@ _Appears in:_
|
|||||||
| `retentionPolicyIntervalSeconds` _integer_ | The retentionCheckInterval defines the frequency at which the<br />system checks and enforces retention policies. | | 1800 | |
|
| `retentionPolicyIntervalSeconds` _integer_ | The retentionCheckInterval defines the frequency at which the<br />system checks and enforces retention policies. | | 1800 | |
|
||||||
| `resources` _[ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#resourcerequirements-v1-core)_ | Resources define cpu/memory requests and limits for the sidecar that runs in the instance pods. | | | |
|
| `resources` _[ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#resourcerequirements-v1-core)_ | Resources define cpu/memory requests and limits for the sidecar that runs in the instance pods. | | | |
|
||||||
| `additionalContainerArgs` _string array_ | AdditionalContainerArgs is an optional list of command-line arguments<br />to be passed to the sidecar container when it starts.<br />The provided arguments are appended to the container’s default arguments. | | | |
|
| `additionalContainerArgs` _string array_ | AdditionalContainerArgs is an optional list of command-line arguments<br />to be passed to the sidecar container when it starts.<br />The provided arguments are appended to the container’s default arguments. | | | |
|
||||||
|
| `logLevel` _string_ | The log level for PostgreSQL instances. Valid values are: `error`, `warning`, `info` (default), `debug`, `trace` | | info | Enum: [error warning info debug trace] <br /> |
|
||||||
|
|
||||||
|
|
||||||
#### ObjectStore
|
#### ObjectStore
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user