diff --git a/CHANGELOG.md b/CHANGELOG.md index 43d0bd80..b76a3e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [Unreleased] +### Added + +- Add the `config.containerdebug` field to roles and role groups ([#899]). + +[#899]: https://github.com/stackabletech/airflow-operator/pull/899 + ## [26.11.0] - 2026-11-20 ## [26.11.0-rc1] - 2026-11-19 diff --git a/docs/modules/airflow/pages/usage-guide/logging.adoc b/docs/modules/airflow/pages/usage-guide/logging.adoc index ffb6612c..54f125e0 100644 --- a/docs/modules/airflow/pages/usage-guide/logging.adoc +++ b/docs/modules/airflow/pages/usage-guide/logging.adoc @@ -17,6 +17,8 @@ spec: vectorAggregatorConfigMapName: vector-aggregator-discovery webservers: config: + containerdebug: + enabled: false logging: enableVectorAgent: true containers: @@ -56,6 +58,9 @@ 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/airflow` 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[]. +Pods started by the Kubernetes executor do not run `containerdebug`, so `kubernetesExecutors` has no such setting. + Further information on how to configure logging, can be found in xref:concepts:logging.adoc[]. == Task logs diff --git a/extra/crds.yaml b/extra/crds.yaml index 1dda843f..540bfb07 100644 --- a/extra/crds.yaml +++ b/extra/crds.yaml @@ -77,6 +77,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 @@ -592,6 +612,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 @@ -1717,6 +1757,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 @@ -2232,6 +2292,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 @@ -3327,6 +3407,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 @@ -3842,6 +3942,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 @@ -4345,6 +4465,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 @@ -4860,6 +5000,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 @@ -5363,6 +5523,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 @@ -5905,6 +6085,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 @@ -6482,6 +6682,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 @@ -6997,6 +7217,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 @@ -8098,6 +8338,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 @@ -8613,6 +8873,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 @@ -9708,6 +9988,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 @@ -10223,6 +10523,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 @@ -10726,6 +11046,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 @@ -11241,6 +11581,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 @@ -11744,6 +12104,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 @@ -12286,6 +12666,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/mod.rs b/rust/operator-binary/src/controller/build/mod.rs index 8ef128cc..17da00a0 100644 --- a/rust/operator-binary/src/controller/build/mod.rs +++ b/rust/operator-binary/src/controller/build/mod.rs @@ -432,7 +432,10 @@ mod tests { use std::collections::BTreeMap; use rstest::rstest; - use stackable_operator::kube::Resource; + use stackable_operator::{ + crd::containerdebug::ValidatedContainerdebugConfig, kube::Resource, shared::time::Duration, + v2::product_logging::framework::STACKABLE_LOG_DIR, + }; use super::{ UNVERSIONED_PRODUCT_VERSION, build, @@ -828,4 +831,47 @@ mod tests { "unexpected error: {error:?}" ); } + + /// Each role group's StatefulSet starts `containerdebug` from that role group's merged config. + #[test] + fn stateful_sets_start_containerdebug_from_the_role_group_config() { + let cluster = validated_cluster_with("kubernetesExecutors", "{config: {}}", |cluster| { + cluster["spec"]["webservers"]["config"] = + yaml_serde::from_str("{containerdebug: {interval: 10m}}") + .expect("the webserver config is valid YAML"); + cluster["spec"]["schedulers"]["roleGroups"]["default"]["config"] = + yaml_serde::from_str("{containerdebug: {enabled: false}}") + .expect("the scheduler role group config is valid YAML"); + }); + let resources = build(&cluster).expect("the resources build"); + + let containerdebug_line = |name: &str| { + resources + .stateful_sets + .iter() + .find(|stateful_set| stateful_set.meta().name.as_deref() == Some(name)) + .and_then(|stateful_set| stateful_set.spec.as_ref()) + .and_then(|spec| spec.template.spec.as_ref()) + .expect("the StatefulSet has a pod spec") + .containers + .iter() + .find(|container| container.name == "airflow") + .and_then(|container| container.args.as_ref()) + .expect("the airflow container has args") + .join("\n") + .lines() + .map(str::trim) + .find(|line| line.starts_with("containerdebug ")) + .map(str::to_owned) + }; + + assert_eq!( + containerdebug_line("my-airflow-webserver-default"), + ValidatedContainerdebugConfig::Enabled { + interval: Duration::from_minutes_unchecked(10) + } + .background_command(STACKABLE_LOG_DIR) + ); + assert_eq!(containerdebug_line("my-airflow-scheduler-default"), None); + } } diff --git a/rust/operator-binary/src/controller/build/resource/statefulset.rs b/rust/operator-binary/src/controller/build/resource/statefulset.rs index cccdcaa2..e7de704d 100644 --- a/rust/operator-binary/src/controller/build/resource/statefulset.rs +++ b/rust/operator-binary/src/controller/build/resource/statefulset.rs @@ -163,7 +163,9 @@ pub fn build_server_rolegroup_statefulset( .context(GracefulShutdownSnafu)?; let mut airflow_container_args = Vec::new(); - airflow_container_args.extend(airflow_role.get_commands(validated_cluster)); + airflow_container_args.extend( + airflow_role.get_commands(validated_cluster, &merged_airflow_config.containerdebug), + ); airflow_container .image_from_product_image(resolved_product_image) diff --git a/rust/operator-binary/src/controller/mod.rs b/rust/operator-binary/src/controller/mod.rs index 31f11e96..a14ff680 100644 --- a/rust/operator-binary/src/controller/mod.rs +++ b/rust/operator-binary/src/controller/mod.rs @@ -8,7 +8,7 @@ use stackable_operator::{ resources::{NoRuntimeLimits, Resources}, }, constant, - crd::{git_sync, listener}, + crd::{containerdebug::ValidatedContainerdebugConfig, git_sync, listener}, database_connections::{ TemplatingMechanism, drivers::{ @@ -117,15 +117,17 @@ pub struct ValidatedAirflowConfig { pub resources: Resources, pub logging: ValidatedLogging, pub affinity: StackableAffinity, + pub containerdebug: ValidatedContainerdebugConfig, pub graceful_shutdown_timeout: Option, pub git_sync_resources: git_sync::v1alpha2::GitSyncResources, } impl ValidatedAirflowConfig { /// Builds the validated config from the merged [`AirflowConfig`], swapping in the - /// already-validated logging. + /// already-validated `containerdebug` and logging configuration. pub(crate) fn from_merged( merged: AirflowConfig, + containerdebug: ValidatedContainerdebugConfig, logging: ValidatedLogging, git_sync_resources: git_sync::v1alpha2::GitSyncResources, ) -> Self { @@ -133,6 +135,7 @@ impl ValidatedAirflowConfig { resources: merged.resources, logging, affinity: merged.affinity, + containerdebug, graceful_shutdown_timeout: merged.graceful_shutdown_timeout, git_sync_resources, } @@ -140,7 +143,8 @@ impl ValidatedAirflowConfig { /// Builds the validated config from the merged [`ExecutorConfig`] (Kubernetes-executor pod /// template), swapping in the already-validated logging. [`ExecutorConfig`] is field-identical - /// to [`AirflowConfig`]. + /// to [`AirflowConfig`], except for `containerdebug`: executor pods don't run `containerdebug`, + /// so it is always disabled for them. pub(crate) fn from_merged_executor( merged: ExecutorConfig, logging: ValidatedLogging, @@ -150,6 +154,7 @@ impl ValidatedAirflowConfig { resources: merged.resources, logging, affinity: merged.affinity, + containerdebug: ValidatedContainerdebugConfig::Disabled, graceful_shutdown_timeout: merged.graceful_shutdown_timeout, git_sync_resources, } diff --git a/rust/operator-binary/src/controller/validate.rs b/rust/operator-binary/src/controller/validate.rs index 97541168..77ebcf06 100644 --- a/rust/operator-binary/src/controller/validate.rs +++ b/rust/operator-binary/src/controller/validate.rs @@ -4,7 +4,7 @@ use snafu::{OptionExt, ResultExt, Snafu}; use stackable_operator::{ commons::product_image_selection::{self, ResolvedProductImage}, config::fragment, - crd::git_sync, + crd::{containerdebug, git_sync}, k8s_openapi::api::core::v1::VolumeMount, kube::ResourceExt, product_logging::spec::Logging, @@ -18,7 +18,7 @@ use stackable_operator::{ role_utils::{GenericCommonConfig, RoleGroup, RoleGroupConfig, with_validated_config}, types::{ kubernetes::ConfigMapName, - operator::{ClusterName, RoleGroupName}, + operator::{ClusterName, RoleGroupName, RoleName}, }, }, }; @@ -77,6 +77,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 the logging configuration"))] ValidateLoggingConfig { source: stackable_operator::v2::product_logging::framework::Error, @@ -333,6 +342,7 @@ fn validate_role_groups( })?; let config = validate_role_group( &resolved_role, + role, &role_group_name, rolegroup, &default_config, @@ -350,6 +360,7 @@ fn validate_role_groups( #[allow(clippy::too_many_arguments)] fn validate_role_group( role: &AirflowRoleType, + airflow_role: &AirflowRole, role_group_name: &RoleGroupName, rolegroup: &RoleGroup, default_config: &AirflowConfigFragment, @@ -370,6 +381,12 @@ fn validate_role_group( })?; let merged_config = validated.config.config; + let containerdebug = merged_config.containerdebug.validate().with_context(|_| { + InvalidContainerdebugConfigSnafu { + role: (**airflow_role).clone(), + role_group: role_group_name.clone(), + } + })?; let logging = validate_logging( &merged_config.logging, &Container::Airflow, @@ -392,7 +409,12 @@ fn validate_role_group( Ok(RoleGroupConfig { replicas: validated.replicas, - config: ValidatedAirflowConfig::from_merged(merged_config, logging, git_sync_resources), + config: ValidatedAirflowConfig::from_merged( + merged_config, + containerdebug, + logging, + git_sync_resources, + ), config_overrides: validated.config.config_overrides, env_overrides, cli_overrides: validated.config.cli_overrides, @@ -524,6 +546,7 @@ mod tests { let validated = validate_role_group( &role, + &AirflowRole::Webserver, &"default".parse().expect("valid role group name"), rolegroup, &default_config, @@ -622,6 +645,7 @@ mod tests { let validated = validate_role_group( &role, + &AirflowRole::Scheduler, &"default".parse().expect("valid role group name"), rolegroup, &default_config, @@ -699,6 +723,7 @@ mod tests { let validated = validate_role_group( &role, + &AirflowRole::Webserver, &"default".parse().expect("valid role group name"), rolegroup, &default_config, @@ -761,4 +786,76 @@ mod tests { "error was: {error:?}" ); } + + /// [`test_cluster`] with the namespace and uid that `validate_cluster` resolves before it gets + /// to the role groups. + fn test_cluster_with_metadata() -> v1alpha2::AirflowCluster { + let mut cluster = test_cluster(); + cluster.metadata.namespace = Some("default".to_owned()); + cluster.metadata.uid = Some("e6ac237d-a6d4-43a1-8135-f36506110912".to_owned()); + cluster + } + + /// 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, + }; + + // The webservers of `test_cluster` have a `config: {}` without `containerdebug`. + let Ok(cluster) = validate_cluster( + &test_cluster_with_metadata(), + "oci.stackable.tech/sdp", + dereferenced_objects(), + ) else { + panic!("the test cluster must validate"); + }; + + assert_eq!( + cluster.webserver_role_group_configs + [&"default".parse().expect("valid 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 mut cluster = test_cluster_with_metadata(); + cluster + .spec + .schedulers + .as_mut() + .expect("the test CR declares a scheduler role") + .config + .config + .containerdebug + .interval = Some(stackable_operator::shared::time::Duration::from_secs(0)); + + let Err(error) = + validate_cluster(&cluster, "oci.stackable.tech/sdp", dereferenced_objects()) + 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 scheduler 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 f4eedf94..9d80f6a9 100644 --- a/rust/operator-binary/src/crd/mod.rs +++ b/rust/operator-binary/src/crd/mod.rs @@ -20,7 +20,13 @@ use stackable_operator::{ merge::Merge, }, constant, - crd::{git_sync, openlineage}, + crd::{ + containerdebug::{ + ValidatedContainerdebugConfig, default_containerdebug_config, + v1alpha1::ContainerdebugConfig, + }, + git_sync, openlineage, + }, deep_merger::ObjectOverrides, k8s_openapi::{ api::core::v1::{Volume, VolumeMount}, @@ -573,7 +579,11 @@ impl AirflowRole { /// config file is in the Airflow home directory on all pods. /// Only the webserver needs to know about authentication CA's which is added via python's certify /// if authentication is enabled. - pub fn get_commands(&self, cluster: &ValidatedCluster) -> Vec { + pub fn get_commands( + &self, + cluster: &ValidatedCluster, + containerdebug: &ValidatedContainerdebugConfig, + ) -> Vec { let auth_config = &cluster.cluster_config.authentication_config; let resolved_product_image = &cluster.image; let database_initialization_enabled = @@ -601,7 +611,7 @@ impl AirflowRole { command.extend(Self::authentication_start_commands(auth_config)); command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), format!( "airflow api-server{} &", self.proxy_headers_argument(cluster) @@ -620,7 +630,7 @@ impl AirflowRole { } command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), ]); if !has_dag_processors { // If no dag_processors role has been specified, the @@ -638,17 +648,17 @@ impl AirflowRole { } AirflowRole::DagProcessor => command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), "airflow dag-processor &".to_string(), ]), AirflowRole::Triggerer => command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), "airflow triggerer &".to_string(), ]), AirflowRole::Worker => command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), "airflow celery worker &".to_string(), ]), } @@ -659,7 +669,7 @@ impl AirflowRole { command.extend(Self::authentication_start_commands(auth_config)); command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), "airflow webserver &".to_string(), ]); } @@ -677,23 +687,23 @@ impl AirflowRole { } command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), "airflow scheduler &".to_string(), ]); } AirflowRole::DagProcessor => command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), "airflow dag-processor &".to_string(), ]), AirflowRole::Triggerer => command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), "airflow triggerer &".to_string(), ]), AirflowRole::Worker => command.extend(vec![ "prepare_signal_handlers".to_string(), - container_debug_command(), + container_debug_command(containerdebug), "airflow celery worker &".to_string(), ]), } @@ -785,15 +795,18 @@ impl Deref for AirflowRole { } } -fn container_debug_command() -> String { +fn container_debug_command(containerdebug: &ValidatedContainerdebugConfig) -> String { // The log directory is created here, because `FILE_LOG_MAX_FILES` makes the telemetry library // prune old log files before it creates the first one, which complains about the directory not // existing yet. formatdoc!( r#" mkdir --parents "${file_log_directory}" || true - containerdebug --output={STACKABLE_LOG_DIR}/containerdebug-state.json --loop &"#, + {containerdebug_command}"#, file_log_directory = FILE_LOG_DIRECTORY.as_ref(), + containerdebug_command = containerdebug + .background_command(STACKABLE_LOG_DIR) + .unwrap_or_default(), ) } @@ -913,7 +926,7 @@ pub struct ExecutorConfig { pub graceful_shutdown_timeout: Option, } -#[derive(Clone, Debug, Default, Fragment, JsonSchema, PartialEq)] +#[derive(Clone, Debug, Fragment, JsonSchema, PartialEq)] #[fragment_attrs( derive( Clone, @@ -937,6 +950,9 @@ pub struct AirflowConfig { #[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, @@ -952,6 +968,7 @@ impl AirflowConfig { resources: default_resources(role), logging: product_logging::spec::default_logging(), affinity: get_affinity(cluster_name, role, opa_config), + containerdebug: default_containerdebug_config(), graceful_shutdown_timeout: Some(match role { AirflowRole::Webserver | AirflowRole::Scheduler @@ -1027,6 +1044,7 @@ fn default_resources(role: &AirflowRole) -> ResourcesFragment Vec { - role.get_commands(cluster) + let containerdebug = ValidatedContainerdebugConfig::Enabled { + interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL, + }; + role.get_commands(cluster, &containerdebug) .into_iter() .filter(|command| command.ends_with(" &")) .collect() @@ -1395,4 +1417,40 @@ mod tests { "# } } + + /// Every role starts `containerdebug` from the given config, in both the Airflow 2.x and 3.x + /// start commands. The command itself is owned (and tested) by operator-rs, so only the wiring + /// is checked here. + #[rstest] + fn every_role_starts_containerdebug_from_the_given_config( + #[values("2.9.3", "3.3.2")] product_version: &str, + #[values( + ValidatedContainerdebugConfig::Enabled { + interval: Duration::from_minutes_unchecked(10), + }, + ValidatedContainerdebugConfig::Disabled + )] + containerdebug: ValidatedContainerdebugConfig, + ) { + let cluster = validated_cluster_with("kubernetesExecutors", "{config: {}}", |cluster| { + cluster["spec"]["image"]["productVersion"] = product_version.into(); + }); + assert_eq!(cluster.image.product_version, product_version); + let expected: Vec = containerdebug + .background_command(STACKABLE_LOG_DIR) + .into_iter() + .collect(); + + for role in AirflowRole::iter() { + let commands = role.get_commands(&cluster, &containerdebug).join("\n"); + let containerdebug_lines: Vec = commands + .lines() + .map(str::trim) + .filter(|line| line.starts_with("containerdebug ")) + .map(str::to_owned) + .collect(); + + assert_eq!(containerdebug_lines, expected, "{role:?}: {commands}"); + } + } }