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

Filter by extension

Filter by extension

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

## [Unreleased]

### Added

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

### Changed

- Getting started guide uses a KRaft cluster instead of ZooKeeper and declares its topic with a
KafkaTopic managed by the agent ([#1079]).

[#1079]: https://github.com/stackabletech/kafka-operator/pull/1079
[#1081]: https://github.com/stackabletech/kafka-operator/pull/1081

## [26.11.0] - 2026-11-20

Expand Down
4 changes: 4 additions & 0 deletions docs/modules/kafka/pages/usage-guide/logging.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ spec:
vectorAggregatorConfigMapName: vector-aggregator-discovery
brokers:
config:
containerdebug:
enabled: false
logging:
enableVectorAgent: true
----
Expand All @@ -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/kafka` 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[].
80 changes: 80 additions & 0 deletions extra/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ spec:
nullable: true
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
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
Expand Down Expand Up @@ -544,6 +564,26 @@ spec:
nullable: true
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
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
Expand Down Expand Up @@ -1252,6 +1292,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
Expand Down Expand Up @@ -1694,6 +1754,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
Expand Down
7 changes: 6 additions & 1 deletion rust/operator-binary/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use stackable_operator::{
resources::{NoRuntimeLimits, Resources},
},
constant,
crd::{listener, management_access::v1alpha1::TlsClientCredential},
crd::{
containerdebug::ValidatedContainerdebugConfig, listener,
management_access::v1alpha1::TlsClientCredential,
},
k8s_openapi::api::{
apps::v1::{Deployment, StatefulSet},
core::v1::{ConfigMap, Service, ServiceAccount},
Expand Down Expand Up @@ -479,6 +482,7 @@ pub struct ValidatedBrokerConfig {
pub resources: Resources<Storage, NoRuntimeLimits>,
pub logging: validate::ValidatedLogging,
pub affinity: StackableAffinity,
pub containerdebug: ValidatedContainerdebugConfig,
pub graceful_shutdown_timeout: Duration,
pub requested_secret_lifetime: Duration,
pub bootstrap_listener_class: ListenerClassName,
Expand All @@ -493,6 +497,7 @@ pub struct ValidatedControllerConfig {
pub resources: Resources<Storage, NoRuntimeLimits>,
pub logging: validate::ValidatedLogging,
pub affinity: StackableAffinity,
pub containerdebug: ValidatedContainerdebugConfig,
pub graceful_shutdown_timeout: Duration,
pub requested_secret_lifetime: Duration,
}
Expand Down
32 changes: 26 additions & 6 deletions rust/operator-binary/src/controller/build/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::str::FromStr;
use indoc::formatdoc;
use stackable_operator::{
constant,
crd::containerdebug::ValidatedContainerdebugConfig,
product_logging::framework::{
create_vector_shutdown_file_command, remove_vector_shutdown_file_command,
},
Expand Down Expand Up @@ -55,13 +56,14 @@ const EXPORT_REPLICA_ID: &str = "export REPLICA_ID=$((POD_INDEX + NODE_ID_OFFSET
pub fn broker_kafka_container_commands(
kraft_mode: bool,
kafka_security: &ValidatedKafkaSecurity,
containerdebug: &ValidatedContainerdebugConfig,
) -> String {
formatdoc! {"
{COMMON_BASH_TRAP_FUNCTIONS}
{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}
{set_realm_env}

{import_opa_tls_cert}
Expand All @@ -73,6 +75,9 @@ pub fn broker_kafka_container_commands(
",
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),
set_realm_env = export_kerberos_realm_command(kafka_security).unwrap_or_default(),
import_opa_tls_cert = copy_opa_tls_cert_command(kafka_security),
Expand Down Expand Up @@ -149,13 +154,14 @@ fn controller_quorum_format_flag(bootstrap_node_id: Option<u32>) -> String {
pub fn controller_kafka_container_command(
kafka_security: &ValidatedKafkaSecurity,
bootstrap_node_id: Option<u32>,
containerdebug: &ValidatedContainerdebugConfig,
) -> String {
formatdoc! {"
{COMMON_BASH_TRAP_FUNCTIONS}
{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}

{import_opa_tls_cert}

Expand All @@ -178,6 +184,9 @@ pub fn controller_kafka_container_command(
",
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(),
import_opa_tls_cert = copy_opa_tls_cert_command(kafka_security),
derive_pod_index = DERIVE_POD_INDEX,
export_replica_id = EXPORT_REPLICA_ID,
Expand Down Expand Up @@ -389,14 +398,22 @@ mod tests {
use indoc::indoc;

use super::*;

/// The `containerdebug` config every role group gets when it configures none.
fn default_containerdebug() -> ValidatedContainerdebugConfig {
ValidatedContainerdebugConfig::Enabled {
interval: stackable_operator::crd::containerdebug::DEFAULT_INTERVAL,
}
}
use crate::controller::test_support::{kerberos, plaintext};

#[test]
fn controller_command_has_no_kerberos_setup() {
// The controllers never use Kerberos: the nodes authenticate each other with their
// internal pod certificates, also when Kerberos is enabled for clients.
for security in [kerberos(), plaintext()] {
let command = controller_kafka_container_command(&security, None);
let command =
controller_kafka_container_command(&security, None, &default_containerdebug());
assert!(!command.contains("KERBEROS_REALM"));
assert!(!command.contains("jaas.properties"));
}
Expand All @@ -419,7 +436,8 @@ mod tests {

#[test]
fn controller_command_templates_the_admin_client_config_for_pre_stop() {
let command = controller_kafka_container_command(&kerberos(), None);
let command =
controller_kafka_container_command(&kerberos(), None, &default_containerdebug());
assert!(
command.contains(
"cp /stackable/config/admin-client.properties /tmp/admin-client.properties"
Expand Down Expand Up @@ -1135,7 +1153,8 @@ mod tests {
/// (`--no-initial-controllers`).
#[test]
fn controller_kafka_container_command_branches_on_the_bootstrap_node_id() {
let command = controller_kafka_container_command(&plaintext(), Some(5));
let command =
controller_kafka_container_command(&plaintext(), Some(5), &default_containerdebug());

assert!(command.contains(r#"if [ "$REPLICA_ID" = "5" ]; then"#));
assert!(command.contains("FORMAT_QUORUM_FLAG=--standalone"));
Expand All @@ -1151,7 +1170,8 @@ mod tests {
/// Without a bootstrap controller, no controller may bootstrap a quorum.
#[test]
fn controller_kafka_container_command_without_bootstrap_node_id_never_uses_standalone() {
let command = controller_kafka_container_command(&plaintext(), None);
let command =
controller_kafka_container_command(&plaintext(), None, &default_containerdebug());
assert!(command.contains("FORMAT_QUORUM_FLAG=--no-initial-controllers"));
assert!(!command.contains("--standalone"));
}
Expand Down
71 changes: 71 additions & 0 deletions rust/operator-binary/src/controller/build/role_group/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ fn role_pod(
.args(vec![broker_kafka_container_commands(
cluster.cluster_config.is_kraft_mode(),
kafka_security,
&config.containerdebug,
)]);

cb_kafka
Expand Down Expand Up @@ -474,4 +475,74 @@ mod tests {
// Kerberos, so there is no login context for the CONTROLLER listener.
assert!(!jaas.contains("controller.KafkaServer"));
}

/// The kafka container starts `containerdebug` from the role group's validated config, which
/// reaches the start command through the role group's Pod. 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 kafka_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 = crate::controller::test_support::validated_cluster(
&crate::controller::test_support::minimal_kafka(
r#"
apiVersion: kafka.stackable.tech/v1alpha1
kind: KafkaCluster
metadata:
name: simple-kafka
namespace: default
uid: 12345678-1234-1234-1234-123456789012
spec:
image:
productVersion: 3.9.2
clusterConfig:
metadataManager: KRaft
controllers:
roleGroups:
default:
replicas: 1
brokers:
roleGroups:
default:
replicas: 1
"#,
),
);
let role_group_name: RoleGroupName = "default".parse().expect("valid role group name");
let mut validated_rg =
crate::controller::test_support::broker_role_group_config(&cluster, "default").clone();
validated_rg.config.containerdebug = containerdebug;

let (builder, _) =
build(&cluster, &role_group_name, &validated_rg).expect("the role group builds");
let args = builder
.build_statefulset()
.expect("the StatefulSet builds")
.spec
.and_then(|spec| spec.template.spec)
.expect("the StatefulSet has a pod spec")
.containers
.into_iter()
.find(|container| container.name == "kafka")
.and_then(|container| container.args)
.expect("the kafka container has args")
.join("\n");

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