-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathlabels.rs
More file actions
71 lines (64 loc) · 2.17 KB
/
Copy pathlabels.rs
File metadata and controls
71 lines (64 loc) · 2.17 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Recommended-label and selector construction for the KafkaCluster build step.
//!
//! These build Kubernetes labels/selectors from a [`ValidatedCluster`]. They live here rather
//! than as methods on [`ValidatedCluster`] so the validated model only exposes views on its
//! properties, not build-step helpers.
use std::str::FromStr;
use stackable_operator::{
kvp::Labels,
v2::{kvp::label, types::operator::ProductVersion},
};
use crate::{
controller::{RoleGroupName, ValidatedCluster, controller_name, operator_name, product_name},
crd::role::KafkaRole,
};
/// Recommended labels for a role-group resource, using the given product version.
fn recommended_labels_for(
cluster: &ValidatedCluster,
product_version: &ProductVersion,
role: &KafkaRole,
role_group_name: &RoleGroupName,
) -> Labels {
label::recommended_labels(
cluster,
&product_name(),
product_version,
&operator_name(),
&controller_name(),
&ValidatedCluster::role_name(role),
role_group_name,
)
}
/// Recommended labels for a role-group resource.
pub fn recommended_labels(
cluster: &ValidatedCluster,
role: &KafkaRole,
role_group_name: &RoleGroupName,
) -> Labels {
recommended_labels_for(cluster, &cluster.product_version, role, role_group_name)
}
/// Recommended labels without a version, for PVC templates that cannot be modified once
/// deployed.
pub fn unversioned_recommended_labels(
cluster: &ValidatedCluster,
role: &KafkaRole,
role_group_name: &RoleGroupName,
) -> Labels {
// A version value is required, and we do want to use the "recommended" format for the
// other desired labels.
let none_version = ProductVersion::from_str("none").expect("'none' is a valid product version");
recommended_labels_for(cluster, &none_version, role, role_group_name)
}
/// Selector labels matching the pods of a role group.
pub fn role_group_selector(
cluster: &ValidatedCluster,
role: &KafkaRole,
role_group_name: &RoleGroupName,
) -> Labels {
label::role_group_selector(
cluster,
&product_name(),
&ValidatedCluster::role_name(role),
role_group_name,
)
}