diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f4ddb9b..49e540ae 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 ([#967]). + +[#967]: https://github.com/stackabletech/trino-operator/pull/967 + ## [26.11.0] - 2026-11-20 ## [26.11.0-rc1] - 2026-11-19 diff --git a/docs/modules/trino/pages/usage-guide/log_aggregation.adoc b/docs/modules/trino/pages/usage-guide/log_aggregation.adoc index 7cf32e61..394bd757 100644 --- a/docs/modules/trino/pages/usage-guide/log_aggregation.adoc +++ b/docs/modules/trino/pages/usage-guide/log_aggregation.adoc @@ -10,6 +10,8 @@ spec: vectorAggregatorConfigMapName: vector-aggregator-discovery coordinators: config: + containerdebug: + enabled: false logging: enableVectorAgent: true containers: @@ -30,4 +32,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/trino` 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 19ac8bd2..87225476 100644 --- a/extra/crds.yaml +++ b/extra/crds.yaml @@ -1135,6 +1135,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 @@ -1750,6 +1770,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 @@ -2464,6 +2504,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 @@ -3071,6 +3131,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/build/command.rs b/rust/operator-binary/src/controller/build/command.rs index 29899745..bf13450c 100644 --- a/rust/operator-binary/src/controller/build/command.rs +++ b/rust/operator-binary/src/controller/build/command.rs @@ -1,6 +1,7 @@ use std::collections::BTreeMap; use stackable_operator::{ + crd::containerdebug::ValidatedContainerdebugConfig, product_logging::framework::{ create_vector_shutdown_file_command, remove_vector_shutdown_file_command, }, @@ -87,6 +88,7 @@ pub fn container_prepare_args( pub fn container_trino_args( authentication_config: &TrinoAuthenticationConfig, catalogs: &BTreeMap, + containerdebug: &ValidatedContainerdebugConfig, ) -> Vec { let mut args = vec![ // copy config files to a writable empty folder @@ -152,7 +154,7 @@ pub fn container_trino_args( {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} bin/launcher run --etc-dir={RW_CONFIG_DIR_NAME} & wait_for_termination $! {create_vector_shutdown_file_command} @@ -160,6 +162,9 @@ wait_for_termination $! remove_vector_shutdown_file_command = remove_vector_shutdown_file_command(STACKABLE_LOG_DIR), file_log_directory = FILE_LOG_DIRECTORY.as_ref(), + containerdebug_command = containerdebug + .background_command(STACKABLE_LOG_DIR) + .unwrap_or_default(), create_vector_shutdown_file_command = create_vector_shutdown_file_command(STACKABLE_LOG_DIR), )); diff --git a/rust/operator-binary/src/controller/build/resource/statefulset.rs b/rust/operator-binary/src/controller/build/resource/statefulset.rs index 8df9cfe8..84b05c63 100644 --- a/rust/operator-binary/src/controller/build/resource/statefulset.rs +++ b/rust/operator-binary/src/controller/build/resource/statefulset.rs @@ -402,7 +402,12 @@ pub fn build_rolegroup_statefulset( "-c".to_string(), ]) .args(vec![ - command::container_trino_args(trino_authentication_config, catalogs).join("\n"), + command::container_trino_args( + trino_authentication_config, + catalogs, + &merged_config.containerdebug, + ) + .join("\n"), ]) .add_env_vars(env.merge(env_overrides.clone())) .add_container_ports(container_ports(cluster)) @@ -835,8 +840,11 @@ fn add_derived_volumes_and_mounts( #[cfg(test)] mod tests { + use rstest::rstest; use stackable_operator::{ + crd::containerdebug::ValidatedContainerdebugConfig, k8s_openapi::api::core::v1::{Container as K8sContainer, PodSpec, VolumeMount}, + shared::time::Duration, v2::builder::pod::container::EnvVarName, }; @@ -933,6 +941,47 @@ mod tests { assert_eq!(containerdebug[0].value.as_deref(), Some("/custom/log/dir")); } + /// The trino 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(ValidatedContainerdebugConfig::Enabled { + interval: Duration::from_minutes_unchecked(10) + })] + #[case::disabled(ValidatedContainerdebugConfig::Disabled)] + fn trino_container_starts_containerdebug_from_config( + #[case] containerdebug: ValidatedContainerdebugConfig, + ) { + let expected = containerdebug.background_command(STACKABLE_LOG_DIR); + let cluster = validated_cluster(); + let role_group_name = RoleGroupName::from_str("default").expect("valid role group name"); + let mut role_group_config = + cluster.coordinator_role_group_configs[&role_group_name].clone(); + role_group_config.config.containerdebug = containerdebug; + + let stateful_set = build_rolegroup_statefulset( + &cluster, + &TrinoRole::Coordinator, + &role_group_name, + &role_group_config, + ) + .expect("the StatefulSet builds"); + + let args = pod_spec(stateful_set) + .containers + .into_iter() + .find(|container| container.name == "trino") + .expect("the trino container exists") + .args + .expect("the trino container has args") + .join("\n"); + assert_eq!( + args.lines() + .find(|line| line.starts_with("containerdebug ")), + expected.as_deref(), + "args: {args}" + ); + } + /// The operator's own volume mounts are added with `expect`, which relies on every add whose /// name derives from user input coming afterwards. A catalog volume that reuses an operator /// volume name must therefore surface as an error, never as a panic. diff --git a/rust/operator-binary/src/controller/mod.rs b/rust/operator-binary/src/controller/mod.rs index 681fc462..c8d0e7f7 100644 --- a/rust/operator-binary/src/controller/mod.rs +++ b/rust/operator-binary/src/controller/mod.rs @@ -6,7 +6,7 @@ use stackable_operator::{ product_image_selection::ResolvedProductImage, resources::{NoRuntimeLimits, Resources}, }, - crd::listener::v1alpha1::Listener, + crd::{containerdebug::ValidatedContainerdebugConfig, listener::v1alpha1::Listener}, k8s_openapi::api::{ apps::v1::StatefulSet, core::v1::{ConfigMap, Service, ServiceAccount}, @@ -136,6 +136,7 @@ impl ValidatedClusterConfig { #[derive(Clone, Debug)] pub struct ValidatedTrinoConfig { pub affinity: StackableAffinity, + pub containerdebug: ValidatedContainerdebugConfig, pub graceful_shutdown_timeout: Option, pub logging: validate::ValidatedLogging, pub query_max_memory: Option, @@ -146,10 +147,15 @@ pub struct ValidatedTrinoConfig { impl ValidatedTrinoConfig { /// Builds the validated config from the merged [`v1alpha1::TrinoConfig`], swapping in the - /// already-validated logging. - fn from_merged(merged: v1alpha1::TrinoConfig, logging: validate::ValidatedLogging) -> Self { + /// already-validated `containerdebug` and logging configuration. + fn from_merged( + merged: v1alpha1::TrinoConfig, + containerdebug: ValidatedContainerdebugConfig, + logging: validate::ValidatedLogging, + ) -> Self { Self { affinity: merged.affinity, + containerdebug, graceful_shutdown_timeout: merged.graceful_shutdown_timeout, logging, query_max_memory: merged.query_max_memory, diff --git a/rust/operator-binary/src/controller/validate.rs b/rust/operator-binary/src/controller/validate.rs index 9a190084..e6ca7185 100644 --- a/rust/operator-binary/src/controller/validate.rs +++ b/rust/operator-binary/src/controller/validate.rs @@ -10,6 +10,7 @@ use stackable_operator::{ cli::OperatorEnvironmentOptions, commons::product_image_selection, config::fragment, + crd::containerdebug::{self, ValidatedContainerdebugConfig}, kube::ResourceExt as _, product_logging::spec::Logging, v2::{ @@ -91,6 +92,15 @@ pub enum Error { role_group: RoleGroupName, }, + #[snafu(display( + "invalid containerdebug configuration for role {role} role group {role_group}" + ))] + InvalidContainerdebugConfig { + source: containerdebug::Error, + role: RoleName, + role_group: RoleGroupName, + }, + #[snafu(display("failed to validate logging configuration"))] ValidateLoggingConfig { source: stackable_operator::v2::product_logging::framework::Error, @@ -416,9 +426,18 @@ where .with_context(|_| FailedToResolveConfigSnafu { role_group: role_group_name.clone(), })?; + let containerdebug = merged + .config + .config + .containerdebug + .validate() + .with_context(|_| InvalidContainerdebugConfigSnafu { + role: (**trino_role).clone(), + role_group: role_group_name.clone(), + })?; role_groups.insert( role_group_name, - into_role_group_config(merged, vector_aggregator_config_map_name)?, + into_role_group_config(merged, containerdebug, vector_aggregator_config_map_name)?, ); } @@ -429,6 +448,7 @@ where /// [`TrinoRoleGroupConfig`] consumed by the build steps. fn into_role_group_config( merged: RoleGroup, + containerdebug: ValidatedContainerdebugConfig, vector_aggregator_config_map_name: &Option, ) -> Result { let replicas = merged.replicas; @@ -438,7 +458,7 @@ fn into_role_group_config( Ok(RoleGroupConfig { replicas, - config: ValidatedTrinoConfig::from_merged(common.config, logging), + config: ValidatedTrinoConfig::from_merged(common.config, containerdebug, logging), config_overrides: common.config_overrides, env_overrides: common.env_overrides.into(), cli_overrides: common.cli_overrides, @@ -489,7 +509,10 @@ pub(crate) fn merged_role_group_config( mod tests { use std::{collections::BTreeMap, str::FromStr}; - use stackable_operator::cli::OperatorEnvironmentOptions; + use stackable_operator::{ + cli::OperatorEnvironmentOptions, + crd::containerdebug::{DEFAULT_INTERVAL, ValidatedContainerdebugConfig}, + }; use super::{Error, RoleGroupName, validate}; use crate::{ @@ -804,4 +827,90 @@ mod tests { let err = validate_yaml(yaml, &empty_derefs()).unwrap_err(); assert!(matches!(err, Error::ParseRoleGroupName { .. })); } + + /// 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() { + let yaml = r#" + apiVersion: trino.stackable.tech/v1alpha1 + kind: TrinoCluster + metadata: + name: simple-trino + namespace: default + uid: "e6ac237d-a6d4-43a1-8135-f36506110912" + spec: + image: + productVersion: "481" + clusterConfig: + catalogLabelSelector: {} + coordinators: + config: + gracefulShutdownTimeout: 1h + roleGroups: + default: + replicas: 1 + workers: + roleGroups: + default: + replicas: 1 + "#; + + let cluster = validate_yaml(yaml, &empty_derefs()).expect("the cluster is valid"); + let role_group_name = RoleGroupName::from_str("default").expect("valid role group name"); + + assert_eq!( + cluster.coordinator_role_group_configs[&role_group_name] + .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 yaml = r#" + apiVersion: trino.stackable.tech/v1alpha1 + kind: TrinoCluster + metadata: + name: simple-trino + namespace: default + uid: "e6ac237d-a6d4-43a1-8135-f36506110912" + spec: + image: + productVersion: "481" + clusterConfig: + catalogLabelSelector: {} + coordinators: + roleGroups: + default: + replicas: 1 + workers: + config: + containerdebug: + interval: 0s + roleGroups: + default: + replicas: 1 + "#; + + let error = validate_yaml(yaml, &empty_derefs()).unwrap_err(); + 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 worker 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 86bce6e4..dc6ee82b 100644 --- a/rust/operator-binary/src/crd/mod.rs +++ b/rust/operator-binary/src/crd/mod.rs @@ -22,7 +22,11 @@ use stackable_operator::{ }, config::{fragment::Fragment, merge::Merge}, constant, - crd::{authentication::core, openlineage}, + crd::{ + authentication::core, + containerdebug::{default_containerdebug_config, v1alpha1::ContainerdebugConfig}, + openlineage, + }, deep_merger::ObjectOverrides, k8s_openapi::apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector}, kube::CustomResource, @@ -211,7 +215,7 @@ pub mod versioned { pub event_listener_properties: KeyValueConfigOverrides, } - #[derive(Clone, Debug, Default, Fragment, JsonSchema, PartialEq)] + #[derive(Clone, Debug, Fragment, JsonSchema, PartialEq)] #[fragment_attrs( derive( Clone, @@ -229,6 +233,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, @@ -538,6 +545,7 @@ impl v1alpha1::TrinoConfig { v1alpha1::TrinoConfigFragment { logging: product_logging::spec::default_logging(), affinity: get_affinity(cluster_name, role, trino_catalogs, opa_config), + containerdebug: default_containerdebug_config(), resources: ResourcesFragment { cpu: CpuLimitsFragment { min: Some(Quantity(cpu_min.to_string())),