Skip to content

Commit c3a49d8

Browse files
committed
Use operator-rs macro
1 parent 12ae7c0 commit c3a49d8

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

rust/operator-binary/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ repository.workspace = true
99
publish = false
1010
build = "build.rs"
1111

12+
[features]
13+
# The macro attributed_string_type is used in this operator. It produces test
14+
# code if the feature "test-support" is set. This feature is defined here to
15+
# suppress a Clippy warning.
16+
test-support = []
17+
1218
[dependencies]
1319
stackable-operator = { workspace = true, features = ["test-support"] }
1420

rust/operator-binary/src/controller/dereference.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{num::ParseIntError, str::FromStr};
77

88
use snafu::{OptionExt, ResultExt, Snafu};
99
use stackable_operator::{
10+
attributed_string_type,
1011
client::Client,
1112
kube::runtime::reflector::{Lookup, ObjectRef},
1213
v2::controller_utils::get_namespace,
@@ -71,18 +72,17 @@ pub enum Error {
7172
},
7273
}
7374

74-
/// TODO: Use a typed String from operator-rs similar to [`stackable_operator::v2::types::operator::ClusterName`].
75-
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
76-
pub struct TrinoCatalogName(pub String);
77-
impl AsRef<str> for TrinoCatalogName {
78-
fn as_ref(&self) -> &str {
79-
&self.0
80-
}
81-
}
82-
impl std::fmt::Display for TrinoCatalogName {
83-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84-
self.0.fmt(f)
85-
}
75+
attributed_string_type! {
76+
TrinoCatalogName,
77+
"The name of a TrinoCluster",
78+
"lakehouse",
79+
// Suffixes are added to produce resource names.
80+
//
81+
// 40 characters for catalog names should be sufficient and still allow the operators to append
82+
// custom suffixes to build resource names.
83+
(max_length = 40),
84+
is_rfc_1035_label_name,
85+
is_valid_label_value
8686
}
8787

8888
type Result<T, E = Error> = std::result::Result<T, E>;

rust/operator-binary/src/crd/catalog/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub mod versioned {
8585
///
8686
/// This is recommended because Kubernetes only allows `a-z` and `-`, while Trino
8787
/// requires quoting for catalogs containing `-` characters. This mechanism allows
88-
/// you to use valid Kubernetes names, but keeps the convenience of using `_` in
88+
/// you to use valid Kubernetes names, but keeps the convenience of using `_` in
8989
/// catalog names.
9090
#[serde(default)]
9191
replace_hyphens_with_underscores: bool,

0 commit comments

Comments
 (0)