Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions crates/stackable-operator/src/v2/cluster_resources.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use stackable_operator::{
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
deep_merger::ObjectOverrides,
k8s_openapi::api::core::v1::ObjectReference,
};

use super::types::{
kubernetes::{NamespaceName, Uid},
operator::{ClusterName, ControllerName, OperatorName, ProductName},
};
use crate::framework::{
NameIsValidLabelValue, macros::attributed_string_type::MAX_LABEL_VALUE_LENGTH,
use crate::{
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
deep_merger::ObjectOverrides,
k8s_openapi::api::core::v1::ObjectReference,
v2::{NameIsValidLabelValue, macros::attributed_string_type::MAX_LABEL_VALUE_LENGTH},
};

/// Infallible variant of [`stackable_operator::cluster_resources::ClusterResources::new`]
Expand Down
26 changes: 15 additions & 11 deletions crates/stackable-operator/src/v2/controller_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
use std::str::FromStr;

use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::kube::runtime::reflector::Lookup;
use strum::{EnumDiscriminants, IntoStaticStr};

use crate::framework::types::{
kubernetes::{NamespaceName, Uid},
operator::ClusterName,
use crate::{
kube::runtime::reflector::Lookup,
v2::types::{
kubernetes::{NamespaceName, Uid},
operator::ClusterName,
},
};

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

#[snafu(display("failed to set the cluster name"))]
ParseClusterName {
source: crate::framework::macros::attributed_string_type::Error,
source: crate::v2::macros::attributed_string_type::Error,
},

#[snafu(display("failed to set the namespace"))]
ParseNamespace {
source: crate::framework::macros::attributed_string_type::Error,
source: crate::v2::macros::attributed_string_type::Error,
},

#[snafu(display("failed to set the UID"))]
ParseUid {
source: crate::framework::macros::attributed_string_type::Error,
source: crate::v2::macros::attributed_string_type::Error,
},
}

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

#[cfg(test)]
mod tests {
use stackable_operator::kube::runtime::reflector::Lookup;
use uuid::uuid;

use super::{ErrorDiscriminants, get_cluster_name, get_namespace, get_uid};
use crate::framework::types::{
kubernetes::{NamespaceName, Uid},
operator::ClusterName,
use crate::{
kube::runtime::reflector::Lookup,
v2::types::{
kubernetes::{NamespaceName, Uid},
operator::ClusterName,
},
};

#[derive(Debug, Default)]
Expand Down
33 changes: 16 additions & 17 deletions crates/stackable-operator/src/v2/kvp/label.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use stackable_operator::{
use crate::{
kube::Resource,
kvp::{Labels, ObjectLabels},
};

use crate::framework::{
HasName, NameIsValidLabelValue,
types::operator::{
ControllerName, OperatorName, ProductName, ProductVersion, RoleGroupName, RoleName,
v2::{
HasName, NameIsValidLabelValue,
types::operator::{
ControllerName, OperatorName, ProductName, ProductVersion, RoleGroupName, RoleName,
},
},
};

Expand Down Expand Up @@ -69,15 +68,15 @@ pub fn role_group_selector(
mod tests {
use std::{borrow::Cow, collections::BTreeMap};

use stackable_operator::{
k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta, kube::Resource,
};

use crate::framework::{
HasName, NameIsValidLabelValue,
kvp::label::{recommended_labels, role_group_selector, role_selector},
types::operator::{
ControllerName, OperatorName, ProductName, ProductVersion, RoleGroupName, RoleName,
use crate::{
k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta,
kube::Resource,
v2::{
HasName, NameIsValidLabelValue,
kvp::label::{recommended_labels, role_group_selector, role_selector},
types::operator::{
ControllerName, OperatorName, ProductName, ProductVersion, RoleGroupName, RoleName,
},
},
};

Expand All @@ -87,7 +86,7 @@ mod tests {

impl Cluster {
fn new() -> Self {
Cluster {
Self {
object_meta: ObjectMeta {
name: Some("cluster-name".to_owned()),
..ObjectMeta::default()
Expand Down
4 changes: 4 additions & 0 deletions crates/stackable-operator/src/v2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use crate::v2::types::kubernetes::Uid;

pub mod builder;
pub mod cluster_resources;
pub mod config_overrides;
pub mod controller_utils;
pub mod kvp;
pub mod macros;
pub mod product_logging;
pub mod role_group_utils;
pub mod role_utils;
pub mod types;
Expand Down
63 changes: 31 additions & 32 deletions crates/stackable-operator/src/v2/product_logging/framework.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::{fmt::Display, str::FromStr};

use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::{
use strum::{EnumDiscriminants, IntoStaticStr};

use crate::{
builder::pod::{container::FieldPathEnvVar, resources::ResourceRequirementsBuilder},
commons::product_image_selection::ResolvedProductImage,
constant,
k8s_openapi::api::core::v1::{Container, VolumeMount},
product_logging::{
framework::VECTOR_CONFIG_FILE,
Expand All @@ -12,12 +15,7 @@ use stackable_operator::{
ContainerLogConfigChoice, CustomContainerLogConfig, LogLevel, Logging,
},
},
};
use strum::{EnumDiscriminants, IntoStaticStr};

use crate::{
constant,
framework::{
v2::{
builder::pod::container::{EnvVarName, EnvVarSet, new_container_builder},
role_group_utils,
types::kubernetes::{ConfigMapKey, ConfigMapName, ContainerName, VolumeName},
Expand Down Expand Up @@ -54,7 +52,7 @@ pub enum Error {

#[snafu(display("failed to parse the container name"))]
ParseContainerName {
source: crate::framework::macros::attributed_string_type::Error,
source: crate::v2::macros::attributed_string_type::Error,
},
}

Expand All @@ -63,7 +61,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;
/// Validated [`ContainerLogConfigChoice`]
///
/// The ConfigMap name in the Custom variant is valid.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ValidatedContainerLogConfigChoice {
Automatic(AutomaticContainerLogConfig),
Custom(ConfigMapName),
Expand All @@ -72,7 +70,7 @@ pub enum ValidatedContainerLogConfigChoice {
/// Validated [`ContainerLogConfigChoice`] for the Vector container
///
/// It includes the discovery ConfigMap name of the Vector aggregator.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VectorContainerLogConfig {
pub log_config: ValidatedContainerLogConfigChoice,
pub vector_aggregator_config_map_name: ConfigMapName,
Expand All @@ -81,14 +79,14 @@ pub struct VectorContainerLogConfig {
/// Validates the log configuration of the container
pub fn validate_logging_configuration_for_container<T>(
logging: &Logging<T>,
container: T,
container: &T,
) -> Result<ValidatedContainerLogConfigChoice>
where
T: Clone + Display + Ord,
{
let container_log_config_choice = logging
.containers
.get(&container)
.get(container)
.and_then(|container_log_config| container_log_config.choice.as_ref())
// This should never happen because default configurations should have been set for all
// containers.
Expand All @@ -111,6 +109,7 @@ where
}

/// Builds the Vector container
#[expect(clippy::too_many_lines)]
pub fn vector_container(
container_name: &ContainerName,
image: &ResolvedProductImage,
Expand Down Expand Up @@ -152,7 +151,7 @@ pub fn vector_container(
.with_value(&EnvVarName::from_str_unsafe("LOG_DIR"), STACKABLE_LOG_DIR)
.with_field_path(
&EnvVarName::from_str_unsafe("NAMESPACE"),
FieldPathEnvVar::Namespace,
&FieldPathEnvVar::Namespace,
)
.with_value(
&EnvVarName::from_str_unsafe("ROLE_GROUP_NAME"),
Expand Down Expand Up @@ -235,27 +234,26 @@ pub fn vector_container(
mod tests {
use std::str::FromStr;

use pretty_assertions::assert_eq;
use serde_json::json;
use stackable_operator::{

use super::{
ErrorDiscriminants, ValidatedContainerLogConfigChoice, VectorContainerLogConfig,
validate_logging_configuration_for_container, vector_container,
};
use crate::{
commons::product_image_selection::ResolvedProductImage,
kvp::LabelValue,
product_logging::spec::{
AutomaticContainerLogConfig, ConfigMapLogConfig, ContainerLogConfig,
ContainerLogConfigChoice, CustomContainerLogConfig, Logging,
},
};

use super::{
ErrorDiscriminants, ValidatedContainerLogConfigChoice, VectorContainerLogConfig,
validate_logging_configuration_for_container, vector_container,
};
use crate::framework::{
builder::pod::container::{EnvVarName, EnvVarSet},
role_group_utils,
types::{
kubernetes::{ConfigMapName, ContainerName, VolumeName},
operator::{ClusterName, RoleGroupName, RoleName},
v2::{
builder::pod::container::{EnvVarName, EnvVarSet},
role_group_utils,
types::{
kubernetes::{ConfigMapName, ContainerName, VolumeName},
operator::{ClusterName, RoleGroupName, RoleName},
},
},
};

Expand All @@ -276,7 +274,7 @@ mod tests {

assert_eq!(
ValidatedContainerLogConfigChoice::Automatic(AutomaticContainerLogConfig::default()),
validate_logging_configuration_for_container(&logging, "container")
validate_logging_configuration_for_container(&logging, &"container")
.expect("should be a valid log config")
);
}
Expand All @@ -302,7 +300,7 @@ mod tests {
ValidatedContainerLogConfigChoice::Custom(ConfigMapName::from_str_unsafe(
"valid-config-map-name"
)),
validate_logging_configuration_for_container(&logging, "container")
validate_logging_configuration_for_container(&logging, &"container")
.expect("should be a valid log config")
);
}
Expand All @@ -320,15 +318,15 @@ mod tests {

assert_eq!(
Err(ErrorDiscriminants::GetContainerLogConfiguration),
validate_logging_configuration_for_container(&logging_without_container, "container")
validate_logging_configuration_for_container(&logging_without_container, &"container")
.map_err(ErrorDiscriminants::from)
);

assert_eq!(
Err(ErrorDiscriminants::GetContainerLogConfiguration),
validate_logging_configuration_for_container(
&logging_without_container_log_config_choice,
"container"
&"container"
)
.map_err(ErrorDiscriminants::from)
);
Expand All @@ -353,12 +351,13 @@ mod tests {

assert_eq!(
Err(ErrorDiscriminants::ParseContainerName),
validate_logging_configuration_for_container(&logging, "container")
validate_logging_configuration_for_container(&logging, &"container")
.map_err(ErrorDiscriminants::from)
);
}

#[test]
#[expect(clippy::too_many_lines)]
fn test_vector_container() {
let image = ResolvedProductImage {
product_version: "1.0.0".to_owned(),
Expand Down
Loading