Skip to content

Commit 89862a7

Browse files
committed
fix: make builder pub
1 parent 2c8db85 commit 89862a7

8 files changed

Lines changed: 62 additions & 70 deletions

File tree

crates/stackable-operator/src/v2/builder/meta.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use stackable_operator::{
1+
use crate::{
22
builder::meta::OwnerReferenceBuilder,
3-
k8s_openapi::apimachinery::pkg::apis::meta::v1::OwnerReference, kube::Resource,
3+
k8s_openapi::apimachinery::pkg::apis::meta::v1::OwnerReference,
4+
kube::Resource,
5+
v2::{HasName, HasUid},
46
};
57

6-
use crate::framework::{HasName, HasUid};
7-
88
/// Infallible variant of
99
/// [`stackable_operator::builder::meta::ObjectMetaBuilder::ownerreference_from_resource`]
1010
pub fn ownerreference_from_resource(
@@ -32,13 +32,12 @@ pub fn ownerreference_from_resource(
3232
mod tests {
3333
use std::borrow::Cow;
3434

35-
use stackable_operator::{
35+
use crate::{
3636
k8s_openapi::apimachinery::pkg::apis::meta::v1::{ObjectMeta, OwnerReference},
3737
kube::Resource,
38+
v2::{HasName, HasUid, Uid, builder::meta::ownerreference_from_resource},
3839
};
3940

40-
use crate::framework::{HasName, HasUid, Uid, builder::meta::ownerreference_from_resource};
41-
4241
struct Cluster {
4342
object_meta: ObjectMeta,
4443
}

crates/stackable-operator/src/v2/builder/pdb.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use stackable_operator::{
1+
use crate::{
22
builder::pdb::PodDisruptionBudgetBuilder,
33
k8s_openapi::apimachinery::pkg::apis::meta::v1::LabelSelector,
44
kube::{Resource, api::ObjectMeta},
5-
};
6-
7-
use crate::framework::{
8-
HasName, HasUid, NameIsValidLabelValue,
9-
types::operator::{ControllerName, OperatorName, ProductName, RoleName},
5+
v2::{
6+
HasName, HasUid, NameIsValidLabelValue,
7+
types::operator::{ControllerName, OperatorName, ProductName, RoleName},
8+
},
109
};
1110

1211
/// Infallible variant of
@@ -35,7 +34,7 @@ pub fn pod_disruption_budget_builder_with_role(
3534
mod tests {
3635
use std::borrow::Cow;
3736

38-
use stackable_operator::{
37+
use crate::{
3938
k8s_openapi::{
4039
api::policy::v1::{PodDisruptionBudget, PodDisruptionBudgetSpec},
4140
apimachinery::pkg::{
@@ -44,14 +43,13 @@ mod tests {
4443
},
4544
},
4645
kube::Resource,
47-
};
48-
49-
use crate::framework::{
50-
HasName, HasUid, NameIsValidLabelValue,
51-
builder::pdb::pod_disruption_budget_builder_with_role,
52-
types::{
53-
kubernetes::Uid,
54-
operator::{ControllerName, OperatorName, ProductName, RoleName},
46+
v2::{
47+
HasName, HasUid, NameIsValidLabelValue,
48+
builder::pdb::pod_disruption_budget_builder_with_role,
49+
types::{
50+
kubernetes::Uid,
51+
operator::{ControllerName, OperatorName, ProductName, RoleName},
52+
},
5553
},
5654
};
5755

crates/stackable-operator/src/v2/builder/pod/container.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use std::{
55
};
66

77
use snafu::Snafu;
8-
use stackable_operator::{
8+
use strum::{EnumDiscriminants, IntoStaticStr};
9+
10+
use crate::{
911
builder::pod::container::{ContainerBuilder, FieldPathEnvVar},
1012
k8s_openapi::api::core::v1::{ConfigMapKeySelector, EnvVar, EnvVarSource, ObjectFieldSelector},
13+
v2::types::kubernetes::{ConfigMapKey, ConfigMapName, ContainerName},
1114
};
12-
use strum::{EnumDiscriminants, IntoStaticStr};
13-
14-
use crate::v2::types::kubernetes::{ConfigMapKey, ConfigMapName, ContainerName};
1515

1616
#[derive(Snafu, Debug, EnumDiscriminants)]
1717
#[strum_discriminants(derive(IntoStaticStr))]
@@ -38,7 +38,7 @@ impl EnvVarName {
3838
///
3939
/// Use this only with constant names that are also tested in unit tests!
4040
pub fn from_str_unsafe(s: &str) -> Self {
41-
EnvVarName::from_str(s).expect("should be a valid environment variable name")
41+
Self::from_str(s).expect("should be a valid environment variable name")
4242
}
4343
}
4444

@@ -84,7 +84,7 @@ impl EnvVarSet {
8484
/// Moves all [`EnvVar`]s from the given set into this one.
8585
///
8686
/// [`EnvVar`]s with the same name are overridden.
87-
pub fn merge(mut self, mut env_var_set: EnvVarSet) -> Self {
87+
pub fn merge(mut self, mut env_var_set: Self) -> Self {
8888
self.0.append(&mut env_var_set.0);
8989

9090
self
@@ -124,7 +124,7 @@ impl EnvVarSet {
124124
/// Adds an environment variable with the given name and field path to this set
125125
///
126126
/// An [`EnvVar`] with the same name is overridden.
127-
pub fn with_field_path(mut self, name: &EnvVarName, field_path: FieldPathEnvVar) -> Self {
127+
pub fn with_field_path(mut self, name: &EnvVarName, field_path: &FieldPathEnvVar) -> Self {
128128
self.0.insert(
129129
name.clone(),
130130
EnvVar {
@@ -191,17 +191,16 @@ impl IntoIterator for EnvVarSet {
191191
mod tests {
192192
use std::str::FromStr;
193193

194-
use stackable_operator::{
194+
use super::{EnvVarName, EnvVarSet};
195+
use crate::{
195196
builder::pod::container::FieldPathEnvVar,
196197
k8s_openapi::api::core::v1::{
197198
ConfigMapKeySelector, EnvVar, EnvVarSource, ObjectFieldSelector,
198199
},
199-
};
200-
201-
use super::{EnvVarName, EnvVarSet};
202-
use crate::framework::{
203-
builder::pod::container::new_container_builder,
204-
types::kubernetes::{ConfigMapKey, ConfigMapName, ContainerName},
200+
v2::{
201+
builder::pod::container::new_container_builder,
202+
types::kubernetes::{ConfigMapKey, ConfigMapName, ContainerName},
203+
},
205204
};
206205

207206
#[test]

crates/stackable-operator/src/v2/builder/pod/volume.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use stackable_operator::{
1+
use crate::{
22
builder::pod::volume::ListenerOperatorVolumeSourceBuilder,
3-
k8s_openapi::api::core::v1::PersistentVolumeClaim, kvp::Labels,
4-
};
5-
6-
use crate::framework::types::kubernetes::{
7-
ListenerClassName, ListenerName, PersistentVolumeClaimName,
3+
k8s_openapi::api::core::v1::PersistentVolumeClaim,
4+
kvp::Labels,
5+
v2::types::kubernetes::{ListenerClassName, ListenerName, PersistentVolumeClaimName},
86
};
97

108
/// Infallible variant of [`stackable_operator::builder::pod::volume::ListenerReference`]
@@ -14,18 +12,14 @@ pub enum ListenerReference {
1412
Listener(ListenerName),
1513
}
1614

17-
impl From<&ListenerReference> for stackable_operator::builder::pod::volume::ListenerReference {
15+
impl From<&ListenerReference> for crate::builder::pod::volume::ListenerReference {
1816
fn from(value: &ListenerReference) -> Self {
1917
match value {
2018
ListenerReference::ListenerClass(listener_class_name) => {
21-
stackable_operator::builder::pod::volume::ListenerReference::ListenerClass(
22-
listener_class_name.to_string(),
23-
)
19+
Self::ListenerClass(listener_class_name.to_string())
2420
}
2521
ListenerReference::Listener(listener_name) => {
26-
stackable_operator::builder::pod::volume::ListenerReference::ListenerName(
27-
listener_name.to_string(),
28-
)
22+
Self::ListenerName(listener_name.to_string())
2923
}
3024
}
3125
}

crates/stackable-operator/src/v2/builder/statefulset.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::collections::BTreeMap;
22

3-
use stackable_operator::kvp::Annotations;
4-
5-
use crate::framework::types::kubernetes::{ConfigMapName, SecretName};
3+
use crate::{
4+
kvp::Annotations,
5+
v2::types::kubernetes::{ConfigMapName, SecretName},
6+
};
67

78
/// Creates `restarter.stackable.tech/ignore-configmap.{i}` annotations for each given ConfigMap.
89
///

crates/stackable-operator/src/v2/macros/attributed_string_type.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ pub enum Regex {
5555

5656
impl Regex {
5757
/// Combine this regular expression with the given one.
58-
pub const fn combine(self, other: Regex) -> Regex {
58+
pub const fn combine(self, other: Self) -> Self {
5959
match (self, other) {
60-
(_, Regex::MatchAll) => self,
61-
(Regex::MatchAll, _) => other,
60+
(_, Self::MatchAll) => self,
61+
(Self::MatchAll, _) => other,
6262
// It is hard to combine two regular expressions and nearly impossible to do this in a
6363
// const context. Fortunately, for most of the data types, only one regular expression
6464
// is set.
65-
_ => Regex::Unknown,
65+
_ => Self::Unknown,
6666
}
6767
}
6868
}
@@ -101,7 +101,7 @@ macro_rules! attributed_string_type {
101101
pub const REGEX: $crate::v2::macros::attributed_string_type::Regex = attributed_string_type!(@regex $($attribute)*);
102102
}
103103

104-
impl crate::config::merge::Atomic for $name {}
104+
impl $crate::config::merge::Atomic for $name {}
105105

106106
impl std::fmt::Display for $name {
107107
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -161,13 +161,13 @@ macro_rules! attributed_string_type {
161161
}
162162

163163
// The JsonSchema implementation requires `max_length`.
164-
impl crate::schemars::JsonSchema for $name {
164+
impl $crate::schemars::JsonSchema for $name {
165165
fn schema_name() -> std::borrow::Cow<'static, str> {
166166
std::stringify!($name).into()
167167
}
168168

169-
fn json_schema(_generator: &mut crate::schemars::generate::SchemaGenerator) -> crate::schemars::Schema {
170-
crate::schemars::json_schema!({
169+
fn json_schema(_generator: &mut $crate::schemars::generate::SchemaGenerator) -> $crate::schemars::Schema {
170+
$crate::schemars::json_schema!({
171171
"type": "string",
172172
"minLength": $name::MIN_LENGTH,
173173
"maxLength": if $name::MAX_LENGTH != usize::MAX {
@@ -233,16 +233,16 @@ macro_rules! attributed_string_type {
233233
);
234234
};
235235
(@from_str $name:ident, $s:expr, is_rfc_1035_label_name) => {
236-
crate::validation::is_lowercase_rfc_1035_label($s).context($crate::v2::macros::attributed_string_type::InvalidRfc1035LabelNameSnafu)?;
236+
$crate::validation::is_lowercase_rfc_1035_label($s).context($crate::v2::macros::attributed_string_type::InvalidRfc1035LabelNameSnafu)?;
237237
};
238238
(@from_str $name:ident, $s:expr, is_rfc_1123_dns_subdomain_name) => {
239-
crate::validation::is_lowercase_rfc_1123_subdomain($s).context($crate::v2::macros::attributed_string_type::InvalidRfc1123DnsSubdomainNameSnafu)?;
239+
$crate::validation::is_lowercase_rfc_1123_subdomain($s).context($crate::v2::macros::attributed_string_type::InvalidRfc1123DnsSubdomainNameSnafu)?;
240240
};
241241
(@from_str $name:ident, $s:expr, is_rfc_1123_label_name) => {
242-
crate::validation::is_lowercase_rfc_1123_label($s).context($crate::v2::macros::attributed_string_type::InvalidRfc1123LabelNameSnafu)?;
242+
$crate::validation::is_lowercase_rfc_1123_label($s).context($crate::v2::macros::attributed_string_type::InvalidRfc1123LabelNameSnafu)?;
243243
};
244244
(@from_str $name:ident, $s:expr, is_valid_label_value) => {
245-
crate::kvp::LabelValue::from_str($s).context($crate::v2::macros::attributed_string_type::InvalidLabelValueSnafu)?;
245+
$crate::kvp::LabelValue::from_str($s).context($crate::v2::macros::attributed_string_type::InvalidLabelValueSnafu)?;
246246
};
247247
(@from_str $name:ident, $s:expr, is_uid) => {
248248
uuid::Uuid::try_parse($s).context($crate::v2::macros::attributed_string_type::InvalidUidSnafu)?;
@@ -321,19 +321,19 @@ macro_rules! attributed_string_type {
321321
};
322322
(@max_length is_rfc_1035_label_name $($attribute:tt)*) => {
323323
$crate::v2::macros::attributed_string_type::min(
324-
crate::validation::RFC_1035_LABEL_MAX_LENGTH,
324+
$crate::validation::RFC_1035_LABEL_MAX_LENGTH,
325325
attributed_string_type!(@max_length $($attribute)*)
326326
)
327327
};
328328
(@max_length is_rfc_1123_dns_subdomain_name $($attribute:tt)*) => {
329329
$crate::v2::macros::attributed_string_type::min(
330-
crate::validation::RFC_1123_SUBDOMAIN_MAX_LENGTH,
330+
$crate::validation::RFC_1123_SUBDOMAIN_MAX_LENGTH,
331331
attributed_string_type!(@max_length $($attribute)*)
332332
)
333333
};
334334
(@max_length is_rfc_1123_label_name $($attribute:tt)*) => {
335335
$crate::v2::macros::attributed_string_type::min(
336-
crate::validation::RFC_1123_LABEL_MAX_LENGTH,
336+
$crate::validation::RFC_1123_LABEL_MAX_LENGTH,
337337
attributed_string_type!(@max_length $($attribute)*)
338338
)
339339
};

crates/stackable-operator/src/v2/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::v2::types::kubernetes::Uid;
22

3+
pub mod builder;
34
pub mod config_overrides;
45
pub mod macros;
56
pub mod types;

crates/stackable-operator/src/v2/types/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ impl std::fmt::Display for Port {
2121

2222
impl From<u16> for Port {
2323
fn from(value: u16) -> Self {
24-
Port(value)
24+
Self(value)
2525
}
2626
}
2727

2828
impl From<Port> for i32 {
2929
fn from(value: Port) -> Self {
30-
value.0 as i32
30+
Self::from(value.0)
3131
}
3232
}
3333

3434
impl TryFrom<i32> for Port {
3535
type Error = Error;
3636

3737
fn try_from(value: i32) -> Result<Self, Self::Error> {
38-
Ok(Port(
38+
Ok(Self(
3939
u16::try_from(value).context(ConvertToPortNumberSnafu)?,
4040
))
4141
}

0 commit comments

Comments
 (0)