-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcluster_resources.rs
More file actions
47 lines (45 loc) · 1.82 KB
/
Copy pathcluster_resources.rs
File metadata and controls
47 lines (45 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use super::types::{
kubernetes::{NamespaceName, Uid},
operator::{ClusterName, ControllerName, OperatorName, ProductName},
};
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`]
#[allow(clippy::too_many_arguments)]
pub fn cluster_resources_new<'a>(
product_name: &ProductName,
operator_name: &OperatorName,
controller_name: &ControllerName,
cluster_name: &ClusterName,
cluster_namespace: &NamespaceName,
cluster_uid: &Uid,
apply_strategy: ClusterResourceApplyStrategy,
object_overrides: &'a ObjectOverrides,
) -> ClusterResources<'a> {
// compile-time check
// ClusterResources::new creates a label value from the given app name by appending
// `-operator`. For the resulting label value to be valid, it must not exceed
// MAX_LABEL_VALUE_LENGTH.
const _: () = assert!(
ProductName::MAX_LENGTH + "-operator".len() <= MAX_LABEL_VALUE_LENGTH,
"The string `<cluster_name>-operator` must not exceed the limit of Label names."
);
ClusterResources::new(
&product_name.to_label_value(),
&operator_name.to_label_value(),
&controller_name.to_label_value(),
&ObjectReference {
name: Some(cluster_name.to_string()),
namespace: Some(cluster_namespace.to_string()),
uid: Some(cluster_uid.to_string()),
..Default::default()
},
apply_strategy,
object_overrides,
)
.expect("ClusterResources should be created because the cluster object reference contains name, namespace and uid.")
}