Skip to content
Merged
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
470 changes: 292 additions & 178 deletions Cargo.lock

Large diffs are not rendered by default.

1,180 changes: 858 additions & 322 deletions Cargo.nix

Large diffs are not rendered by default.

4 changes: 2 additions & 2 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,7 +31,7 @@ tokio = { version = "1.40", features = ["full"] }
tokio-zookeeper = "0.4"
tracing = "0.1"

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

[patch.crates-io]
Expand Down
14 changes: 7 additions & 7 deletions crate-hashes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 28 additions & 8 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,8 +124,15 @@ 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 zk_server_heap_env = construct_zk_server_heap_env(&merged_config).unwrap();
let non_heap_jvm_args = construct_non_heap_jvm_args(
&zookeeper,
&role,
&rolegroup,
zookeeper.spec.image.product_version(),
)
.expect("test: function must pass");
let zk_server_heap_env =
construct_zk_server_heap_env(&merged_config).expect("test: function must pass");

assert_eq!(
non_heap_jvm_args,
Expand Down Expand Up @@ -167,8 +176,15 @@ 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 zk_server_heap_env = construct_zk_server_heap_env(&merged_config).unwrap();
let non_heap_jvm_args = construct_non_heap_jvm_args(
&zookeeper,
&role,
&rolegroup,
zookeeper.spec.image.product_version(),
)
.expect("test: function must pass");
let zk_server_heap_env =
construct_zk_server_heap_env(&merged_config).expect("test: function must pass");

assert_eq!(
non_heap_jvm_args,
Expand Down Expand Up @@ -197,8 +213,12 @@ mod tests {
let rolegroup_ref = zookeeper.server_rolegroup_ref("default");
let merged_config = zookeeper
.merged_config(&zookeeper_role, &rolegroup_ref)
.unwrap();
let role = zookeeper.spec.servers.clone().unwrap();
.expect("test: merged config can be created");
let role = zookeeper
.spec
.servers
.clone()
.expect("test: server role is defined in the ZookeeperCluster");

(zookeeper, merged_config, role, "default".to_owned())
}
Expand Down
18 changes: 3 additions & 15 deletions rust/operator-binary/src/crd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use stackable_operator::{
product_logging::{self, spec::Logging},
role_utils::{GenericRoleConfig, JavaCommonConfig, Role, RoleGroup, RoleGroupRef},
schemars::{self, JsonSchema},
shared::time::Duration,
status::condition::{ClusterCondition, HasStatusCondition},
time::Duration,
utils::cluster_info::KubernetesClusterInfo,
versioned::versioned,
};
Expand Down 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/crd/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use stackable_operator::{
client::Client,
crd::authentication::core,
k8s_openapi::api::core::v1::Volume,
time::Duration,
shared::time::Duration,
};

use crate::{
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
57 changes: 39 additions & 18 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 @@ -62,11 +65,11 @@ use stackable_operator::{
},
},
role_utils::RoleGroupRef,
shared::time::Duration,
status::condition::{
compute_conditions, operations::ClusterOperationsConditionBuilder,
statefulset::StatefulSetConditionBuilder,
},
time::Duration,
utils::{COMMON_BASH_TRAP_FUNCTIONS, cluster_info::KubernetesClusterInfo},
};
use strum::{EnumDiscriminants, IntoStaticStr};
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
Loading
Loading