Skip to content

Commit 4956fbd

Browse files
feat: Inject vector aggregator address as env into vector config (#707)
* inject vector aggregator address as env into config & add watch for referenced cms * add pr number to changelog * regenerate nix * fix changelog * chore: Use borrows --------- Co-authored-by: Nick Larsen <nick.larsen@stackable.tech>
1 parent 3693dc9 commit 4956fbd

File tree

7 files changed

+54
-101
lines changed

7 files changed

+54
-101
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ All notable changes to this project will be documented in this file.
1818
- BREAKING: user-info-fetcher: The file log directory was set by `OPA_OPERATOR_LOG_DIRECTORY`,
1919
and is now set by `ROLLING_LOGS` (or via `--rolling-logs <DIRECTORY>`).
2020
- Replace stackable-operator `print_startup_string` with `tracing::info!` with fields.
21+
- BREAKING: Inject the vector aggregator address into the vector config using the env var `VECTOR_AGGREGATOR_ADDRESS` instead
22+
of having the operator write it to the vector config ([#707]).
2123

2224
### Fixed
2325

2426
- Use `json` file extension for log files ([#709]).
2527

2628
[#703]: https://github.com/stackabletech/opa-operator/pull/703
29+
[#707]: https://github.com/stackabletech/opa-operator/pull/707
2730
[#709]: https://github.com/stackabletech/opa-operator/pull/709
2831

2932
## [25.3.0] - 2025-03-21

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repository = "https://github.com/stackabletech/opa-operator"
1111

1212
[workspace.dependencies]
1313
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }
14-
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.89.1" }
14+
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.90.0" }
1515
stackable-telemetry = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-telemetry-0.4.0" }
1616
stackable-versioned = { git = "https://github.com/stackabletech/operator-rs.git", features = ["k8s"], tag = "stackable-versioned-0.6.0" }
1717

crate-hashes.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/operator-binary/src/controller.rs

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ use strum::{EnumDiscriminants, IntoStaticStr};
7676
use crate::{
7777
discovery::{self, build_discovery_configmaps},
7878
operations::graceful_shutdown::add_graceful_shutdown_config,
79-
product_logging::{
80-
BundleBuilderLogLevel, extend_role_group_config_map, resolve_vector_aggregator_address,
81-
},
79+
product_logging::{BundleBuilderLogLevel, extend_role_group_config_map},
8280
};
8381

8482
pub const OPA_CONTROLLER_NAME: &str = "opacluster";
@@ -251,10 +249,8 @@ pub enum Error {
251249
source: stackable_operator::builder::pod::container::Error,
252250
},
253251

254-
#[snafu(display("failed to resolve the Vector aggregator address"))]
255-
ResolveVectorAggregatorAddress {
256-
source: crate::product_logging::Error,
257-
},
252+
#[snafu(display("vector agent is enabled but vector aggregator ConfigMap is missing"))]
253+
VectorAggregatorConfigMapMissing,
258254

259255
#[snafu(display("failed to add the logging configuration to the ConfigMap [{cm_name}]"))]
260256
InvalidLoggingConfig {
@@ -443,10 +439,6 @@ pub async fn reconcile_opa(
443439
.map(Cow::Borrowed)
444440
.unwrap_or_default();
445441

446-
let vector_aggregator_address = resolve_vector_aggregator_address(opa, client)
447-
.await
448-
.context(ResolveVectorAggregatorAddressSnafu)?;
449-
450442
let server_role_service = build_server_role_service(opa, &resolved_product_image)?;
451443
// required for discovery config map later
452444
let server_role_service = cluster_resources
@@ -488,7 +480,6 @@ pub async fn reconcile_opa(
488480
&resolved_product_image,
489481
&rolegroup,
490482
&merged_config,
491-
vector_aggregator_address.as_deref(),
492483
)?;
493484
let rg_service = build_rolegroup_service(opa, &resolved_product_image, &rolegroup)?;
494485
let rg_daemonset = build_server_rolegroup_daemonset(
@@ -682,7 +673,6 @@ fn build_server_rolegroup_config_map(
682673
resolved_product_image: &ResolvedProductImage,
683674
rolegroup: &RoleGroupRef<v1alpha1::OpaCluster>,
684675
merged_config: &v1alpha1::OpaConfig,
685-
vector_aggregator_address: Option<&str>,
686676
) -> Result<ConfigMap> {
687677
let mut cm_builder = ConfigMapBuilder::new();
688678

@@ -711,15 +701,11 @@ fn build_server_rolegroup_config_map(
711701
);
712702
}
713703

714-
extend_role_group_config_map(
715-
rolegroup,
716-
vector_aggregator_address,
717-
&merged_config.logging,
718-
&mut cm_builder,
719-
)
720-
.context(InvalidLoggingConfigSnafu {
721-
cm_name: rolegroup.object_name(),
722-
})?;
704+
extend_role_group_config_map(rolegroup, &merged_config.logging, &mut cm_builder).context(
705+
InvalidLoggingConfigSnafu {
706+
cm_name: rolegroup.object_name(),
707+
},
708+
)?;
723709

724710
cm_builder
725711
.build()
@@ -1034,24 +1020,32 @@ fn build_server_rolegroup_daemonset(
10341020
}
10351021

10361022
if merged_config.logging.enable_vector_agent {
1037-
pb.add_container(
1038-
product_logging::framework::vector_container(
1039-
resolved_product_image,
1040-
CONFIG_VOLUME_NAME,
1041-
LOG_VOLUME_NAME,
1042-
merged_config
1043-
.logging
1044-
.containers
1045-
.get(&v1alpha1::Container::Vector),
1046-
ResourceRequirementsBuilder::new()
1047-
.with_cpu_request("250m")
1048-
.with_cpu_limit("500m")
1049-
.with_memory_request("128Mi")
1050-
.with_memory_limit("128Mi")
1051-
.build(),
1052-
)
1053-
.context(ConfigureLoggingSnafu)?,
1054-
);
1023+
match &opa.spec.cluster_config.vector_aggregator_config_map_name {
1024+
Some(vector_aggregator_config_map_name) => {
1025+
pb.add_container(
1026+
product_logging::framework::vector_container(
1027+
resolved_product_image,
1028+
CONFIG_VOLUME_NAME,
1029+
LOG_VOLUME_NAME,
1030+
merged_config
1031+
.logging
1032+
.containers
1033+
.get(&v1alpha1::Container::Vector),
1034+
ResourceRequirementsBuilder::new()
1035+
.with_cpu_request("250m")
1036+
.with_cpu_limit("500m")
1037+
.with_memory_request("128Mi")
1038+
.with_memory_limit("128Mi")
1039+
.build(),
1040+
vector_aggregator_config_map_name,
1041+
)
1042+
.context(ConfigureLoggingSnafu)?,
1043+
);
1044+
}
1045+
None => {
1046+
VectorAggregatorConfigMapMissingSnafu.fail()?;
1047+
}
1048+
}
10551049
}
10561050

10571051
add_graceful_shutdown_config(merged_config, &mut pb).context(GracefulShutdownSnafu)?;

rust/operator-binary/src/product_logging.rs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
use snafu::{OptionExt, ResultExt, Snafu};
1+
use snafu::Snafu;
22
use stackable_opa_operator::crd::v1alpha1;
33
use stackable_operator::{
44
builder::configmap::ConfigMapBuilder,
5-
client::Client,
6-
k8s_openapi::api::core::v1::ConfigMap,
7-
kube::ResourceExt,
85
product_logging::{
96
self,
107
spec::{ContainerLogConfig, ContainerLogConfigChoice, LogLevel, Logging},
@@ -32,8 +29,6 @@ pub enum Error {
3229

3330
type Result<T, E = Error> = std::result::Result<T, E>;
3431

35-
const VECTOR_AGGREGATOR_CM_ENTRY: &str = "ADDRESS";
36-
3732
#[derive(strum::Display)]
3833
#[strum(serialize_all = "lowercase")]
3934
pub enum OpaLogLevel {
@@ -74,44 +69,9 @@ impl From<LogLevel> for BundleBuilderLogLevel {
7469
}
7570
}
7671

77-
/// Return the address of the Vector aggregator if the corresponding ConfigMap name is given in the
78-
/// cluster spec
79-
pub async fn resolve_vector_aggregator_address(
80-
opa: &v1alpha1::OpaCluster,
81-
client: &Client,
82-
) -> Result<Option<String>> {
83-
let vector_aggregator_address = if let Some(vector_aggregator_config_map_name) =
84-
&opa.spec.cluster_config.vector_aggregator_config_map_name
85-
{
86-
let vector_aggregator_address = client
87-
.get::<ConfigMap>(
88-
vector_aggregator_config_map_name,
89-
opa.namespace()
90-
.as_deref()
91-
.context(ObjectHasNoNamespaceSnafu)?,
92-
)
93-
.await
94-
.context(ConfigMapNotFoundSnafu {
95-
cm_name: vector_aggregator_config_map_name.to_string(),
96-
})?
97-
.data
98-
.and_then(|mut data| data.remove(VECTOR_AGGREGATOR_CM_ENTRY))
99-
.context(MissingConfigMapEntrySnafu {
100-
entry: VECTOR_AGGREGATOR_CM_ENTRY,
101-
cm_name: vector_aggregator_config_map_name.to_string(),
102-
})?;
103-
Some(vector_aggregator_address)
104-
} else {
105-
None
106-
};
107-
108-
Ok(vector_aggregator_address)
109-
}
110-
11172
/// Extend the role group ConfigMap with logging and Vector configurations
11273
pub fn extend_role_group_config_map(
11374
rolegroup: &RoleGroupRef<v1alpha1::OpaCluster>,
114-
vector_aggregator_address: Option<&str>,
11575
logging: &Logging<v1alpha1::Container>,
11676
cm_builder: &mut ConfigMapBuilder,
11777
) -> Result<()> {
@@ -127,11 +87,7 @@ pub fn extend_role_group_config_map(
12787
if logging.enable_vector_agent {
12888
cm_builder.add_data(
12989
product_logging::framework::VECTOR_CONFIG_FILE,
130-
product_logging::framework::create_vector_config(
131-
rolegroup,
132-
vector_aggregator_address.context(MissingVectorAggregatorAddressSnafu)?,
133-
vector_log_config,
134-
),
90+
product_logging::framework::create_vector_config(rolegroup, vector_log_config),
13591
);
13692
}
13793

0 commit comments

Comments
 (0)