Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Add the `config.containerdebug` field to roles and role groups ([#211]).

[#211]: https://github.com/stackabletech/opensearch-operator/pull/211

## [26.11.0] - 2026-11-20

## [26.11.0-rc1] - 2026-11-19
Expand Down
4 changes: 4 additions & 0 deletions docs/modules/opensearch/pages/usage-guide/logging.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ spec:
vectorAggregatorConfigMapName: vector-aggregator-discovery
nodes:
config:
containerdebug:
enabled: false
logging:
enableVectorAgent: true
containers:
Expand Down Expand Up @@ -39,4 +41,6 @@ Overriding `FILE_LOG_DIRECTORY` with `envOverrides` therefore changes how these
The agent only collects files one level below `/stackable/log`, so a sibling directory such as `/stackable/log/opensearch` relabels the events instead of dropping them, while any deeper or shallower path stops the aggregation.
A path outside `/stackable/log` also leaves the size-capped log volume.

The `containerdebug` process can be configured or turned off per role and role group, as described in xref:concepts:observability/containerdebug.adoc#configuration[].

Further information on how to configure logging, can be found in xref:concepts:logging.adoc[].
40 changes: 40 additions & 0 deletions extra/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,26 @@ spec:
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
containerdebug:
default:
enabled: null
interval: null
description: |-
Configures the `containerdebug` tool, which periodically logs information about the container
environment (such as network interfaces, DNS lookups and disk usage) in the background of the
product container.
properties:
enabled:
description: Whether `containerdebug` runs in the background of the product container. Defaults to `true`.
nullable: true
type: boolean
interval:
description: |-
Time between two runs of `containerdebug`, e.g. `30m`, `1h` or `2d`. Must not be zero.
Defaults to `30m`.
nullable: true
type: string
type: object
discoveryServiceExposed:
description: Determines whether this role group is exposed in the discovery service.
nullable: true
Expand Down Expand Up @@ -2069,6 +2089,26 @@ spec:
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
containerdebug:
default:
enabled: null
interval: null
description: |-
Configures the `containerdebug` tool, which periodically logs information about the container
environment (such as network interfaces, DNS lookups and disk usage) in the background of the
product container.
properties:
enabled:
description: Whether `containerdebug` runs in the background of the product container. Defaults to `true`.
nullable: true
type: boolean
interval:
description: |-
Time between two runs of `containerdebug`, e.g. `30m`, `1h` or `2d`. Must not be zero.
Defaults to `30m`.
nullable: true
type: string
type: object
discoveryServiceExposed:
description: Determines whether this role group is exposed in the discovery service.
nullable: true
Expand Down
4 changes: 3 additions & 1 deletion rust/operator-binary/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use stackable_operator::{
product_image_selection::ResolvedProductImage,
},
constant,
crd::listener,
crd::{containerdebug::ValidatedContainerdebugConfig, listener},
k8s_openapi::api::{
apps::v1::StatefulSet,
core::v1::{ConfigMap, Service, ServiceAccount},
Expand Down Expand Up @@ -180,6 +180,7 @@ pub struct DereferencedObjects {
#[derive(Clone, Debug, PartialEq)]
pub struct ValidatedOpenSearchConfig {
pub affinity: StackableAffinity,
pub containerdebug: ValidatedContainerdebugConfig,
pub discovery_service_exposed: bool,
pub listener_class: ListenerClassName,
pub logging: ValidatedLogging,
Expand Down Expand Up @@ -673,6 +674,7 @@ mod tests {
replicas: Some(replicas),
config: ValidatedOpenSearchConfig {
affinity: StackableAffinity::default(),
containerdebug: stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled { interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL },
discovery_service_exposed: true,
listener_class: ListenerClassName::from_str_unsafe("external-stable"),
logging: ValidatedLogging {
Expand Down
1 change: 1 addition & 0 deletions rust/operator-binary/src/controller/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ mod tests {
replicas: Some(replicas),
config: ValidatedOpenSearchConfig {
affinity: StackableAffinity::default(),
containerdebug: stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled { interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL },
discovery_service_exposed: true,
listener_class: ListenerClassName::from_str_unsafe("external-stable"),
logging: ValidatedLogging {
Expand Down
1 change: 1 addition & 0 deletions rust/operator-binary/src/controller/build/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ mod tests {
replicas: Some(test_config.replicas),
config: ValidatedOpenSearchConfig {
affinity: StackableAffinity::default(),
containerdebug: stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled { interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL },
discovery_service_exposed: true,
listener_class: ListenerClassName::from_str_unsafe("cluster-internal"),
logging: ValidatedLogging {
Expand Down
1 change: 1 addition & 0 deletions rust/operator-binary/src/controller/build/role_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ mod tests {
replicas: Some(1),
config: ValidatedOpenSearchConfig {
affinity: StackableAffinity::default(),
containerdebug: stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled { interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL },
discovery_service_exposed: true,
listener_class: ListenerClassName::from_str_unsafe("cluster-internal"),
logging: ValidatedLogging {
Expand Down
65 changes: 63 additions & 2 deletions rust/operator-binary/src/controller/build/role_group_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ impl<'a> RoleGroupBuilder<'a> {
prepare_signal_handlers\n\
if command -v containerdebug >/dev/null 2>&1; then\n\
mkdir --parents \"${file_log_directory}\" || true\n\
containerdebug --output={STACKABLE_LOG_DIR}/containerdebug-state.json --loop &\n\
{containerdebug_command}\n\
else\n\
echo >&2 \"containerdebug not installed; Proceed without it.\"\n\
fi\n\
Expand All @@ -778,6 +778,12 @@ impl<'a> RoleGroupBuilder<'a> {
{create_vector_shutdown_file_command}",
extra_args = self.role_group_config.cli_overrides_to_vec().join(" "),
file_log_directory = ENV_VAR_NAME_FILE_LOG_DIRECTORY.as_ref(),
containerdebug_command = self
.role_group_config
.config
.containerdebug
.background_command(STACKABLE_LOG_DIR)
.unwrap_or_default(),
remove_vector_shutdown_file_command =
remove_vector_shutdown_file_command(STACKABLE_LOG_DIR),
create_vector_shutdown_file_command =
Expand Down Expand Up @@ -1561,6 +1567,7 @@ mod tests {
replicas: Some(1),
config: ValidatedOpenSearchConfig {
affinity: StackableAffinity::default(),
containerdebug: stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled { interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL },
discovery_service_exposed: true,
listener_class: ListenerClassName::from_str_unsafe("cluster-internal"),
logging: ValidatedLogging {
Expand Down Expand Up @@ -1763,6 +1770,60 @@ mod tests {
);
}

/// The opensearch container starts `containerdebug` from the role group's validated config.
/// The command itself is owned (and tested) by operator-rs, so only the wiring is checked here.
#[rstest]
#[case::enabled(
stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled {
interval: Duration::from_minutes_unchecked(10)
}
)]
#[case::disabled(
stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Disabled
)]
fn test_build_stateful_set_starts_containerdebug_from_config(
#[case] containerdebug: stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig,
) {
let expected = containerdebug.background_command(
stackable_operator::v2::product_logging::framework::STACKABLE_LOG_DIR,
);
let mut cluster = validated_cluster(TestSecurityMode::Disabled);
cluster
.role_group_configs
.values_mut()
.next()
.expect("should contain a role group")
.config
.containerdebug = containerdebug;
let context_names = context_names();
let role_group_builder = role_group_builder(&cluster, &context_names);

let args = role_group_builder
.build_stateful_set()
.spec
.and_then(|spec| spec.template.spec)
.expect("should have a pod spec")
.containers
.into_iter()
.find(|container| {
container.name
== v1alpha1::Container::OpenSearch
.to_container_name()
.to_string()
})
.and_then(|container| container.args)
.expect("the opensearch container should have args")
.join("\n");

assert_eq!(
expected.as_deref(),
args.lines()
.map(str::trim)
.find(|line| line.starts_with("containerdebug ")),
"args: {args}"
);
}

#[rstest]
#[case::security_mode_initializing(TestSecurityMode::Initializing)]
#[case::security_mode_managing(TestSecurityMode::Managing)]
Expand Down Expand Up @@ -2083,7 +2144,7 @@ mod tests {
"prepare_signal_handlers\n",
"if command -v containerdebug >/dev/null 2>&1; then\n",
"mkdir --parents \"$FILE_LOG_DIRECTORY\" || true\n",
"containerdebug --output=/stackable/log/containerdebug-state.json --loop &\n",
"containerdebug --output=/stackable/log/containerdebug-state.json --loop=30m &\n",
"else\n",
"echo >&2 \"containerdebug not installed; Proceed without it.\"\n",
"fi\n",
Expand Down
105 changes: 103 additions & 2 deletions rust/operator-binary/src/controller/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ pub enum Error {
ValidateOpenSearchConfig {
source: stackable_operator::config::fragment::ValidationError,
},

#[snafu(display("invalid containerdebug configuration for role group {role_group}"))]
InvalidContainerdebugConfig {
source: stackable_operator::crd::containerdebug::Error,
role_group: RoleGroupName,
},
}

type Result<T, E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -162,8 +168,13 @@ pub fn validate(
let role_group_name =
RoleGroupName::from_str(raw_role_group_name).context(ParseRoleGroupNameSnafu)?;

let validated_role_group_config =
validate_role_group_config(context_names, &cluster_name, cluster, role_group_config)?;
let validated_role_group_config = validate_role_group_config(
context_names,
&cluster_name,
cluster,
&role_group_name,
role_group_config,
)?;

role_group_configs.insert(role_group_name, validated_role_group_config);
}
Expand Down Expand Up @@ -194,6 +205,7 @@ fn validate_role_group_config(
context_names: &ContextNames,
cluster_name: &ClusterName,
cluster: &v1alpha1::OpenSearchCluster,
role_group_name: &RoleGroupName,
role_group_config: &OpenSearchRoleGroup,
) -> Result<OpenSearchRoleGroupConfig> {
let merged_role_group: RoleGroup<v1alpha1::OpenSearchConfig, _, _> = with_validated_config(
Expand All @@ -207,6 +219,15 @@ fn validate_role_group_config(
)
.context(ValidateOpenSearchConfigSnafu)?;

let containerdebug = merged_role_group
.config
.config
.containerdebug
.validate()
.with_context(|_| InvalidContainerdebugConfigSnafu {
role_group: role_group_name.clone(),
})?;

let logging = validate_logging_configuration(
&merged_role_group.config.config.logging,
&cluster
Expand All @@ -226,6 +247,7 @@ fn validate_role_group_config(

let validated_config = ValidatedOpenSearchConfig {
affinity: merged_role_group.config.config.affinity,
containerdebug,
discovery_service_exposed: merged_role_group.config.config.discovery_service_exposed,
listener_class: merged_role_group.config.config.listener_class,
logging,
Expand Down Expand Up @@ -562,6 +584,7 @@ mod tests {
}),
..StackableAffinity::default()
},
containerdebug: stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled { interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL },
discovery_service_exposed: true,
listener_class: ListenerClassName::from_str_unsafe(
"listener-class-from-role-group-level"
Expand Down Expand Up @@ -849,6 +872,84 @@ mod tests {
);
}

/// A role `config` that does not mention `containerdebug` still gets the default, so the
/// `containerdebug` field of the CRD must be optional. The role config is deserialized,
/// because only then does a missing `serde(default)` show.
#[test]
fn test_validate_ok_containerdebug_defaults_when_not_configured() {
let mut cluster = cluster();
cluster.spec.nodes.config.config =
serde_json::from_value(json!({ "gracefulShutdownTimeout": "1h" }))
.expect("should be a valid role config");

let validated_cluster = validate(
&context_names(),
&operator_environment(),
&cluster,
&dereferenced_objects(),
)
.expect("should be valid");
let (_, role_group_config) = validated_cluster
.role_group_configs
.first_key_value()
.expect("should contain a role group");

assert_eq!(
stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled {
interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL
},
role_group_config.config.containerdebug
);
}

#[test]
fn test_validate_err_invalid_containerdebug_config() {
test_validate_err(
|cluster, _| {
cluster.spec.nodes.config.config.containerdebug.interval =
Some(Duration::from_secs(0))
},
ErrorDiscriminants::InvalidContainerdebugConfig,
);
}

/// An invalid `containerdebug` config names the role group it came from.
#[test]
fn test_validate_err_invalid_containerdebug_config_names_the_role_group() {
let mut cluster = cluster();
cluster.spec.nodes.config.config.containerdebug.interval = Some(Duration::from_secs(0));
let role_group_name = cluster
.spec
.nodes
.role_groups
.keys()
.next()
.expect("should contain a role group")
.to_owned();

let error = validate(
&context_names(),
&operator_environment(),
&cluster,
&dereferenced_objects(),
)
.expect_err("should be invalid");
let chain: Vec<String> =
std::iter::successors(Some(&error as &dyn std::error::Error), |error| {
error.source()
})
.map(ToString::to_string)
.collect();

assert_eq!(
vec![
format!("invalid containerdebug configuration for role group {role_group_name}"),
"the containerdebug interval must not be zero".to_owned(),
],
chain
);
}

#[test]
fn test_validate_err_termination_grace_period_too_long() {
test_validate_err(
Expand Down
Loading
Loading