Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
527 changes: 398 additions & 129 deletions Cargo.lock

Large diffs are not rendered by default.

2,483 changes: 2,008 additions & 475 deletions Cargo.nix

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ edition = "2021"
repository = "https://github.com/stackabletech/listener-operator"

[workspace.dependencies]
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.89.1" }
stackable-telemetry = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-telemetry-0.4.0" }

anyhow = "1.0"
built = { version = "0.7", features = ["chrono", "git2"] }
clap = "4.5"
Expand All @@ -24,7 +27,6 @@ serde = "1.0"
serde_json = "1.0"
serde_yaml = "0.9"
snafu = "0.8"
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.87.0" }
strum = { version = "0.27", features = ["derive"] }
socket2 = { version = "0.5", features = ["all"] }
tokio = { version = "1.40", features = ["full"] }
Expand Down
7 changes: 4 additions & 3 deletions crate-hashes.json

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

4 changes: 3 additions & 1 deletion rust/olm-deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ repository.workspace = true
publish = false

[dependencies]
stackable-operator.workspace = true
stackable-telemetry.workspace = true

anyhow.workspace = true
clap.workspace = true
tokio.workspace = true
tracing.workspace = true
stackable-operator.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
Expand Down
82 changes: 65 additions & 17 deletions rust/olm-deployer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@ mod owner;
mod resources;
mod tolerations;

use std::ops::Deref as _;

use anyhow::{Context, Result, anyhow, bail};
use clap::{Parser, crate_description, crate_version};
use clap::Parser;
use stackable_operator::{
cli::Command,
cli::{Command, RollingPeriod, TelemetryArguments},
client,
k8s_openapi::api::{apps::v1::Deployment, rbac::v1::ClusterRole},
kube,
kube::{
self,
api::{Api, DynamicObject, ListParams, Patch, PatchParams, ResourceExt},
core::GroupVersionKind,
discovery::{ApiResource, Discovery, Scope},
},
logging, utils,
utils::cluster_info::KubernetesClusterInfoOpts,
};
use stackable_telemetry::{Tracing, tracing::settings::Settings};
use tracing::level_filters::LevelFilter;

pub const APP_NAME: &str = "stkbl-listener-olm-deployer";
pub const ENV_VAR_LOGGING: &str = "STKBL_LISTENER_OLM_DEPLOYER_LOG";

// TODO (@NickLarsenNZ): Change the variable to `CONSOLE_LOG`
pub const ENV_VAR_CONSOLE_LOG: &str = "STKBL_LISTENER_OLM_DEPLOYER_LOG";

mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
Expand All @@ -56,21 +61,26 @@ struct OlmDeployerRun {
help = "Keep running after manifests have been successfully applied."
)]
keep_alive: bool,

#[arg(
long,
short,
help = "Name of ClusterServiceVersion object that owns this Deployment."
)]
csv: String,

#[arg(long, short, help = "Name of deployment object that owns this Pod.")]
deployer: String,

#[arg(long, short, help = "Namespace of the ClusterServiceVersion object.")]
namespace: String,

#[arg(long, short, help = "Directory with manifests to patch and apply.")]
dir: std::path::PathBuf,
/// Tracing log collector system
#[arg(long, env, default_value_t, value_enum)]
pub tracing_target: logging::TracingTarget,

#[command(flatten)]
pub telemetry_arguments: TelemetryArguments,

