Skip to content

Commit 4663a95

Browse files
committed
refactor: combine the operator lib and binary crates
1 parent b6aa661 commit 4663a95

File tree

15 files changed

+89
-130
lines changed

15 files changed

+89
-130
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
1212
- Support new versions 2.8.2, 3.4.1, 3.5.1 ([#627]).
1313
- Document internal clusterId check ([#631]).
1414
- Support graceful shutdown ([#635]).
15+
- Combine the operator lib and binary crates ([#638]).
1516

1617
### Changed
1718

Cargo.lock

Lines changed: 10 additions & 21 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
[workspace]
2-
members = [
3-
"rust/crd", "rust/operator", "rust/operator-binary"
4-
]
2+
members = ["rust/crd", "rust/operator-binary"]
53

64
[workspace.package]
75
version = "0.0.0-dev"

rust/operator-binary/Cargo.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "stackable-kafka-operator-binary"
2+
name = "stackable-kafka-operator"
33
description = "Stackable Operator for Apache Kafka"
44
version.workspace = true
55
authors.workspace = true
@@ -10,16 +10,24 @@ publish = false
1010

1111
[dependencies]
1212
stackable-kafka-crd = { path = "../crd" }
13-
stackable-kafka-operator = { path = "../operator" }
1413

1514
clap.workspace = true
15+
futures.workspace = true
16+
product-config.workspace = true
17+
serde_json.workspace = true
18+
serde.workspace = true
19+
snafu.workspace = true
1620
stackable-operator.workspace = true
21+
strum.workspace = true
1722
tokio.workspace = true
1823
tracing.workspace = true
1924

25+
[dev-dependencies]
26+
serde_yaml.workspace = true
27+
2028
[build-dependencies]
2129
built.workspace = true
2230

2331
[[bin]]
2432
name = "stackable-kafka-operator"
25-
path = "src/stackable-kafka-operator.rs"
33+
path = "src/main.rs"
File renamed without changes.

rust/operator/src/lib.rs renamed to rust/operator-binary/src/main.rs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use std::sync::Arc;
22

3+
use clap::{crate_description, crate_version, Parser};
34
use futures::StreamExt;
45
use product_config::ProductConfigManager;
5-
use stackable_kafka_crd::{KafkaCluster, OPERATOR_NAME};
6+
use stackable_kafka_crd::{KafkaCluster, APP_NAME, OPERATOR_NAME};
67
use stackable_operator::{
7-
client::Client,
8+
cli::{Command, ProductOperatorRun},
9+
client::{self, Client},
10+
error,
811
k8s_openapi::api::{
912
apps::v1::StatefulSet,
1013
core::v1::{ConfigMap, Pod, Service, ServiceAccount},
@@ -13,6 +16,7 @@ use stackable_operator::{
1316
kube::runtime::{watcher, Controller},
1417
logging::controller::report_controller_reconciled,
1518
namespace::WatchNamespace,
19+
CustomResourceExt,
1620
};
1721

1822
use crate::{
@@ -27,9 +31,69 @@ mod product_logging;
2731
mod utils;
2832

2933
mod built_info {
34+
// The file has been placed there by the build script.
35+
include!(concat!(env!("OUT_DIR"), "/built.rs"));
36+
pub const TARGET: Option<&str> = option_env!("TARGET");
3037
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
3138
}
3239

40+
#[derive(clap::Parser)]
41+
#[clap(about, author)]
42+
struct Opts {
43+
#[clap(subcommand)]
44+
cmd: Command<KafkaRun>,
45+
}
46+
47+
#[derive(clap::Parser)]
48+
struct KafkaRun {
49+
#[clap(long, env)]
50+
kafka_broker_clusterrole: String,
51+
#[clap(flatten)]
52+
common: ProductOperatorRun,
53+
}
54+
55+
#[tokio::main]
56+
async fn main() -> Result<(), error::Error> {
57+
let opts = Opts::parse();
58+
match opts.cmd {
59+
Command::Crd => KafkaCluster::print_yaml_schema()?,
60+
Command::Run(KafkaRun {
61+
kafka_broker_clusterrole,
62+
common:
63+
ProductOperatorRun {
64+
product_config,
65+
watch_namespace,
66+
tracing_target,
67+
},
68+
}) => {
69+
stackable_operator::logging::initialize_logging(
70+
"KAFKA_OPERATOR_LOG",
71+
APP_NAME,
72+
tracing_target,
73+
);
74+
stackable_operator::utils::print_startup_string(
75+
crate_description!(),
76+
crate_version!(),
77+
built_info::GIT_VERSION,
78+
built_info::TARGET.unwrap_or("unknown target"),
79+
built_info::BUILT_TIME_UTC,
80+
built_info::RUSTC_VERSION,
81+
);
82+
let controller_config = ControllerConfig {
83+
broker_clusterrole: kafka_broker_clusterrole,
84+
};
85+
let product_config = product_config.load(&[
86+
"deploy/config-spec/properties.yaml",
87+
"/etc/stackable/kafka-operator/config-spec/properties.yaml",
88+
])?;
89+
let client = client::create_client(Some(OPERATOR_NAME.to_string())).await?;
90+
create_controller(client, controller_config, product_config, watch_namespace).await;
91+
}
92+
};
93+
94+
Ok(())
95+
}
96+
3397
pub struct ControllerConfig {
3498
pub broker_clusterrole: String,
3599
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)