From 14c79cab900552ad8dbb76ba23535fd894491fe3 Mon Sep 17 00:00:00 2001 From: Maxi Wittich Date: Mon, 23 Nov 2026 15:15:00 +0100 Subject: [PATCH 1/5] Add containerdebug config, tests for defaults --- rust/operator-binary/src/controller.rs | 4 +- rust/operator-binary/src/controller/build.rs | 1 + .../src/controller/build/node_config.rs | 1 + .../src/controller/build/role_builder.rs | 1 + .../controller/build/role_group_builder.rs | 65 ++++++++++- .../src/controller/validate.rs | 105 +++++++++++++++++- rust/operator-binary/src/crd/mod.rs | 5 + 7 files changed, 177 insertions(+), 5 deletions(-) diff --git a/rust/operator-binary/src/controller.rs b/rust/operator-binary/src/controller.rs index 7abf33f..432db79 100644 --- a/rust/operator-binary/src/controller.rs +++ b/rust/operator-binary/src/controller.rs @@ -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}, @@ -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, @@ -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 { diff --git a/rust/operator-binary/src/controller/build.rs b/rust/operator-binary/src/controller/build.rs index 27278cb..1214b49 100644 --- a/rust/operator-binary/src/controller/build.rs +++ b/rust/operator-binary/src/controller/build.rs @@ -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 { diff --git a/rust/operator-binary/src/controller/build/node_config.rs b/rust/operator-binary/src/controller/build/node_config.rs index 9bf6cf5..0d5bf0f 100644 --- a/rust/operator-binary/src/controller/build/node_config.rs +++ b/rust/operator-binary/src/controller/build/node_config.rs @@ -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 { diff --git a/rust/operator-binary/src/controller/build/role_builder.rs b/rust/operator-binary/src/controller/build/role_builder.rs index 14cf814..ac0625c 100644 --- a/rust/operator-binary/src/controller/build/role_builder.rs +++ b/rust/operator-binary/src/controller/build/role_builder.rs @@ -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 { diff --git a/rust/operator-binary/src/controller/build/role_group_builder.rs b/rust/operator-binary/src/controller/build/role_group_builder.rs index 4edc9a5..ddc8f54 100644 --- a/rust/operator-binary/src/controller/build/role_group_builder.rs +++ b/rust/operator-binary/src/controller/build/role_group_builder.rs @@ -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\ @@ -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 = @@ -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 { @@ -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)] @@ -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", diff --git a/rust/operator-binary/src/controller/validate.rs b/rust/operator-binary/src/controller/validate.rs index 16e13f5..7ff1e1e 100644 --- a/rust/operator-binary/src/controller/validate.rs +++ b/rust/operator-binary/src/controller/validate.rs @@ -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 = std::result::Result; @@ -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); } @@ -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 { let merged_role_group: RoleGroup = with_validated_config( @@ -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 @@ -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, @@ -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" @@ -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 = + 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( diff --git a/rust/operator-binary/src/crd/mod.rs b/rust/operator-binary/src/crd/mod.rs index 6f26853..bd020e4 100644 --- a/rust/operator-binary/src/crd/mod.rs +++ b/rust/operator-binary/src/crd/mod.rs @@ -18,6 +18,7 @@ use stackable_operator::{ merge::{Atomic, Merge}, }, constant, + crd::containerdebug::{default_containerdebug_config, v1alpha1::ContainerdebugConfig}, deep_merger::ObjectOverrides, k8s_openapi::{api::core::v1::PodAntiAffinity, apimachinery::pkg::api::resource::Quantity}, kube::CustomResource, @@ -391,6 +392,9 @@ pub mod versioned { #[fragment_attrs(serde(default))] pub affinity: StackableAffinity, + #[fragment_attrs(serde(default))] + pub containerdebug: ContainerdebugConfig, + /// Determines whether this role group is exposed in the discovery service. pub discovery_service_exposed: bool, @@ -538,6 +542,7 @@ impl v1alpha1::OpenSearchConfig { node_affinity: None, node_selector: None, }, + containerdebug: default_containerdebug_config(), discovery_service_exposed: Some(true), // Default taken from the Helm chart, see // https://github.com/opensearch-project/helm-charts/blob/opensearch-3.0.0/charts/opensearch/values.yaml#L364 From 279d6cc7ce8dca3074fd01280e214cf6b4874908 Mon Sep 17 00:00:00 2001 From: Maxi Wittich Date: Mon, 23 Nov 2026 15:15:15 +0100 Subject: [PATCH 2/5] Regenerate crds --- extra/crds.yaml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/extra/crds.yaml b/extra/crds.yaml index ff92247..e425816 100644 --- a/extra/crds.yaml +++ b/extra/crds.yaml @@ -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 @@ -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 From ccd383d9fb5f45c17b8c54154195ce633a757e12 Mon Sep 17 00:00:00 2001 From: Maxi Wittich Date: Mon, 23 Nov 2026 15:15:37 +0100 Subject: [PATCH 3/5] Add documentation --- docs/modules/opensearch/pages/usage-guide/logging.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/modules/opensearch/pages/usage-guide/logging.adoc b/docs/modules/opensearch/pages/usage-guide/logging.adoc index 66fee5f..e8920ff 100644 --- a/docs/modules/opensearch/pages/usage-guide/logging.adoc +++ b/docs/modules/opensearch/pages/usage-guide/logging.adoc @@ -10,6 +10,8 @@ spec: vectorAggregatorConfigMapName: vector-aggregator-discovery nodes: config: + containerdebug: + enabled: false logging: enableVectorAgent: true containers: @@ -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[]. From b7c421b6fffb6e4685cb779bb3e470c412e126b2 Mon Sep 17 00:00:00 2001 From: Maxi Wittich Date: Tue, 24 Nov 2026 12:38:42 +0100 Subject: [PATCH 4/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 558704c..ad0e625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - The logs of the `containerdebug` process are now collected by the Vector agent and forwarded to the Vector aggregator. The operator enables the file logs of containerdebug for this, with an hourly rotation that keeps at most two files ([#205]). +- Add the `config.containerdebug` field to roles and role groups ([#TBD]). ### Changed From a8a177122f2690862f08ffed30f2c198b5a3e9e3 Mon Sep 17 00:00:00 2001 From: Maxi Wittich Date: Tue, 24 Nov 2026 12:40:46 +0100 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad0e625..4da6de3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -17,7 +23,6 @@ All notable changes to this project will be documented in this file. - The logs of the `containerdebug` process are now collected by the Vector agent and forwarded to the Vector aggregator. The operator enables the file logs of containerdebug for this, with an hourly rotation that keeps at most two files ([#205]). -- Add the `config.containerdebug` field to roles and role groups ([#TBD]). ### Changed