diff --git a/CHANGELOG.md b/CHANGELOG.md index bd609141..21777374 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 `TRINO_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 ([#734]). ### Fixed - Use `json` file extension for log files ([#733]). +- Fix a bug where changes to ConfigMaps that are referenced in the TrinoCluster spec didn't trigger a reconciliation ([#734]). [#728]: https://github.com/stackabletech/trino-operator/pull/728 +[#734]: https://github.com/stackabletech/trino-operator/pull/734 [#733]: https://github.com/stackabletech/trino-operator/pull/733 ## [25.3.0] - 2025-03-21 diff --git a/Cargo.lock b/Cargo.lock index 89a8c0bd..8dccba86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2696,8 +2696,8 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[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", @@ -2732,7 +2732,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", @@ -2743,7 +2743,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 6523afd7..84cb2c69 100644 --- a/Cargo.nix +++ b/Cargo.nix @@ -8607,13 +8607,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 = [ @@ -8758,8 +8758,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"; @@ -8793,8 +8793,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 6f9959e1..e33b7d38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/stackabletech/trino-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/controller.rs b/rust/operator-binary/src/controller.rs index cae36f93..36e76313 100644 --- a/rust/operator-binary/src/controller.rs +++ b/rust/operator-binary/src/controller.rs @@ -93,7 +93,7 @@ use crate::{ operations::{ add_graceful_shutdown_config, graceful_shutdown_config_properties, pdb::add_pdbs, }, - product_logging::{get_log_properties, get_vector_toml, resolve_vector_aggregator_address}, + product_logging::{get_log_properties, get_vector_toml}, }; pub struct Ctx { @@ -230,10 +230,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 build vector container"))] BuildVectorContainer { source: LoggingError }, @@ -470,10 +468,6 @@ pub async fn reconcile_trino( create_shared_internal_secret(trino, client).await?; - let vector_aggregator_address = resolve_vector_aggregator_address(trino, client) - .await - .context(ResolveVectorAggregatorAddressSnafu)?; - let mut sts_cond_builder = StatefulSetConditionBuilder::default(); for (trino_role_str, role_config) in validated_config { @@ -498,7 +492,6 @@ pub async fn reconcile_trino( &merged_config, &trino_authentication_config, &trino_opa_config, - vector_aggregator_address.as_deref(), &client.kubernetes_cluster_info, )?; let rg_catalog_configmap = build_rolegroup_catalog_config_map( @@ -634,7 +627,6 @@ fn build_rolegroup_config_map( merged_config: &v1alpha1::TrinoConfig, trino_authentication_config: &TrinoAuthenticationConfig, trino_opa_config: &Option, - vector_aggregator_address: Option<&str>, cluster_info: &KubernetesClusterInfo, ) -> Result { let mut cm_conf_data = BTreeMap::new(); @@ -725,14 +717,11 @@ fn build_rolegroup_config_map( cm_conf_data.insert(file_name.to_string(), log_properties); } - if let Some(vector_toml) = get_vector_toml( - rolegroup_ref, - vector_aggregator_address, - &merged_config.logging, - ) - .context(InvalidLoggingConfigSnafu { - cm_name: rolegroup_ref.object_name(), - })? { + if let Some(vector_toml) = get_vector_toml(rolegroup_ref, &merged_config.logging) + .context(InvalidLoggingConfigSnafu { + cm_name: rolegroup_ref.object_name(), + })? + { cm_conf_data.insert( product_logging::framework::VECTOR_CONFIG_FILE.to_string(), vector_toml, @@ -1079,21 +1068,29 @@ fn build_rolegroup_statefulset( } 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(BuildVectorContainerSnafu)?, - ); + match &trino.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(BuildVectorContainerSnafu)?, + ); + } + None => { + VectorAggregatorConfigMapMissingSnafu.fail()?; + } + } } let metadata = ObjectMetaBuilder::new() @@ -1812,7 +1809,6 @@ mod tests { &merged_config, &trino_authentication_config, &trino_opa_config, - None, &cluster_info, ) .unwrap() diff --git a/rust/operator-binary/src/main.rs b/rust/operator-binary/src/main.rs index 36c8af16..9fe7b596 100644 --- a/rust/operator-binary/src/main.rs +++ b/rust/operator-binary/src/main.rs @@ -137,8 +137,9 @@ async fn main() -> anyhow::Result<()> { watch_namespace.get_api::>(&client), watcher::Config::default(), ); - let catalog_cluster_store = Arc::new(cluster_controller.store()); - let authentication_class_cluster_store = catalog_cluster_store.clone(); + let catalog_cluster_store = cluster_controller.store(); + let authentication_class_cluster_store = cluster_controller.store(); + let config_map_cluster_store = cluster_controller.store(); cluster_controller .owns( @@ -181,6 +182,17 @@ async fn main() -> anyhow::Result<()> { .map(|trino| ObjectRef::from_obj(&*trino)) }, ) + .watches( + watch_namespace.get_api::>(&client), + watcher::Config::default(), + move |config_map| { + config_map_cluster_store + .state() + .into_iter() + .filter(move |druid| references_config_map(druid, &config_map)) + .map(|druid| ObjectRef::from_obj(&*druid)) + }, + ) .run( controller::reconcile_trino, controller::error_policy, @@ -229,3 +241,20 @@ fn references_authentication_class( .iter() .any(|c| c.authentication_class_name() == &authentication_class_name) } + +fn references_config_map( + trino: &DeserializeGuard, + config_map: &DeserializeGuard, +) -> bool { + let Ok(trino) = &trino.0 else { + return false; + }; + + match &trino.spec.cluster_config.authorization { + Some(trino_authorization) => match &trino_authorization.opa { + Some(opa_config) => opa_config.config_map_name == config_map.name_any(), + None => false, + }, + None => false, + } +} diff --git a/rust/operator-binary/src/product_logging.rs b/rust/operator-binary/src/product_logging.rs index 77e078d4..0906218d 100644 --- a/rust/operator-binary/src/product_logging.rs +++ b/rust/operator-binary/src/product_logging.rs @@ -1,8 +1,5 @@ -use snafu::{OptionExt, ResultExt, Snafu}; +use snafu::Snafu; use stackable_operator::{ - client::Client, - k8s_openapi::api::core::v1::ConfigMap, - kube::ResourceExt, product_logging::{ framework::create_vector_config, spec::{ @@ -32,15 +29,10 @@ pub enum Error { entry: &'static str, cm_name: String, }, - - #[snafu(display("vectorAggregatorConfigMapName must be set"))] - MissingVectorAggregatorAddress, } type Result = std::result::Result; -const VECTOR_AGGREGATOR_CM_ENTRY: &str = "ADDRESS"; - #[derive(Display)] #[strum(serialize_all = "lowercase")] pub enum TrinoLogLevel { @@ -63,44 +55,6 @@ impl From for TrinoLogLevel { } } -/// 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( - trino: &v1alpha1::TrinoCluster, - client: &Client, -) -> Result> { - let vector_aggregator_address = if let Some(vector_aggregator_config_map_name) = &trino - .spec - .cluster_config - .vector_aggregator_config_map_name - .as_ref() - { - let vector_aggregator_address = client - .get::( - vector_aggregator_config_map_name, - trino - .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) -} - /// Return the `log.properties` configuration pub fn get_log_properties(logging: &Logging) -> Option { if let Some(ContainerLogConfig { @@ -116,7 +70,6 @@ pub fn get_log_properties(logging: &Logging) -> Option { /// Return the vector toml configuration pub fn get_vector_toml( rolegroup: &RoleGroupRef, - vector_aggregator_address: Option<&str>, logging: &Logging, ) -> Result> { let vector_log_config = if let Some(ContainerLogConfig { @@ -129,11 +82,7 @@ pub fn get_vector_toml( }; if logging.enable_vector_agent { - Ok(Some(create_vector_config( - rolegroup, - vector_aggregator_address.context(MissingVectorAggregatorAddressSnafu)?, - vector_log_config, - ))) + Ok(Some(create_vector_config(rolegroup, vector_log_config))) } else { Ok(None) }