Skip to content

Commit 5cba7dd

Browse files
adwk67claude
andcommitted
feat: add framework macros and validated type definitions
Introduce the framework module with compile-time validated string wrapper types (attributed_string_type macro) and typed Kubernetes/operator name types. Ported from the opensearch-operator reference implementation. All code is currently unused and will be wired into the controller in subsequent commits. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 80c396d commit 5cba7dd

12 files changed

Lines changed: 1553 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 205 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const_format = "0.2"
2020
fnv = "1.0"
2121
futures = { version = "0.3", features = ["compat"] }
2222
indoc = "2.0"
23+
regex = "1.11"
2324
pin-project = "1.1"
2425
rstest = "0.26"
2526
semver = "1.0"
@@ -30,6 +31,7 @@ snafu = "0.9"
3031
strum = { version = "0.28", features = ["derive"] }
3132
tokio = { version = "1.40", features = ["full"] }
3233
tracing = "0.1"
34+
uuid = { version = "1.16", features = ["v4"] }
3335

3436
[patch."https://github.com/stackabletech/operator-rs.git"]
3537
# stackable-operator = { path = "../operator-rs/crates/stackable-operator" }

rust/operator-binary/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const_format.workspace = true
1818
fnv.workspace = true
1919
futures.workspace = true
2020
indoc.workspace = true
21+
regex.workspace = true
2122
pin-project.workspace = true
2223
semver.workspace = true
2324
serde.workspace = true
@@ -26,6 +27,7 @@ snafu.workspace = true
2627
strum.workspace = true
2728
tokio.workspace = true
2829
tracing.workspace = true
30+
uuid.workspace = true
2931

3032
[dev-dependencies]
3133
rstest.workspace = true
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//! Additions to stackable-operator
2+
//!
3+
//! Functions in stackable-operator usually accept generic types like strings and validate the
4+
//! parameters as late as possible. Therefore, nearly all functions have to return a [`Result`] and
5+
//! errors are returned along the call chain. That makes error handling complex because every
6+
//! module re-packages the received error. Also, the validation is repeated if the value is used in
7+
//! different function calls. Sometimes, validation is not necessary if constant values are used,
8+
//! e.g. the name of the operator.
9+
//!
10+
//! This operator uses a different approach. The incoming values are validated as early as possible
11+
//! and wrapped in a fail-safe type. This type is then used along the call chain, validation is not
12+
//! necessary anymore and functions without side effects do not need to return a [`Result`].
13+
//!
14+
//! However, this operator uses stackable-operator and at the interface, the fail-safe types must
15+
//! be unwrapped and the [`Result`] returned by the stackable-operator function must be handled.
16+
//! This is done by calling [`Result::expect`] which requires thorough testing.
17+
//!
18+
//! When the development of this module has progressed and changes become less frequent, then this
19+
//! module can be incorporated into stackable-operator. The module structure should already
20+
//! resemble the one of stackable-operator.
21+
22+
use types::kubernetes::Uid;
23+
24+
pub mod macros;
25+
pub mod types;
26+
27+
/// Has a non-empty name
28+
///
29+
/// Useful as an object reference; Should not be used to create an object because the name could
30+
/// violate the naming constraints (e.g. maximum length) of the object.
31+
pub trait HasName {
32+
#[allow(dead_code)]
33+
fn to_name(&self) -> String;
34+
}
35+
36+
/// Has a Kubernetes UID
37+
pub trait HasUid {
38+
fn to_uid(&self) -> Uid;
39+
}
40+
41+
/// The name is a valid label value
42+
pub trait NameIsValidLabelValue {
43+
fn to_label_value(&self) -> String;
44+
}

0 commit comments

Comments
 (0)