Skip to content

Commit 950fbf5

Browse files
committed
feat: add loglevel
Signed-off-by: Armando Ruocco <[email protected]>
1 parent 6a7589a commit 950fbf5

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

api/v1/objectstore_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@ type InstanceSidecarConfiguration struct {
4141
// AdditionalContainerArgs is an optional list of command-line arguments
4242
// to be passed to the sidecar container when it starts.
4343
// The provided arguments are appended to the container’s default arguments.
44+
// +kubebuilder:validation:XValidation:rule="self == null || self.all(a, !a.matches('^--log-level($|=.*)'))",reason="FieldValueForbidden",message="use spec.instanceSidecarConfiguration.logLevel instead of --log-level in additionalContainerArgs"
4445
// +optional
4546
AdditionalContainerArgs []string `json:"additionalContainerArgs,omitempty"`
47+
48+
// The instances' log level, one of the following values: error, warning, info (default), debug, trace
49+
// +kubebuilder:default:=info
50+
// +kubebuilder:validation:Enum:=error;warning;info;debug;trace
51+
// +optional
52+
LogLevel string `json:"logLevel,omitempty"`
4653
}
4754

4855
// ObjectStoreSpec defines the desired state of ObjectStore.

config/crd/bases/barmancloud.cnpg.io_objectstores.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ spec:
399399
items:
400400
type: string
401401
type: array
402+
x-kubernetes-validations:
403+
- message: use spec.instanceSidecarConfiguration.logLevel instead
404+
of --log-level in additionalContainerArgs
405+
reason: FieldValueForbidden
406+
rule: self == null || self.all(a, !a.matches('^--log-level($|=.*)'))
402407
env:
403408
description: The environment to be explicitly passed to the sidecar
404409
items:
@@ -519,6 +524,17 @@ spec:
519524
- name
520525
type: object
521526
type: array
527+
logLevel:
528+
default: info
529+
description: 'The instances'' log level, one of the following
530+
values: error, warning, info (default), debug, trace'
531+
enum:
532+
- error
533+
- warning
534+
- info
535+
- debug
536+
- trace
537+
type: string
522538
resources:
523539
description: Resources define cpu/memory requests and limits for
524540
the sidecar that runs in the instance pods.

internal/cnpgi/operator/lifecycle.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ func (impl LifecycleImplementation) collectAdditionalInstanceArgs(
236236
ctx context.Context,
237237
pluginConfiguration *config.PluginConfiguration,
238238
) ([]string, error) {
239+
collectTypedAdditionalArgs := func(store *barmancloudv1.ObjectStore) []string {
240+
var args []string
241+
if len(store.Spec.InstanceSidecarConfiguration.LogLevel) > 0 {
242+
args = append(args, "--log-level", store.Spec.InstanceSidecarConfiguration.LogLevel)
243+
}
244+
245+
return args
246+
}
247+
239248
// Prefer the cluster object store (backup/archive). If not set, fallback to the recovery object store.
240249
// If neither is configured, no additional args are provided.
241250
if len(pluginConfiguration.BarmanObjectName) > 0 {
@@ -244,7 +253,11 @@ func (impl LifecycleImplementation) collectAdditionalInstanceArgs(
244253
return nil, fmt.Errorf("while getting barman object store %s: %w",
245254
pluginConfiguration.GetBarmanObjectKey().String(), err)
246255
}
247-
return barmanObjectStore.Spec.InstanceSidecarConfiguration.AdditionalContainerArgs, nil
256+
args := append(
257+
barmanObjectStore.Spec.InstanceSidecarConfiguration.AdditionalContainerArgs,
258+
collectTypedAdditionalArgs(&barmanObjectStore)...,
259+
)
260+
return args, nil
248261
}
249262

250263
if len(pluginConfiguration.RecoveryBarmanObjectName) > 0 {
@@ -253,7 +266,11 @@ func (impl LifecycleImplementation) collectAdditionalInstanceArgs(
253266
return nil, fmt.Errorf("while getting recovery barman object store %s: %w",
254267
pluginConfiguration.GetRecoveryBarmanObjectKey().String(), err)
255268
}
256-
return barmanObjectStore.Spec.InstanceSidecarConfiguration.AdditionalContainerArgs, nil
269+
args := append(
270+
barmanObjectStore.Spec.InstanceSidecarConfiguration.AdditionalContainerArgs,
271+
collectTypedAdditionalArgs(&barmanObjectStore)...,
272+
)
273+
return args, nil
257274
}
258275

259276
return nil, nil

0 commit comments

Comments
 (0)