diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b95c2ac..3bcd5da0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,12 +10,16 @@ All notable changes to this project will be documented in this file. - BREAKING: The file log directory was set by `KAFKA_OPERATOR_LOG_DIRECTORY`, and is now set by `ROLLING_LOGS` (or via `--rolling-logs `). - Replace stackable-operator `print_startup_string` with `tracing::info!` with fields. +- BREAKING: Inject the vector aggregator address into the vector config using the env var `VECTOR_AGGREGATOR_ADDRESS` instead + of having the operator write it to the vector config ([#844]). ### Fixed - Use `json` file extension for log files ([#846]). +- Fix a bug where changes to ConfigMaps that are referenced in the KafkaCluster spec didn't trigger a reconciliation ([#844]). [#840]: https://github.com/stackabletech/kafka-operator/pull/840 +[#844]: https://github.com/stackabletech/kafka-operator/pull/844 [#846]: https://github.com/stackabletech/kafka-operator/pull/846 ## [25.3.0] - 2025-03-21 diff --git a/Cargo.lock b/Cargo.lock index 1469e7d9..264598bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2660,8 +2660,8 @@ dependencies = [ [[package]] name = "stackable-operator" -version = "0.89.1" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.89.1#cd73728af410c52972b9a9a3ba1302bcdb574d04" +version = "0.90.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.90.0#ea063b4595caa20c82d37c595487c76476c9ab10" dependencies = [ "chrono", "clap", @@ -2696,7 +2696,7 @@ dependencies = [ [[package]] name = "stackable-operator-derive" version = "0.3.1" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.89.1#cd73728af410c52972b9a9a3ba1302bcdb574d04" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.90.0#ea063b4595caa20c82d37c595487c76476c9ab10" dependencies = [ "darling", "proc-macro2", @@ -2707,7 +2707,7 @@ dependencies = [ [[package]] name = "stackable-shared" version = "0.0.1" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.89.1#cd73728af410c52972b9a9a3ba1302bcdb574d04" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.90.0#ea063b4595caa20c82d37c595487c76476c9ab10" dependencies = [ "kube", "semver", diff --git a/Cargo.nix b/Cargo.nix index 594a3028..f4349e56 100644 --- a/Cargo.nix +++ b/Cargo.nix @@ -8544,13 +8544,13 @@ rec { }; "stackable-operator" = rec { crateName = "stackable-operator"; - version = "0.89.1"; + version = "0.90.0"; edition = "2024"; workspace_member = null; src = pkgs.fetchgit { url = "https://github.com/stackabletech/operator-rs.git"; - rev = "cd73728af410c52972b9a9a3ba1302bcdb574d04"; - sha256 = "1hrxrybc6197ibx0m2wfxlg5pdg4hanf6xvslzrhsp77a04pb0y9"; + rev = "ea063b4595caa20c82d37c595487c76476c9ab10"; + sha256 = "0fclvpxhchykqd7bl8hscr4v06mbs2v5vjp0xv27nvqr94j63xs2"; }; libName = "stackable_operator"; authors = [ @@ -8695,8 +8695,8 @@ rec { workspace_member = null; src = pkgs.fetchgit { url = "https://github.com/stackabletech/operator-rs.git"; - rev = "cd73728af410c52972b9a9a3ba1302bcdb574d04"; - sha256 = "1hrxrybc6197ibx0m2wfxlg5pdg4hanf6xvslzrhsp77a04pb0y9"; + rev = "ea063b4595caa20c82d37c595487c76476c9ab10"; + sha256 = "0fclvpxhchykqd7bl8hscr4v06mbs2v5vjp0xv27nvqr94j63xs2"; }; procMacro = true; libName = "stackable_operator_derive"; @@ -8730,8 +8730,8 @@ rec { workspace_member = null; src = pkgs.fetchgit { url = "https://github.com/stackabletech/operator-rs.git"; - rev = "cd73728af410c52972b9a9a3ba1302bcdb574d04"; - sha256 = "1hrxrybc6197ibx0m2wfxlg5pdg4hanf6xvslzrhsp77a04pb0y9"; + rev = "ea063b4595caa20c82d37c595487c76476c9ab10"; + sha256 = "0fclvpxhchykqd7bl8hscr4v06mbs2v5vjp0xv27nvqr94j63xs2"; }; libName = "stackable_shared"; authors = [ diff --git a/Cargo.toml b/Cargo.toml index 7204bdb3..f02166e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/stackabletech/kafka-operator" [workspace.dependencies] product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" } -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.89.1" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.90.0" } stackable-telemetry = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-telemetry-0.4.0" } stackable-versioned = { git = "https://github.com/stackabletech/operator-rs.git", features = ["k8s"], tag = "stackable-versioned-0.7.1" } diff --git a/crate-hashes.json b/crate-hashes.json index 0460dbd5..c8a9703a 100644 --- a/crate-hashes.json +++ b/crate-hashes.json @@ -1,7 +1,7 @@ { - "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.89.1#stackable-operator-derive@0.3.1": "1hrxrybc6197ibx0m2wfxlg5pdg4hanf6xvslzrhsp77a04pb0y9", - "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.89.1#stackable-operator@0.89.1": "1hrxrybc6197ibx0m2wfxlg5pdg4hanf6xvslzrhsp77a04pb0y9", - "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.89.1#stackable-shared@0.0.1": "1hrxrybc6197ibx0m2wfxlg5pdg4hanf6xvslzrhsp77a04pb0y9", + "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.90.0#stackable-operator-derive@0.3.1": "0fclvpxhchykqd7bl8hscr4v06mbs2v5vjp0xv27nvqr94j63xs2", + "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.90.0#stackable-operator@0.90.0": "0fclvpxhchykqd7bl8hscr4v06mbs2v5vjp0xv27nvqr94j63xs2", + "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.90.0#stackable-shared@0.0.1": "0fclvpxhchykqd7bl8hscr4v06mbs2v5vjp0xv27nvqr94j63xs2", "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-telemetry-0.4.0#stackable-telemetry@0.4.0": "0hcm64fb2ngyalq8rci5lrr881prg023pq9cd1sfr79iynbr6a26", "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-versioned-0.7.1#k8s-version@0.1.2": "16klfwx3kz3ys7afwjicfj8msws9a718izx09jspwwpff3rl6wsi", "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-versioned-0.7.1#stackable-versioned-macros@0.7.1": "16klfwx3kz3ys7afwjicfj8msws9a718izx09jspwwpff3rl6wsi", diff --git a/rust/operator-binary/src/kafka_controller.rs b/rust/operator-binary/src/kafka_controller.rs index bb6fa51d..1fc37461 100644 --- a/rust/operator-binary/src/kafka_controller.rs +++ b/rust/operator-binary/src/kafka_controller.rs @@ -92,10 +92,7 @@ use crate::{ graceful_shutdown::{add_graceful_shutdown_config, graceful_shutdown_config_properties}, pdb::add_pdbs, }, - product_logging::{ - LOG4J_CONFIG_FILE, MAX_KAFKA_LOG_FILES_SIZE, extend_role_group_config_map, - resolve_vector_aggregator_address, - }, + product_logging::{LOG4J_CONFIG_FILE, MAX_KAFKA_LOG_FILES_SIZE, extend_role_group_config_map}, utils::build_recommended_labels, }; @@ -253,10 +250,8 @@ pub enum Error { #[snafu(display("failed to resolve and merge config for role and role group"))] FailedToResolveConfig { source: crate::crd::Error }, - #[snafu(display("failed to resolve the Vector aggregator address"))] - ResolveVectorAggregatorAddress { - source: crate::product_logging::Error, - }, + #[snafu(display("vector agent is enabled but vector aggregator ConfigMap is missing"))] + VectorAggregatorConfigMapMissing, #[snafu(display("failed to add the logging configuration to the ConfigMap [{cm_name}]"))] InvalidLoggingConfig { @@ -396,7 +391,7 @@ impl ReconcilerError for Error { Error::FailedToInitializeSecurityContext { .. } => None, Error::CreateClusterResources { .. } => None, Error::FailedToResolveConfig { .. } => None, - Error::ResolveVectorAggregatorAddress { .. } => None, + Error::VectorAggregatorConfigMapMissing { .. } => None, Error::InvalidLoggingConfig { .. } => None, Error::ApplyServiceAccount { .. } => None, Error::ApplyRoleBinding { .. } => None, @@ -508,10 +503,6 @@ pub async fn reconcile_kafka( None }; - let vector_aggregator_address = resolve_vector_aggregator_address(kafka, client) - .await - .context(ResolveVectorAggregatorAddressSnafu)?; - let mut ss_cond_builder = StatefulSetConditionBuilder::default(); let (rbac_sa, rbac_rolebinding) = build_rbac_resources( @@ -550,7 +541,6 @@ pub async fn reconcile_kafka( &rolegroup_ref, rolegroup_config, &merged_config, - vector_aggregator_address.as_deref(), )?; let rg_statefulset = build_broker_rolegroup_statefulset( kafka, @@ -688,7 +678,6 @@ fn build_broker_rolegroup_config_map( rolegroup: &RoleGroupRef, broker_config: &HashMap>, merged_config: &KafkaConfig, - vector_aggregator_address: Option<&str>, ) -> Result { let mut server_cfg = broker_config .get(&PropertyNameKind::File(SERVER_PROPERTIES_FILE.to_string())) @@ -751,15 +740,11 @@ fn build_broker_rolegroup_config_map( tracing::debug!(?server_cfg, "Applied server config"); tracing::debug!(?jvm_sec_props, "Applied JVM config"); - extend_role_group_config_map( - rolegroup, - vector_aggregator_address, - &merged_config.logging, - &mut cm_builder, - ) - .context(InvalidLoggingConfigSnafu { - cm_name: rolegroup.object_name(), - })?; + extend_role_group_config_map(rolegroup, &merged_config.logging, &mut cm_builder).context( + InvalidLoggingConfigSnafu { + cm_name: rolegroup.object_name(), + }, + )?; cm_builder .build() @@ -1114,21 +1099,29 @@ fn build_broker_rolegroup_statefulset( // Add vector container after kafka container to keep the defaulting into kafka container if merged_config.logging.enable_vector_agent { - pod_builder.add_container( - product_logging::framework::vector_container( - resolved_product_image, - "config", - "log", - merged_config.logging.containers.get(&Container::Vector), - ResourceRequirementsBuilder::new() - .with_cpu_request("250m") - .with_cpu_limit("500m") - .with_memory_request("128Mi") - .with_memory_limit("128Mi") - .build(), - ) - .context(ConfigureLoggingSnafu)?, - ); + match &kafka.spec.cluster_config.vector_aggregator_config_map_name { + Some(vector_aggregator_config_map_name) => { + pod_builder.add_container( + product_logging::framework::vector_container( + resolved_product_image, + "config", + "log", + merged_config.logging.containers.get(&Container::Vector), + ResourceRequirementsBuilder::new() + .with_cpu_request("250m") + .with_cpu_limit("500m") + .with_memory_request("128Mi") + .with_memory_limit("128Mi") + .build(), + vector_aggregator_config_map_name, + ) + .context(ConfigureLoggingSnafu)?, + ); + } + None => { + VectorAggregatorConfigMapMissingSnafu.fail()?; + } + } } add_graceful_shutdown_config(merged_config, &mut pod_builder).context(GracefulShutdownSnafu)?; diff --git a/rust/operator-binary/src/main.rs b/rust/operator-binary/src/main.rs index 7356b448..ab665bab 100644 --- a/rust/operator-binary/src/main.rs +++ b/rust/operator-binary/src/main.rs @@ -14,10 +14,12 @@ use stackable_operator::{ rbac::v1::RoleBinding, }, kube::{ + ResourceExt, core::DeserializeGuard, runtime::{ Controller, events::{Recorder, Reporter}, + reflector::ObjectRef, watcher, }, }, @@ -156,55 +158,87 @@ pub async fn create_controller( instance: None, })); - Controller::new( + let kafka_controller = Controller::new( namespace.get_api::>(&client), watcher::Config::default(), - ) - .owns( - namespace.get_api::(&client), - watcher::Config::default(), - ) - .owns( - namespace.get_api::(&client), - watcher::Config::default(), - ) - .owns( - namespace.get_api::(&client), - watcher::Config::default(), - ) - .owns( - namespace.get_api::(&client), - watcher::Config::default(), - ) - .owns( - namespace.get_api::(&client), - watcher::Config::default(), - ) - .owns( - namespace.get_api::(&client), - watcher::Config::default(), - ) - .shutdown_on_signal() - .run( - kafka_controller::reconcile_kafka, - kafka_controller::error_policy, - Arc::new(kafka_controller::Ctx { - client: client.clone(), - product_config, - }), - ) - // We can let the reporting happen in the background - .for_each_concurrent( - 16, // concurrency limit - move |result| { - // The event_recorder needs to be shared across all invocations, so that - // events are correctly aggregated - let event_recorder = event_recorder.clone(); - async move { - report_controller_reconciled(&event_recorder, KAFKA_FULL_CONTROLLER_NAME, &result) + ); + let config_map_store = kafka_controller.store(); + kafka_controller + .owns( + namespace.get_api::(&client), + watcher::Config::default(), + ) + .owns( + namespace.get_api::(&client), + watcher::Config::default(), + ) + .owns( + namespace.get_api::(&client), + watcher::Config::default(), + ) + .owns( + namespace.get_api::(&client), + watcher::Config::default(), + ) + .owns( + namespace.get_api::(&client), + watcher::Config::default(), + ) + .owns( + namespace.get_api::(&client), + watcher::Config::default(), + ) + .shutdown_on_signal() + .watches( + namespace.get_api::>(&client), + watcher::Config::default(), + move |config_map| { + config_map_store + .state() + .into_iter() + .filter(move |kafka| references_config_map(kafka, &config_map)) + .map(|kafka| ObjectRef::from_obj(&*kafka)) + }, + ) + .run( + kafka_controller::reconcile_kafka, + kafka_controller::error_policy, + Arc::new(kafka_controller::Ctx { + client: client.clone(), + product_config, + }), + ) + // We can let the reporting happen in the background + .for_each_concurrent( + 16, // concurrency limit + move |result| { + // The event_recorder needs to be shared across all invocations, so that + // events are correctly aggregated + let event_recorder = event_recorder.clone(); + async move { + report_controller_reconciled( + &event_recorder, + KAFKA_FULL_CONTROLLER_NAME, + &result, + ) .await; - } - }, - ) - .await; + } + }, + ) + .await; +} + +fn references_config_map( + kafka: &DeserializeGuard, + config_map: &DeserializeGuard, +) -> bool { + let Ok(kafka) = &kafka.0 else { + return false; + }; + + kafka.spec.cluster_config.zookeeper_config_map_name == config_map.name_any() + || match &kafka.spec.cluster_config.authorization.opa { + Some(opa_config) => opa_config.config_map_name == config_map.name_any(), + None => false, + } } diff --git a/rust/operator-binary/src/product_logging.rs b/rust/operator-binary/src/product_logging.rs index fc58e460..2ba77898 100644 --- a/rust/operator-binary/src/product_logging.rs +++ b/rust/operator-binary/src/product_logging.rs @@ -1,9 +1,6 @@ -use snafu::{OptionExt, ResultExt, Snafu}; +use snafu::Snafu; use stackable_operator::{ builder::configmap::ConfigMapBuilder, - client::Client, - k8s_openapi::api::core::v1::ConfigMap, - kube::ResourceExt, memory::{BinaryMultiple, MemoryQuantity}, product_logging::{ self, @@ -33,9 +30,6 @@ pub enum Error { #[snafu(display("crd validation failure"))] CrdValidationFailure { source: crate::crd::Error }, - - #[snafu(display("vectorAggregatorConfigMapName must be set"))] - MissingVectorAggregatorAddress, } type Result = std::result::Result; @@ -48,51 +42,11 @@ pub const MAX_KAFKA_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity { unit: BinaryMultiple::Mebi, }; -const VECTOR_AGGREGATOR_CM_ENTRY: &str = "ADDRESS"; const CONSOLE_CONVERSION_PATTERN: &str = "[%d] %p %m (%c)%n"; -/// Return the address of the Vector aggregator if the corresponding ConfigMap name is given in the -/// cluster spec -pub async fn resolve_vector_aggregator_address( - kafka: &v1alpha1::KafkaCluster, - client: &Client, -) -> Result> { - let vector_aggregator_address = if let Some(vector_aggregator_config_map_name) = &kafka - .spec - .cluster_config - .vector_aggregator_config_map_name - .as_ref() - { - let vector_aggregator_address = client - .get::( - vector_aggregator_config_map_name, - kafka - .namespace() - .as_deref() - .context(ObjectHasNoNamespaceSnafu)?, - ) - .await - .context(ConfigMapNotFoundSnafu { - cm_name: vector_aggregator_config_map_name.to_string(), - })? - .data - .and_then(|mut data| data.remove(VECTOR_AGGREGATOR_CM_ENTRY)) - .context(MissingConfigMapEntrySnafu { - entry: VECTOR_AGGREGATOR_CM_ENTRY, - cm_name: vector_aggregator_config_map_name.to_string(), - })?; - Some(vector_aggregator_address) - } else { - None - }; - - Ok(vector_aggregator_address) -} - /// Extend the role group ConfigMap with logging and Vector configurations pub fn extend_role_group_config_map( rolegroup: &RoleGroupRef, - vector_aggregator_address: Option<&str>, logging: &Logging, cm_builder: &mut ConfigMapBuilder, ) -> Result<()> { @@ -130,11 +84,7 @@ pub fn extend_role_group_config_map( if logging.enable_vector_agent { cm_builder.add_data( product_logging::framework::VECTOR_CONFIG_FILE, - product_logging::framework::create_vector_config( - rolegroup, - vector_aggregator_address.context(MissingVectorAggregatorAddressSnafu)?, - vector_log_config, - ), + product_logging::framework::create_vector_config(rolegroup, vector_log_config), ); }