Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
383 changes: 229 additions & 154 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/stackabletech/zookeeper-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", features = ["telemetry", "versioned"], tag = "stackable-operator-0.94.0" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", features = ["telemetry", "versioned"], tag = "stackable-operator-0.95.0" }

anyhow = "1.0"
built = { version = "0.8", features = ["chrono", "git2"] }
Expand All @@ -31,8 +31,8 @@ tokio = { version = "1.40", features = ["full"] }
tokio-zookeeper = "0.4"
tracing = "0.1"

#[patch."https://github.com/stackabletech/operator-rs"]
# stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "main" }
[patch."https://github.com/stackabletech/operator-rs"]
stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "main" }

[patch.crates-io]
# tokio-zookeeper = { path = "../tokio-zookeeper" }
Expand Down
22 changes: 18 additions & 4 deletions rust/operator-binary/src/config/jvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ fn construct_jvm_args(
zk: &ZookeeperCluster,
role: &Role<ZookeeperConfigFragment, ZookeeperServerRoleConfig, JavaCommonConfig>,
role_group: &str,
product_version: &str,
) -> Result<Vec<String>, Error> {
let logging_framework = zk.logging_framework();
let logging_framework = zk.logging_framework(product_version);

let jvm_args = vec![
format!("-Djava.security.properties={STACKABLE_CONFIG_DIR}/{JVM_SECURITY_PROPERTIES_FILE}"),
Expand Down Expand Up @@ -67,8 +68,9 @@ pub fn construct_non_heap_jvm_args(
zk: &ZookeeperCluster,
role: &Role<ZookeeperConfigFragment, ZookeeperServerRoleConfig, JavaCommonConfig>,
role_group: &str,
product_version: &str,
) -> Result<String, Error> {
let mut jvm_args = construct_jvm_args(zk, role, role_group)?;
let mut jvm_args = construct_jvm_args(zk, role, role_group, product_version)?;
jvm_args.retain(|arg| !is_heap_jvm_argument(arg));

Ok(jvm_args.join(" "))
Expand Down Expand Up @@ -122,7 +124,13 @@ mod tests {
replicas: 1
"#;
let (zookeeper, merged_config, role, rolegroup) = construct_boilerplate(input);
let non_heap_jvm_args = construct_non_heap_jvm_args(&zookeeper, &role, &rolegroup).unwrap();
let non_heap_jvm_args = construct_non_heap_jvm_args(
&zookeeper,
&role,
&rolegroup,
zookeeper.spec.image.product_version(),
)
.unwrap();
let zk_server_heap_env = construct_zk_server_heap_env(&merged_config).unwrap();

assert_eq!(
Expand Down Expand Up @@ -167,7 +175,13 @@ mod tests {
- -Dhttps.proxyPort=1234
"#;
let (zookeeper, merged_config, role, rolegroup) = construct_boilerplate(input);
let non_heap_jvm_args = construct_non_heap_jvm_args(&zookeeper, &role, &rolegroup).unwrap();
let non_heap_jvm_args = construct_non_heap_jvm_args(
&zookeeper,
&role,
&rolegroup,
zookeeper.spec.image.product_version(),
)
.unwrap();
let zk_server_heap_env = construct_zk_server_heap_env(&merged_config).unwrap();

assert_eq!(
Expand Down
16 changes: 2 additions & 14 deletions rust/operator-binary/src/crd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ pub const DOCKER_IMAGE_BASE_NAME: &str = "zookeeper";
const DEFAULT_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_minutes_unchecked(2);
pub const DEFAULT_LISTENER_CLASS: &str = "cluster-internal";

mod built_info {
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
}

#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("object has no namespace associated"))]
Expand Down Expand Up @@ -520,22 +516,14 @@ impl ZookeeperPodRef {
}

impl v1alpha1::ZookeeperCluster {
pub fn logging_framework(&self) -> LoggingFramework {
let version = self
.spec
.image
.resolve(
DOCKER_IMAGE_BASE_NAME,
crate::crd::built_info::CARGO_PKG_VERSION,
)
.product_version;
pub fn logging_framework(&self, product_version: &str) -> LoggingFramework {
let zookeeper_versions_with_log4j = [
"1.", "2.", "3.0.", "3.1.", "3.2.", "3.3.", "3.4.", "3.5.", "3.6.", "3.7.",
];

if zookeeper_versions_with_log4j
.into_iter()
.any(|prefix| version.starts_with(prefix))
.any(|prefix| product_version.starts_with(prefix))
{
LoggingFramework::LOG4J
} else {
Expand Down
2 changes: 1 addition & 1 deletion rust/operator-binary/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn build_discovery_configmap(
.with_recommended_labels(build_recommended_labels(
owner,
controller_name,
&resolved_product_image.app_version_label,
&resolved_product_image.app_version_label_value,
&ZookeeperRole::Server.to_string(),
"discovery",
))
Expand Down
2 changes: 1 addition & 1 deletion rust/operator-binary/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn build_role_listener(
.with_recommended_labels(build_recommended_labels(
zk,
ZK_CONTROLLER_NAME,
&resolved_product_image.app_version_label,
&resolved_product_image.app_version_label_value,
&zk_role.to_string(),
"none", // TODO (@NickLarsenNZ): update build_recommended_labels to have an optional role_group
))
Expand Down
10 changes: 5 additions & 5 deletions rust/operator-binary/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ async fn main() -> anyhow::Result<()> {
Command::Run(ProductOperatorRun {
product_config,
watch_namespace,
telemetry_arguments,
cluster_info_opts,
operator_environment: _,
telemetry,
cluster_info,
}) => {
// NOTE (@NickLarsenNZ): Before stackable-telemetry was used:
// - The console log level was set by `ZOOKEEPER_OPERATOR_LOG`, and is now `CONSOLE_LOG` (when using Tracing::pre_configured).
// - The file log level was set by `ZOOKEEPER_OPERATOR_LOG`, and is now set via `FILE_LOG` (when using Tracing::pre_configured).
// - The file log directory was set by `ZOOKEEPER_OPERATOR_LOG_DIRECTORY`, and is now set by `ROLLING_LOGS_DIR` (or via `--rolling-logs <DIRECTORY>`).
let _tracing_guard =
Tracing::pre_configured(built_info::PKG_NAME, telemetry_arguments).init()?;
let _tracing_guard = Tracing::pre_configured(built_info::PKG_NAME, telemetry).init()?;

tracing::info!(
built_info.pkg_version = built_info::PKG_VERSION,
Expand All @@ -93,7 +93,7 @@ async fn main() -> anyhow::Result<()> {
])?;
let client = stackable_operator::client::initialize_operator(
Some(OPERATOR_NAME.to_string()),
&cluster_info_opts,
&cluster_info,
)
.await?;

Expand Down
3 changes: 2 additions & 1 deletion rust/operator-binary/src/product_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn extend_role_group_config_map(
role: ZookeeperRole,
rolegroup: &RoleGroupRef<v1alpha1::ZookeeperCluster>,
cm_builder: &mut ConfigMapBuilder,
product_version: &str,
) -> Result<()> {
let logging = zk
.logging(&role, rolegroup)
Expand All @@ -54,7 +55,7 @@ pub fn extend_role_group_config_map(
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
}) = logging.containers.get(&v1alpha1::Container::Zookeeper)
{
match zk.logging_framework() {
match zk.logging_framework(product_version) {
LoggingFramework::LOG4J => {
cm_builder.add_data(
LOG4J_CONFIG_FILE,
Expand Down
55 changes: 38 additions & 17 deletions rust/operator-binary/src/zk_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use stackable_operator::{
},
},
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
commons::{product_image_selection::ResolvedProductImage, rbac::build_rbac_resources},
commons::{
product_image_selection::{self, ResolvedProductImage},
rbac::build_rbac_resources,
},
k8s_openapi::{
DeepMerge,
api::{
Expand Down Expand Up @@ -296,6 +299,11 @@ pub enum Error {
BuildListenerPersistentVolume {
source: stackable_operator::builder::pod::volume::ListenerOperatorVolumeSourceBuilderError,
},

#[snafu(display("failed to resolve product image"))]
ResolveProductImage {
source: product_image_selection::Error,
},
}

impl ReconcilerError for Error {
Expand Down Expand Up @@ -346,6 +354,7 @@ impl ReconcilerError for Error {
Error::ApplyGroupListener { .. } => None,
Error::BuildListenerPersistentVolume { .. } => None,
Error::ListenerConfiguration { .. } => None,
Error::ResolveProductImage { .. } => None,
}
}
}
Expand All @@ -364,7 +373,8 @@ pub async fn reconcile_zk(
let resolved_product_image = zk
.spec
.image
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::PKG_VERSION);
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::PKG_VERSION)
.context(ResolveProductImageSnafu)?;

let mut cluster_resources = ClusterResources::new(
APP_NAME,
Expand All @@ -376,7 +386,7 @@ pub async fn reconcile_zk(
.context(CreateClusterResourcesSnafu)?;

let validated_config = validate_all_roles_and_groups_config(
&resolved_product_image.app_version_label,
&resolved_product_image.product_version,
&transform_all_roles_to_config(
zk,
[(
Expand Down Expand Up @@ -622,7 +632,7 @@ fn build_server_rolegroup_config_map(
.with_recommended_labels(build_recommended_labels(
zk,
ZK_CONTROLLER_NAME,
&resolved_product_image.app_version_label,
&resolved_product_image.app_version_label_value,
&rolegroup.role,
&rolegroup.role_group,
))
Expand All @@ -644,11 +654,16 @@ fn build_server_rolegroup_config_map(
})?,
);

extend_role_group_config_map(zk, role, rolegroup, &mut cm_builder).context(
InvalidLoggingConfigSnafu {
cm_name: rolegroup.object_name(),
},
)?;
extend_role_group_config_map(
zk,
role,
rolegroup,
&mut cm_builder,
&resolved_product_image.product_version,
)
.context(InvalidLoggingConfigSnafu {
cm_name: rolegroup.object_name(),
})?;

cm_builder
.build()
Expand All @@ -675,7 +690,7 @@ fn build_server_rolegroup_headless_service(
.with_recommended_labels(build_recommended_labels(
zk,
ZK_CONTROLLER_NAME,
&resolved_product_image.app_version_label,
&resolved_product_image.app_version_label_value,
&rolegroup.role,
&rolegroup.role_group,
))
Expand Down Expand Up @@ -736,7 +751,7 @@ fn build_server_rolegroup_metrics_service(
.with_recommended_labels(build_recommended_labels(
zk,
ZK_CONTROLLER_NAME,
&resolved_product_image.app_version_label,
&resolved_product_image.app_version_label_value,
&rolegroup.role,
&rolegroup.role_group,
))
Expand Down Expand Up @@ -953,8 +968,13 @@ fn build_server_rolegroup_statefulset(
)
.add_env_var(
"SERVER_JVMFLAGS",
construct_non_heap_jvm_args(zk, role, &rolegroup_ref.role_group)
.context(ConstructJvmArgumentsSnafu)?,
construct_non_heap_jvm_args(
zk,
role,
&rolegroup_ref.role_group,
&resolved_product_image.product_version,
)
.context(ConstructJvmArgumentsSnafu)?,
)
.add_env_var(
"CONTAINERDEBUG_LOG_DIRECTORY",
Expand Down Expand Up @@ -1006,7 +1026,7 @@ fn build_server_rolegroup_statefulset(
.with_recommended_labels(build_recommended_labels(
zk,
ZK_CONTROLLER_NAME,
&resolved_product_image.app_version_label,
&resolved_product_image.app_version_label_value,
&rolegroup_ref.role,
&rolegroup_ref.role_group,
))
Expand Down Expand Up @@ -1120,7 +1140,7 @@ fn build_server_rolegroup_statefulset(
.with_recommended_labels(build_recommended_labels(
zk,
ZK_CONTROLLER_NAME,
&resolved_product_image.app_version_label,
&resolved_product_image.app_version_label_value,
&rolegroup_ref.role,
&rolegroup_ref.role_group,
))
Expand Down Expand Up @@ -1275,10 +1295,11 @@ mod tests {
let resolved_product_image = zookeeper
.spec
.image
.resolve(DOCKER_IMAGE_BASE_NAME, "0.0.0-dev");
.resolve(DOCKER_IMAGE_BASE_NAME, "0.0.0-dev")
.expect("test resolved product image is always valid");

let validated_config = validate_all_roles_and_groups_config(
&resolved_product_image.app_version_label,
&resolved_product_image.product_version,
&transform_all_roles_to_config(
&zookeeper,
[(
Expand Down
11 changes: 9 additions & 2 deletions rust/operator-binary/src/znode_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use const_format::concatcp;
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::{
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
commons::product_image_selection::ResolvedProductImage,
commons::product_image_selection::{self, ResolvedProductImage},
crd::listener,
k8s_openapi::api::core::v1::ConfigMap,
kube::{
Expand Down Expand Up @@ -130,6 +130,11 @@ pub enum Error {
source: stackable_operator::cluster_resources::Error,
znode: ObjectRef<v1alpha1::ZookeeperZnode>,
},

#[snafu(display("failed to resolve product image"))]
ResolveProductImage {
source: product_image_selection::Error,
},
}
type Result<T, E = Error> = std::result::Result<T, E>;

Expand Down Expand Up @@ -179,6 +184,7 @@ impl ReconcilerError for Error {
Error::ObjectHasNoNamespace => None,
Error::FailedToInitializeSecurityContext { .. } => None,
Error::ZnodeMissingExpectedKeys { .. } => None,
Error::ResolveProductImage { .. } => None,
}
}
}
Expand Down Expand Up @@ -247,7 +253,8 @@ pub async fn reconcile_znode(
let resolved_product_image = zk
.spec
.image
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::PKG_VERSION);
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::PKG_VERSION)
.context(ResolveProductImageSnafu)?;
reconcile_apply(client, &znode, Ok(zk), &znode_path, &resolved_product_image)
.await
}
Expand Down
Loading