Skip to content

Commit 75d8eca

Browse files
committed
Merge remote-tracking branch 'origin/smooth-operator' into refactor/add-config-file-writers
# Conflicts: # crates/stackable-operator/src/v2/mod.rs
2 parents a4af6ea + 831e1ba commit 75d8eca

6 files changed

Lines changed: 78 additions & 75 deletions

File tree

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
use stackable_operator::{
2-
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
3-
deep_merger::ObjectOverrides,
4-
k8s_openapi::api::core::v1::ObjectReference,
5-
};
6-
71
use super::types::{
82
kubernetes::{NamespaceName, Uid},
93
operator::{ClusterName, ControllerName, OperatorName, ProductName},
104
};
11-
use crate::framework::{
12-
NameIsValidLabelValue, macros::attributed_string_type::MAX_LABEL_VALUE_LENGTH,
5+
use crate::{
6+
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
7+
deep_merger::ObjectOverrides,
8+
k8s_openapi::api::core::v1::ObjectReference,
9+
v2::{NameIsValidLabelValue, macros::attributed_string_type::MAX_LABEL_VALUE_LENGTH},
1310
};
1411

15-
/// Infallible variant of [`stackable_operator::cluster_resources::ClusterResources::new`]
12+
/// Infallible variant of [`crate::cluster_resources::ClusterResources::new`]
1613
#[allow(clippy::too_many_arguments)]
1714
pub fn cluster_resources_new<'a>(
1815
product_name: &ProductName,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
config::merge::Merge, k8s_openapi::DeepMerge, schemars, utils::crds::raw_object_schema,
1010
};
1111

12-
// Variant of [`stackable_operator::config_overrides::KeyValueConfigOverrides`] that implements
12+
// Variant of [`crate::config_overrides::KeyValueConfigOverrides`] that implements
1313
// Merge
1414
/// Flat key-value overrides for `*.properties`, Hadoop XML, etc.
1515
///
@@ -22,7 +22,7 @@ pub struct KeyValueConfigOverrides {
2222
pub overrides: BTreeMap<String, Option<String>>,
2323
}
2424

25-
// Variant of [`stackable_operator::config_overrides::JsonConfigOverrides`] with the following
25+
// Variant of [`crate::config_overrides::JsonConfigOverrides`] with the following
2626
// changes:
2727
// - Implements Default
2828
// - Implements Merge by using a Sequence variant which is not exposed in the CRD
@@ -63,7 +63,7 @@ pub enum JsonConfigOverrides {
6363
}
6464

