feat: add logLevel

Add the support to set the logLevel through a typed field

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
Armando Ruocco 2025-09-18 11:51:38 +02:00 committed by Leonardo Cecchi
parent 77aa6e04ff
commit 912bcfeab4
8 changed files with 121 additions and 4 deletions

View File

@ -13,6 +13,7 @@ DigitalOcean
Docusaurus
EDB
EKS
Enum
EnvVar
GCP
GKE

View File

@ -41,8 +41,15 @@ type InstanceSidecarConfiguration struct {
// AdditionalContainerArgs is an optional list of command-line arguments
// to be passed to the sidecar container when it starts.
// The provided arguments are appended to the containers 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
AdditionalContainerArgs []string `json:"additionalContainerArgs,omitempty"`
// The instances' log level, one of the following values: 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.

View File

@ -399,6 +399,11 @@ spec:
items:
type: string
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:
description: The environment to be explicitly passed to the sidecar
items:
@ -557,6 +562,17 @@ spec:
- name
type: object
type: array
logLevel:
default: info
description: 'The instances'' log level, one of the following
values: error, warning, info (default), debug, trace'
enum:
- error
- warning
- info
- debug
- trace
type: string
resources:
description: Resources define cpu/memory requests and limits for
the sidecar that runs in the instance pods.

View File

@ -5,6 +5,7 @@ metadata:
spec:
retentionPolicy: "1m"
instanceSidecarConfiguration:
logLevel: "debug"
retentionPolicyIntervalSeconds: 1800
resources:
requests:
@ -13,8 +14,6 @@ spec:
limits:
memory: "512Mi"
cpu: "500m"
additionalContainerArgs:
- --log-level=debug
configuration:
endpointCA:
name: minio-server-tls

View File

@ -236,6 +236,19 @@ func (impl LifecycleImplementation) collectAdditionalInstanceArgs(
ctx context.Context,
pluginConfiguration *config.PluginConfiguration,
) ([]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.
// If neither is configured, no additional args are provided.
if len(pluginConfiguration.BarmanObjectName) > 0 {
@ -244,7 +257,12 @@ func (impl LifecycleImplementation) collectAdditionalInstanceArgs(
return nil, fmt.Errorf("while getting barman object store %s: %w",
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 {
@ -253,7 +271,12 @@ func (impl LifecycleImplementation) collectAdditionalInstanceArgs(
return nil, fmt.Errorf("while getting recovery barman object store %s: %w",
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

View File

@ -313,6 +313,60 @@ var _ = Describe("LifecycleImplementation", func() {
Expect(err.Error()).To(ContainSubstring(ns + "/" + pc.RecoveryBarmanObjectName))
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"}))
})
})
})

View File

@ -398,6 +398,11 @@ spec:
items:
type: string
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:
description: The environment to be explicitly passed to the sidecar
items:
@ -556,6 +561,17 @@ spec:
- name
type: object
type: array
logLevel:
default: info
description: 'The instances'' log level, one of the following
values: error, warning, info (default), debug, trace'
enum:
- error
- warning
- info
- debug
- trace
type: string
resources:
description: Resources define cpu/memory requests and limits for
the sidecar that runs in the instance pods.

View File

@ -30,6 +30,7 @@ _Appears in:_
| `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. | | | |
| `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 containers default arguments. | | | |
| `logLevel` _string_ | The instances' log level, one of the following values: error, warning, info (default), debug, trace | | info | Enum: [error warning info debug trace] <br /> |
#### ObjectStore