diff --git a/CHANGELOG.md b/CHANGELOG.md index 76772a30..48d21f66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [Unreleased] +### Added + +- Add the `config.containerdebug` field to roles and role groups ([#818]). + +[#818]: https://github.com/stackabletech/superset-operator/pull/818 + ## [26.11.0] - 2026-11-20 ## [26.11.0-rc1] - 2026-11-19 diff --git a/docs/modules/superset/pages/usage-guide/logging.adoc b/docs/modules/superset/pages/usage-guide/logging.adoc index 1d113c3a..65a52a57 100644 --- a/docs/modules/superset/pages/usage-guide/logging.adoc +++ b/docs/modules/superset/pages/usage-guide/logging.adoc @@ -10,6 +10,8 @@ spec: vectorAggregatorConfigMapName: vector-aggregator-discovery nodes: config: + containerdebug: + enabled: false logging: enableVectorAgent: true ---- @@ -22,4 +24,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/superset` 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[]. diff --git a/extra/crds.yaml b/extra/crds.yaml index b54ed81e..b8142670 100644 --- a/extra/crds.yaml +++ b/extra/crds.yaml @@ -75,6 +75,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 gracefulShutdownTimeout: description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details. nullable: true @@ -452,6 +472,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 gracefulShutdownTimeout: description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details. nullable: true @@ -1260,6 +1300,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 gracefulShutdownTimeout: description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details. nullable: true @@ -1637,6 +1697,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 gracefulShutdownTimeout: description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details. nullable: true @@ -2015,6 +2095,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 gracefulShutdownTimeout: description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details. nullable: true @@ -2392,6 +2492,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 gracefulShutdownTimeout: description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details. nullable: true diff --git a/rust/operator-binary/src/controller.rs b/rust/operator-binary/src/controller.rs index 78a1b53e..fc2814b7 100644 --- a/rust/operator-binary/src/controller.rs +++ b/rust/operator-binary/src/controller.rs @@ -18,7 +18,7 @@ use stackable_operator::{ resources::{NoRuntimeLimits, Resources}, }, constant, - crd::listener, + crd::{containerdebug::ValidatedContainerdebugConfig, listener}, k8s_openapi::api::{ apps::v1::{Deployment, StatefulSet}, core::v1::{ConfigMap, Service, ServiceAccount}, @@ -148,6 +148,7 @@ pub type SupersetRoleGroupConfig = #[derive(Clone, Debug)] pub struct ValidatedSupersetConfig { pub affinity: StackableAffinity, + pub containerdebug: ValidatedContainerdebugConfig, pub graceful_shutdown_timeout: Option, pub logging: ValidatedLogging, pub resources: Resources, @@ -157,10 +158,15 @@ pub struct ValidatedSupersetConfig { impl ValidatedSupersetConfig { /// Builds the validated config from the merged [`SupersetConfig`], swapping in the - /// already-validated logging. - fn from_merged(merged: SupersetConfig, logging: ValidatedLogging) -> Self { + /// already-validated `containerdebug` and logging configuration. + fn from_merged( + merged: SupersetConfig, + containerdebug: ValidatedContainerdebugConfig, + logging: ValidatedLogging, + ) -> Self { Self { affinity: merged.affinity, + containerdebug, graceful_shutdown_timeout: merged.graceful_shutdown_timeout, logging, resources: merged.resources, diff --git a/rust/operator-binary/src/controller/build/properties/superset_config.rs b/rust/operator-binary/src/controller/build/properties/superset_config.rs index 788bc0a3..b9d80807 100644 --- a/rust/operator-binary/src/controller/build/properties/superset_config.rs +++ b/rust/operator-binary/src/controller/build/properties/superset_config.rs @@ -312,6 +312,10 @@ mod tests { ) -> ValidatedSupersetConfig { ValidatedSupersetConfig { affinity: StackableAffinity::default(), + containerdebug: + stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled { + interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL, + }, graceful_shutdown_timeout: None, logging: ValidatedLogging { superset_container: ValidatedContainerLogConfigChoice::Automatic( diff --git a/rust/operator-binary/src/controller/build/resource/deployment.rs b/rust/operator-binary/src/controller/build/resource/deployment.rs index e27bcc6e..b2146f7d 100644 --- a/rust/operator-binary/src/controller/build/resource/deployment.rs +++ b/rust/operator-binary/src/controller/build/resource/deployment.rs @@ -126,7 +126,7 @@ pub fn build_rolegroup_deployment( {remove_vector_shutdown_file_command} prepare_signal_handlers mkdir --parents \"${file_log_directory}\" || true - containerdebug --output={STACKABLE_LOG_DIR}/containerdebug-state.json --loop & + {containerdebug_command} {celery_command} & @@ -135,6 +135,10 @@ pub fn build_rolegroup_deployment( ", log_config_file = ConfigFileName::LogConfig, file_log_directory = super::FILE_LOG_DIRECTORY.as_ref(), + containerdebug_command = merged_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 = @@ -241,7 +245,12 @@ fn beat_replicas(requested: Option) -> Option { #[cfg(test)] mod tests { - use super::beat_replicas; + use std::str::FromStr; + + use stackable_operator::v2::types::operator::RoleGroupName; + + use super::{beat_replicas, build_rolegroup_deployment}; + use crate::{controller::build::test_support::validated_cluster, crd::SupersetRole}; #[test] fn beat_replicas_clamps_to_a_single_instance() { @@ -255,4 +264,57 @@ mod tests { assert_eq!(beat_replicas(Some(2)), Some(1)); assert_eq!(beat_replicas(Some(100)), Some(1)); } + + /// The superset container of a Celery worker or beat 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::rstest] + fn superset_container_starts_containerdebug_from_config( + #[values(SupersetRole::Worker, SupersetRole::Beat)] role: SupersetRole, + #[values( + stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled { + interval: stackable_operator::shared::time::Duration::from_minutes_unchecked(10) + }, + stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Disabled + )] + containerdebug: stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig, + ) { + let expected = containerdebug.background_command( + stackable_operator::v2::product_logging::framework::STACKABLE_LOG_DIR, + ); + let cluster = validated_cluster(); + let role_group_name = RoleGroupName::from_str("default").expect("valid role group name"); + let role_group_configs = match role { + SupersetRole::Worker => &cluster.worker_role_group_configs, + SupersetRole::Beat => &cluster.beat_role_group_configs, + SupersetRole::Node => unreachable!("nodes are built as a StatefulSet"), + }; + let mut rg = role_group_configs + .get(&role_group_name) + .expect("default role group") + .clone(); + rg.config.containerdebug = containerdebug; + + let deployment = build_rolegroup_deployment(&cluster, &role, &role_group_name, &rg) + .expect("deployment built"); + + let args = deployment + .spec + .and_then(|spec| spec.template.spec) + .expect("pod spec") + .containers + .into_iter() + .find(|container| container.name == "superset") + .and_then(|container| container.args) + .expect("the superset container has args") + .join("\n"); + + assert_eq!( + args.lines() + .map(str::trim) + .find(|line| line.starts_with("containerdebug ")), + expected.as_deref(), + "args: {args}" + ); + } } diff --git a/rust/operator-binary/src/controller/build/resource/statefulset.rs b/rust/operator-binary/src/controller/build/resource/statefulset.rs index 89b4846c..f7288401 100644 --- a/rust/operator-binary/src/controller/build/resource/statefulset.rs +++ b/rust/operator-binary/src/controller/build/resource/statefulset.rs @@ -191,7 +191,7 @@ pub fn build_node_rolegroup_statefulset( {remove_vector_shutdown_file_command} prepare_signal_handlers mkdir --parents \"${file_log_directory}\" || true - containerdebug --output={STACKABLE_LOG_DIR}/containerdebug-state.json --loop & + {containerdebug_command} gunicorn --bind 0.0.0.0:${{SUPERSET_PORT}} --worker-class gthread --threads 20 --timeout {webserver_timeout} --limit-request-line 0 --limit-request-field_size 0 'superset.app:create_app()' & wait_for_termination $! @@ -199,6 +199,10 @@ pub fn build_node_rolegroup_statefulset( ", log_config_file = ConfigFileName::LogConfig, file_log_directory = super::FILE_LOG_DIRECTORY.as_ref(), + containerdebug_command = merged_config + .containerdebug + .background_command(STACKABLE_LOG_DIR) + .unwrap_or_default(), auth_commands = authentication_start_commands(&validated.cluster_config.authentication_config), remove_vector_shutdown_file_command = remove_vector_shutdown_file_command(STACKABLE_LOG_DIR), @@ -461,4 +465,52 @@ mod tests { "the user-supplied env override must win over the operator-set value" ); } + + /// The superset container of a webserver node 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::rstest] + #[case::enabled(stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Enabled { + interval: stackable_operator::shared::time::Duration::from_minutes_unchecked(10) + })] + #[case::disabled( + stackable_operator::crd::containerdebug::ValidatedContainerdebugConfig::Disabled + )] + fn superset_container_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 cluster = validated_cluster(); + let role_group_name = RoleGroupName::from_str("default").expect("valid role group name"); + let mut rg = cluster + .node_role_group_configs + .get(&role_group_name) + .expect("node default role group") + .clone(); + rg.config.containerdebug = containerdebug; + + let stateful_set = build_node_rolegroup_statefulset(&cluster, &role_group_name, &rg) + .expect("statefulset built"); + + let args = stateful_set + .spec + .and_then(|spec| spec.template.spec) + .expect("pod spec") + .containers + .into_iter() + .find(|container| container.name == "superset") + .and_then(|container| container.args) + .expect("the superset container has args") + .join("\n"); + + assert_eq!( + args.lines() + .map(str::trim) + .find(|line| line.starts_with("containerdebug ")), + expected.as_deref(), + "args: {args}" + ); + } } diff --git a/rust/operator-binary/src/controller/validate.rs b/rust/operator-binary/src/controller/validate.rs index b3fc2e9c..53f15f50 100644 --- a/rust/operator-binary/src/controller/validate.rs +++ b/rust/operator-binary/src/controller/validate.rs @@ -19,7 +19,7 @@ use stackable_operator::{ role_utils::{GenericCommonConfig, with_validated_config}, types::{ kubernetes::{ConfigMapName, SecretName}, - operator::RoleGroupName, + operator::{RoleGroupName, RoleName}, }, }, }; @@ -68,6 +68,15 @@ pub enum Error { role_group: RoleGroupName, }, + #[snafu(display( + "invalid containerdebug configuration for role {role} role group {role_group}" + ))] + InvalidContainerdebugConfig { + source: stackable_operator::crd::containerdebug::Error, + role: RoleName, + role_group: RoleGroupName, + }, + #[snafu(display("invalid role group name {role_group}"))] ParseRoleGroupName { source: stackable_operator::v2::macros::attributed_string_type::Error, @@ -256,6 +265,7 @@ fn validate_role_groups( } })?; let validated = validate_role_group_config( + role, &role_group_name, rolegroup, resolved_role, @@ -269,6 +279,7 @@ fn validate_role_groups( /// Merges and validates one role group into a [`SupersetRoleGroupConfig`]. fn validate_role_group_config( + superset_role: &SupersetRole, role_group_name: &RoleGroupName, role_group: &SupersetRoleGroupType, role: &SupersetRoleType, @@ -286,6 +297,16 @@ fn validate_role_group_config( role_group: role_group_name.clone(), })?; + let containerdebug = merged + .config + .config + .containerdebug + .validate() + .with_context(|_| InvalidContainerdebugConfigSnafu { + role: (**superset_role).clone(), + role_group: role_group_name.clone(), + })?; + let logging = validate_logging( &merged.config.config.logging, vector_aggregator_config_map_name, @@ -293,7 +314,7 @@ fn validate_role_group_config( Ok(SupersetRoleGroupConfig { replicas: merged.replicas, - config: ValidatedSupersetConfig::from_merged(merged.config.config, logging), + config: ValidatedSupersetConfig::from_merged(merged.config.config, containerdebug, logging), config_overrides: merged.config.config_overrides, env_overrides: merged.config.env_overrides.into(), cli_overrides: merged.config.cli_overrides, @@ -453,4 +474,104 @@ mod tests { "a `null` configOverrides value must be rejected: values are typed as String" ); } + + /// A role `config` that does not mention `containerdebug` still gets the default, so the + /// `containerdebug` field of the CRD must be optional. + #[test] + fn containerdebug_defaults_when_not_configured() { + use stackable_operator::crd::containerdebug::{ + DEFAULT_INTERVAL, ValidatedContainerdebugConfig, + }; + + let input = r#" + apiVersion: superset.stackable.tech/v1alpha1 + kind: SupersetCluster + metadata: + name: simple-superset + namespace: default + uid: 01234567-89ab-cdef-0123-456789abcdef + spec: + image: + productVersion: 4.1.4 + clusterConfig: + credentialsSecret: superset-admin-credentials + metadataDatabase: + postgresql: + host: superset-postgresql + database: superset + credentialsSecretName: superset-postgresql-credentials + nodes: + config: + gracefulShutdownTimeout: 1h + roleGroups: + default: + replicas: 1 + "#; + let superset: v1alpha1::SupersetCluster = + yaml_from_str_singleton_map(input).expect("illegal test input"); + + let validated = + validate_cluster(&superset, default_dereferenced(), "test-repo").expect("validated"); + let node = validated + .node_role_group_configs + .get(&"default".parse().expect("valid role group name")) + .expect("node default rolegroup"); + + assert_eq!( + node.config.containerdebug, + ValidatedContainerdebugConfig::Enabled { + interval: DEFAULT_INTERVAL + } + ); + } + + /// An invalid `containerdebug` config fails the validation, naming the role and role group. + #[test] + fn zero_containerdebug_interval_fails_validation() { + let input = r#" + apiVersion: superset.stackable.tech/v1alpha1 + kind: SupersetCluster + metadata: + name: simple-superset + namespace: default + uid: 01234567-89ab-cdef-0123-456789abcdef + spec: + image: + productVersion: 4.1.4 + clusterConfig: + credentialsSecret: superset-admin-credentials + metadataDatabase: + postgresql: + host: superset-postgresql + database: superset + credentialsSecretName: superset-postgresql-credentials + nodes: + config: + containerdebug: + interval: 0s + roleGroups: + default: + replicas: 1 + "#; + let superset: v1alpha1::SupersetCluster = + yaml_from_str_singleton_map(input).expect("illegal test input"); + + let Err(error) = validate_cluster(&superset, default_dereferenced(), "test-repo") else { + panic!("the validation should fail"); + }; + let chain: Vec = + std::iter::successors(Some(&error as &dyn std::error::Error), |error| { + error.source() + }) + .map(ToString::to_string) + .collect(); + + assert_eq!( + chain, + [ + "invalid containerdebug configuration for role node role group default", + "the containerdebug interval must not be zero", + ] + ); + } } diff --git a/rust/operator-binary/src/crd/mod.rs b/rust/operator-binary/src/crd/mod.rs index 7043e176..bed60074 100644 --- a/rust/operator-binary/src/crd/mod.rs +++ b/rust/operator-binary/src/crd/mod.rs @@ -15,6 +15,7 @@ use stackable_operator::{ }, config::{fragment::Fragment, merge::Merge}, constant, + crd::containerdebug::{default_containerdebug_config, v1alpha1::ContainerdebugConfig}, deep_merger::ObjectOverrides, k8s_openapi::apimachinery::pkg::api::resource::Quantity, kube::{CustomResource, ResourceExt}, @@ -277,7 +278,7 @@ pub mod versioned { pub vector_aggregator_config_map_name: Option, } - #[derive(Clone, Debug, Default, Fragment, JsonSchema, PartialEq)] + #[derive(Clone, Debug, Fragment, JsonSchema, PartialEq)] #[fragment_attrs( derive( Clone, @@ -312,6 +313,9 @@ pub mod versioned { #[fragment_attrs(serde(default))] pub affinity: StackableAffinity, + #[fragment_attrs(serde(default))] + pub containerdebug: ContainerdebugConfig, + /// Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details. #[fragment_attrs(serde(default))] pub graceful_shutdown_timeout: Option, @@ -527,6 +531,7 @@ impl v1alpha1::SupersetConfig { }, logging: product_logging::spec::default_logging(), affinity: affinity::get_affinity(cluster_name, role, opa_config), + containerdebug: default_containerdebug_config(), graceful_shutdown_timeout: Some(DEFAULT_NODE_GRACEFUL_SHUTDOWN_TIMEOUT), row_limit: None, webserver_timeout: None, @@ -547,6 +552,7 @@ impl v1alpha1::SupersetConfig { // Only the web server (node) is known to request the role mapping from OPA, so // workers and beat get no affinity to the OPA Pods. affinity: affinity::get_affinity(cluster_name, role, None), + containerdebug: default_containerdebug_config(), graceful_shutdown_timeout: Some(DEFAULT_NODE_GRACEFUL_SHUTDOWN_TIMEOUT), row_limit: None, webserver_timeout: None, @@ -567,6 +573,7 @@ impl v1alpha1::SupersetConfig { // Only the web server (node) is known to request the role mapping from OPA, so // workers and beat get no affinity to the OPA Pods. affinity: affinity::get_affinity(cluster_name, role, None), + containerdebug: default_containerdebug_config(), graceful_shutdown_timeout: Some(DEFAULT_NODE_GRACEFUL_SHUTDOWN_TIMEOUT), row_limit: None, webserver_timeout: None,