diff --git a/src/lib.rs b/src/lib.rs index 714f9f82a..6b99efd2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ pub mod product_config_utils; pub mod reconcile; pub mod role_utils; pub mod status; +pub mod utils; pub mod validation; pub use crate::crd::CustomResourceExt; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 000000000..227d17873 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,47 @@ +use tracing::info; + +/// Prints helpful and standardized diagnostic messages. +/// +/// This method is meant to be called first thing in the `main` method of an Operator. +/// +/// # Usage +/// +/// Use the [`built`](https://crates.io/crates/built) crate and include it in your `main.rs` like this: +/// +/// ```text +/// mod built_info { +/// // The file has been placed there by the build script. +/// include!(concat!(env!("OUT_DIR"), "/built.rs")); +/// } +/// ``` +/// +/// Then call this method in your `main` method: +/// +/// ```text +/// stackable_operator::utils::print_startup_string( +/// built_info::PKG_DESCRIPTION, +/// built_info::PKG_VERSION, +/// built_info::GIT_VERSION, +/// built_info::TARGET, +/// built_info::BUILT_TIME_UTC, +/// built_info::RUSTC_VERSION, +/// ); +/// ``` +pub fn print_startup_string( + pkg_description: &str, + pkg_version: &str, + git_version: Option<&str>, + target: &str, + built_time: &str, + rustc_version: &str, +) { + let git_information = match git_version { + None => "".to_string(), + Some(git) => format!(" (Git information: {})", git), + }; + info!("Starting {}", pkg_description); + info!( + "This is version {}{}, built for {} by {} at {}", + pkg_version, git_information, target, rustc_version, built_time + ) +}