#[command(flatten)]
pub cluster_info_opts: KubernetesClusterInfoOpts,
}
Expand All @@ -84,18 +94,56 @@ async fn main() -> Result<()> {
deployer,
namespace,
dir,
tracing_target,
telemetry_arguments,
cluster_info_opts,
}) = opts.cmd
{
logging::initialize_logging(ENV_VAR_LOGGING, APP_NAME, tracing_target);
utils::print_startup_string(
crate_description!(),
crate_version!(),
built_info::GIT_VERSION,
built_info::TARGET,
built_info::BUILT_TIME_UTC,
built_info::RUSTC_VERSION,
let _tracing_guard = Tracing::builder()
.service_name("secret-operator-olm-deployer")
.with_console_output((
ENV_VAR_CONSOLE_LOG,
LevelFilter::INFO,
!telemetry_arguments.no_console_output,
))
// NOTE (@NickLarsenNZ): Before stackable-telemetry was used, the log directory was
// set via an env: `STKBL_LISTENER_OLM_DEPLOYER_LOG_DIRECTORY`.
// See: https://github.com/stackabletech/operator-rs/blob/f035997fca85a54238c8de895389cc50b4d421e2/crates/stackable-operator/src/logging/mod.rs#L40
// Now it will be `ROLLING_LOGS` (or via `--rolling-logs <DIRECTORY>`).
.with_file_output(telemetry_arguments.rolling_logs.map(|log_directory| {
let rotation_period = telemetry_arguments
.rolling_logs_period
.unwrap_or(RollingPeriod::Hourly)
.deref()
.clone();

Settings::builder()
.with_environment_variable(ENV_VAR_CONSOLE_LOG)
.with_default_level(LevelFilter::INFO)
.file_log_settings_builder(log_directory, "tracing-rs.log")
.with_rotation_period(rotation_period)
.build()
}))
.with_otlp_log_exporter((
"OTLP_LOG",
LevelFilter::DEBUG,
telemetry_arguments.otlp_logs,
))
.with_otlp_trace_exporter((
"OTLP_TRACE",
LevelFilter::DEBUG,
telemetry_arguments.otlp_traces,
))
.build()
.init()?;

tracing::info!(
built_info.pkg_version = built_info::PKG_VERSION,
built_info.git_version = built_info::GIT_VERSION,
built_info.target = built_info::TARGET,
built_info.built_time_utc = built_info::BUILT_TIME_UTC,
built_info.rustc_version = built_info::RUSTC_VERSION,
"Starting {description}",
description = built_info::PKG_DESCRIPTION
);

let client =
Expand Down
3 changes: 2 additions & 1 deletion rust/operator-binary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ publish = false

[dependencies]
csi-grpc = { path = "../csi-grpc" }
stackable-operator.workspace = true
stackable-telemetry.workspace = true

clap.workspace = true
const_format.workspace = true
Expand All @@ -18,7 +20,6 @@ libc.workspace = true
pin-project.workspace = true
prost.workspace = true
socket2.workspace = true
stackable-operator.workspace = true
tokio.workspace = true
tokio-stream.workspace = true
tonic.workspace = true
Expand Down
80 changes: 60 additions & 20 deletions rust/operator-binary/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{os::unix::prelude::FileTypeExt, path::PathBuf};
use std::{ops::Deref as _, os::unix::prelude::FileTypeExt, path::PathBuf};

use clap::{Parser, crate_description, crate_version};
use clap::Parser;
use csi_grpc::v1::{
controller_server::ControllerServer, identity_server::IdentityServer, node_server::NodeServer,
};
Expand All @@ -11,13 +11,15 @@ use csi_server::{
use futures::{FutureExt, TryStreamExt, pin_mut};
use stackable_operator::{
CustomResourceExt,
cli::{RollingPeriod, TelemetryArguments},
commons::listener::{Listener, ListenerClass, PodListeners},
logging::TracingTarget,
utils::cluster_info::KubernetesClusterInfoOpts,
};
use stackable_telemetry::{Tracing, tracing::settings::Settings};
use tokio::signal::unix::{SignalKind, signal};
use tokio_stream::wrappers::UnixListenerStream;
use tonic::transport::Server;
use tracing::level_filters::LevelFilter;
use utils::unix_stream::{TonicUnixStream, uds_bind_private};

mod csi_server;
Expand All @@ -36,20 +38,20 @@ struct Opts {

#[derive(clap::Parser)]
struct ListenerOperatorRun {
#[arg(long, env, default_value_t, value_enum)]
tracing_target: TracingTarget,

#[clap(long, env)]
csi_endpoint: PathBuf,

#[clap(subcommand)]
mode: RunMode,

#[command(flatten)]
pub telemetry_arguments: TelemetryArguments,

#[command(flatten)]
pub cluster_info_opts: KubernetesClusterInfoOpts,
}

#[derive(clap::Parser, strum::AsRefStr)]
#[derive(Debug, clap::Parser, strum::AsRefStr, strum::Display)]
enum RunMode {
Controller,
Node {
Expand All @@ -62,6 +64,9 @@ mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

// TODO (@NickLarsenNZ): Change the variable to `CONSOLE_LOG`
pub const ENV_VAR_CONSOLE_LOG: &str = "LISTENER_OPERATOR_LOG";

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let opts = Opts::parse();
Expand All @@ -72,23 +77,58 @@ async fn main() -> anyhow::Result<()> {
PodListeners::print_yaml_schema(built_info::PKG_VERSION)?;
}
stackable_operator::cli::Command::Run(ListenerOperatorRun {
tracing_target,
csi_endpoint,
mode,
telemetry_arguments,
cluster_info_opts,
}) => {
stackable_operator::logging::initialize_logging(
"LISTENER_OPERATOR_LOG",
"listener-operator",
tracing_target,
);
stackable_operator::utils::print_startup_string(
&format!("{} ({})", crate_description!(), mode.as_ref()),
crate_version!(),
built_info::GIT_VERSION,
built_info::TARGET,
built_info::BUILT_TIME_UTC,
built_info::RUSTC_VERSION,
let _tracing_guard = Tracing::builder()
.service_name("listener-operator")
.with_console_output((
ENV_VAR_CONSOLE_LOG,
LevelFilter::INFO,
!telemetry_arguments.no_console_output,
))
// NOTE (@NickLarsenNZ): Before stackable-telemetry was used, the log directory was
// set via an env: `LISTENER_OPERATOR_LOG_DIRECTORY`.
// See: https://github.com/stackabletech/operator-rs/blob/f035997fca85a54238c8de895389cc50b4d421e2/crates/stackable-operator/src/logging/mod.rs#L40
// Now it will be `ROLLING_LOGS` (or via `--rolling-logs <DIRECTORY>`).
.with_file_output(telemetry_arguments.rolling_logs.map(|log_directory| {
let rotation_period = telemetry_arguments
.rolling_logs_period
.unwrap_or(RollingPeriod::Hourly)
.deref()
.clone();

Settings::builder()
.with_environment_variable(ENV_VAR_CONSOLE_LOG)
.with_default_level(LevelFilter::INFO)
.file_log_settings_builder(log_directory, "tracing-rs.log")
.with_rotation_period(rotation_period)
.build()
}))
.with_otlp_log_exporter((
"OTLP_LOG",
LevelFilter::DEBUG,
telemetry_arguments.otlp_logs,
))
.with_otlp_trace_exporter((
"OTLP_TRACE",
LevelFilter::DEBUG,
telemetry_arguments.otlp_traces,
))
.build()
.init()?;

tracing::info!(
run_mode = %mode,
built_info.pkg_version = built_info::PKG_VERSION,
built_info.git_version = built_info::GIT_VERSION,
built_info.target = built_info::TARGET,
built_info.built_time_utc = built_info::BUILT_TIME_UTC,
built_info.rustc_version = built_info::RUSTC_VERSION,
"Starting {description}",
description = built_info::PKG_DESCRIPTION
);
let client = stackable_operator::client::initialize_operator(
Some(OPERATOR_KEY.to_string()),
Expand Down