6565
impl JsonConfigOverrides {
66-
// Infallible variant of [`stackable_operator::config_overrides::JsonConfigOverrides::apply`]
66+
// Infallible variant of [`crate::config_overrides::JsonConfigOverrides::apply`]
6767
pub fn apply(&self, base: &serde_json::Value) -> serde_json::Value {
6868
match self {
6969
Self::JsonMergePatch(patch) => {

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
use std::str::FromStr;
44

55
use snafu::{OptionExt, ResultExt, Snafu};
6-
use stackable_operator::kube::runtime::reflector::Lookup;
76
use strum::{EnumDiscriminants, IntoStaticStr};
87

9-
use crate::framework::types::{
10-
kubernetes::{NamespaceName, Uid},
11-
operator::ClusterName,
8+
use crate::{
9+
kube::runtime::reflector::Lookup,
10+
v2::types::{
11+
kubernetes::{NamespaceName, Uid},
12+
operator::ClusterName,
13+
},
1214
};
1315

1416
#[derive(Snafu, Debug, EnumDiscriminants)]
@@ -25,17 +27,17 @@ pub enum Error {
2527

2628
#[snafu(display("failed to set the cluster name"))]
2729
ParseClusterName {
28-
source: crate::framework::macros::attributed_string_type::Error,
30+
source: crate::v2::macros::attributed_string_type::Error,
2931
},
3032

3133
#[snafu(display("failed to set the namespace"))]
3234
ParseNamespace {
33-
source: crate::framework::macros::attributed_string_type::Error,
35+
source: crate::v2::macros::attributed_string_type::Error,
3436
},
3537

3638
#[snafu(display("failed to set the UID"))]
3739
ParseUid {
38-
source: crate::framework::macros::attributed_string_type::Error,
40+
source: crate::v2::macros::attributed_string_type::Error,
3941
},
4042
}
4143

@@ -67,13 +69,15 @@ pub fn get_uid(resource: &impl Lookup) -> Result<Uid> {
6769

6870
#[cfg(test)]
6971
mod tests {
70-
use stackable_operator::kube::runtime::reflector::Lookup;
7172
use uuid::uuid;
7273

7374
use super::{ErrorDiscriminants, get_cluster_name, get_namespace, get_uid};
74-
use crate::framework::types::{
75-
kubernetes::{NamespaceName, Uid},
76-
operator::ClusterName,
75+
use crate::{
76+
kube::runtime::reflector::Lookup,
77+
v2::types::{
78+
kubernetes::{NamespaceName, Uid},
79+
operator::ClusterName,
80+
},
7781
};
7882

7983
#[derive(Debug, Default)]

crates/stackable-operator/src/v2/kvp/label.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
use stackable_operator::{
1+
use crate::{
22
kube::Resource,
33
kvp::{Labels, ObjectLabels},
4-
};
5-
6-
use crate::framework::{
7-
HasName, NameIsValidLabelValue,
8-
types::operator::{
9-
ControllerName, OperatorName, ProductName, ProductVersion, RoleGroupName, RoleName,
4+
v2::{
5+
HasName, NameIsValidLabelValue,
6+
types::operator::{
7+
ControllerName, OperatorName, ProductName, ProductVersion, RoleGroupName, RoleName,
8+
},
109
},
1110
};
1211

13-
/// Infallible variant of [`stackable_operator::kvp::Labels::recommended`]
12+
/// Infallible variant of [`crate::kvp::Labels::recommended`]
1413
pub fn recommended_labels(
1514
owner: &(impl Resource + HasName + NameIsValidLabelValue),
1615
product_name: &ProductName,
@@ -35,7 +34,7 @@ pub fn recommended_labels(
3534
)
3635
}
3736

38-
/// Infallible variant of [`stackable_operator::kvp::Labels::role_selector`]
37+
/// Infallible variant of [`crate::kvp::Labels::role_selector`]
3938
pub fn role_selector(
4039
owner: &(impl Resource + HasName + NameIsValidLabelValue),
4140
product_name: &ProductName,
@@ -49,7 +48,7 @@ pub fn role_selector(
4948
.expect("Labels should be created because all given parameters produce valid label values")
5049
}
5150

52-
/// Infallible variant of [`stackable_operator::kvp::Labels::role_group_selector`]
51+
/// Infallible variant of [`crate::kvp::Labels::role_group_selector`]
5352
pub fn role_group_selector(
5453
owner: &(impl Resource + HasName + NameIsValidLabelValue),
5554
product_name: &ProductName,
@@ -69,15 +68,15 @@ pub fn role_group_selector(
6968
mod tests {
7069
use std::{borrow::Cow, collections::BTreeMap};
7170

72-
use stackable_operator::{
73-
k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta, kube::Resource,
74-
};
75-
76-
use crate::framework::{
77-
HasName, NameIsValidLabelValue,
78-
kvp::label::{recommended_labels, role_group_selector, role_selector},
79-
types::operator::{
80-
ControllerName, OperatorName, ProductName, ProductVersion, RoleGroupName, RoleName,
71+
use crate::{
72+
k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta,
73+
kube::Resource,
74+
v2::{
75+
HasName, NameIsValidLabelValue,
76+
kvp::label::{recommended_labels, role_group_selector, role_selector},
77+
types::operator::{
78+
ControllerName, OperatorName, ProductName, ProductVersion, RoleGroupName, RoleName,
79+
},
8180
},
8281
};
8382

@@ -87,7 +86,7 @@ mod tests {
8786

8887
impl Cluster {
8988
fn new() -> Self {
90-
Cluster {
89+
Self {
9190
object_meta: ObjectMeta {
9291
name: Some("cluster-name".to_owned()),
9392
..ObjectMeta::default()

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use crate::v2::types::kubernetes::Uid;
22

33
pub mod builder;
4+
pub mod cluster_resources;
45
pub mod config_file_writer;
56
pub mod config_overrides;
7+
pub mod controller_utils;
68
pub mod flask_config_writer;
9+
pub mod kvp;
710
pub mod macros;
11+
pub mod product_logging;
812
pub mod role_group_utils;
913
pub mod role_utils;
1014
pub mod types;

crates/stackable-operator/src/v2/product_logging/framework.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use std::{fmt::Display, str::FromStr};
22

33
use snafu::{OptionExt, ResultExt, Snafu};
4-
use stackable_operator::{
4+
use strum::{EnumDiscriminants, IntoStaticStr};
5+
6+
use crate::{
57
builder::pod::{container::FieldPathEnvVar, resources::ResourceRequirementsBuilder},
68
commons::product_image_selection::ResolvedProductImage,
9+
constant,
710
k8s_openapi::api::core::v1::{Container, VolumeMount},
811
product_logging::{
912
framework::VECTOR_CONFIG_FILE,
@@ -12,12 +15,7 @@ use stackable_operator::{
1215
ContainerLogConfigChoice, CustomContainerLogConfig, LogLevel, Logging,
1316
},
1417
},
15-
};
16-
use strum::{EnumDiscriminants, IntoStaticStr};
17-
18-
use crate::{
19-
constant,
20-
framework::{
18+
v2::{
2119
builder::pod::container::{EnvVarName, EnvVarSet, new_container_builder},
2220
role_group_utils,
2321
types::kubernetes::{ConfigMapKey, ConfigMapName, ContainerName, VolumeName},
@@ -54,7 +52,7 @@ pub enum Error {
5452

5553
#[snafu(display("failed to parse the container name"))]
5654
ParseContainerName {
57-
source: crate::framework::macros::attributed_string_type::Error,
55+
source: crate::v2::macros::attributed_string_type::Error,
5856
},
5957
}
6058

@@ -63,7 +61,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;
6361
/// Validated [`ContainerLogConfigChoice`]
6462
///
6563
/// The ConfigMap name in the Custom variant is valid.
66-
#[derive(Clone, Debug, PartialEq)]
64+
#[derive(Clone, Debug, PartialEq, Eq)]
6765
pub enum ValidatedContainerLogConfigChoice {
6866
Automatic(AutomaticContainerLogConfig),
6967
Custom(ConfigMapName),
@@ -72,7 +70,7 @@ pub enum ValidatedContainerLogConfigChoice {
7270
/// Validated [`ContainerLogConfigChoice`] for the Vector container
7371
///
7472
/// It includes the discovery ConfigMap name of the Vector aggregator.
75-
#[derive(Clone, Debug, PartialEq)]
73+
#[derive(Clone, Debug, PartialEq, Eq)]
7674
pub struct VectorContainerLogConfig {
7775
pub log_config: ValidatedContainerLogConfigChoice,
7876
pub vector_aggregator_config_map_name: ConfigMapName,
@@ -81,14 +79,14 @@ pub struct VectorContainerLogConfig {
8179
/// Validates the log configuration of the container
8280
pub fn validate_logging_configuration_for_container<T>(
8381
logging: &Logging<T>,
84-
container: T,
82+
container: &T,
8583
) -> Result<ValidatedContainerLogConfigChoice>
8684
where
8785
T: Clone + Display + Ord,
8886
{
8987
let container_log_config_choice = logging
9088
.containers
91-
.get(&container)
89+
.get(container)
9290
.and_then(|container_log_config| container_log_config.choice.as_ref())
9391
// This should never happen because default configurations should have been set for all
9492
// containers.
@@ -111,6 +109,7 @@ where
111109
}
112110

113111
/// Builds the Vector container
112+
#[expect(clippy::too_many_lines)]
114113
pub fn vector_container(
115114
container_name: &ContainerName,
116115
image: &ResolvedProductImage,
@@ -152,7 +151,7 @@ pub fn vector_container(
152151
.with_value(&EnvVarName::from_str_unsafe("LOG_DIR"), STACKABLE_LOG_DIR)
153152
.with_field_path(
154153
&EnvVarName::from_str_unsafe("NAMESPACE"),
155-
FieldPathEnvVar::Namespace,
154+
&FieldPathEnvVar::Namespace,
156155
)
157156
.with_value(
158157
&EnvVarName::from_str_unsafe("ROLE_GROUP_NAME"),
@@ -235,27 +234,26 @@ pub fn vector_container(
235234
mod tests {
236235
use std::str::FromStr;
237236

238-
use pretty_assertions::assert_eq;
239237
use serde_json::json;
240-
use stackable_operator::{
238+
239+
use super::{
240+
ErrorDiscriminants, ValidatedContainerLogConfigChoice, VectorContainerLogConfig,
241+
validate_logging_configuration_for_container, vector_container,
242+
};
243+
use crate::{
241244
commons::product_image_selection::ResolvedProductImage,
242245
kvp::LabelValue,
243246
product_logging::spec::{
244247
AutomaticContainerLogConfig, ConfigMapLogConfig, ContainerLogConfig,
245248
ContainerLogConfigChoice, CustomContainerLogConfig, Logging,
246249
},
247-
};
248-
249-
use super::{
250-
ErrorDiscriminants, ValidatedContainerLogConfigChoice, VectorContainerLogConfig,
251-
validate_logging_configuration_for_container, vector_container,
252-
};
253-
use crate::framework::{
254-
builder::pod::container::{EnvVarName, EnvVarSet},
255-
role_group_utils,
256-
types::{
257-
kubernetes::{ConfigMapName, ContainerName, VolumeName},
258-
operator::{ClusterName, RoleGroupName, RoleName},
250+
v2::{
251+
builder::pod::container::{EnvVarName, EnvVarSet},
252+
role_group_utils,
253+
types::{
254+
kubernetes::{ConfigMapName, ContainerName, VolumeName},
255+
operator::{ClusterName, RoleGroupName, RoleName},
256+
},
259257
},
260258
};
261259

@@ -276,7 +274,7 @@ mod tests {
276274

277275
assert_eq!(
278276
ValidatedContainerLogConfigChoice::Automatic(AutomaticContainerLogConfig::default()),
279-
validate_logging_configuration_for_container(&logging, "container")
277+
validate_logging_configuration_for_container(&logging, &"container")
280278
.expect("should be a valid log config")
281279
);
282280
}
@@ -302,7 +300,7 @@ mod tests {
302300
ValidatedContainerLogConfigChoice::Custom(ConfigMapName::from_str_unsafe(
303301
"valid-config-map-name"
304302
)),
305-
validate_logging_configuration_for_container(&logging, "container")
303+
validate_logging_configuration_for_container(&logging, &"container")
306304
.expect("should be a valid log config")
307305
);
308306
}
@@ -320,15 +318,15 @@ mod tests {
320318

321319
assert_eq!(
322320
Err(ErrorDiscriminants::GetContainerLogConfiguration),
323-
validate_logging_configuration_for_container(&logging_without_container, "container")
321+
validate_logging_configuration_for_container(&logging_without_container, &"container")
324322
.map_err(ErrorDiscriminants::from)
325323
);
326324

327325
assert_eq!(
328326
Err(ErrorDiscriminants::GetContainerLogConfiguration),
329327
validate_logging_configuration_for_container(
330328
&logging_without_container_log_config_choice,
331-
"container"
329+
&"container"
332330
)
333331
.map_err(ErrorDiscriminants::from)
334332
);
@@ -353,12 +351,13 @@ mod tests {
353351

354352
assert_eq!(
355353
Err(ErrorDiscriminants::ParseContainerName),
356-
validate_logging_configuration_for_container(&logging, "container")
354+
validate_logging_configuration_for_container(&logging, &"container")
357355
.map_err(ErrorDiscriminants::from)
358356
);
359357
}
360358

361359
#[test]
360+
#[expect(clippy::too_many_lines)]
362361
fn test_vector_container() {
363362
let image = ResolvedProductImage {
364363
product_version: "1.0.0".to_owned(),

0 commit comments

Comments
 (0)