Skip to content

Commit 48c23a7

Browse files
committed
fix: add namespace / uid to ValidatedCluster
1 parent bfe5726 commit 48c23a7

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

rust/operator-binary/src/controller/build/properties/env_vars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub fn build_airflow_statefulset_envs(
214214
AIRFLOW_KUBERNETES_EXECUTOR_NAMESPACE.into(),
215215
EnvVar {
216216
name: AIRFLOW_KUBERNETES_EXECUTOR_NAMESPACE.into(),
217-
value: cluster.namespace(),
217+
value: Some(cluster.namespace.to_string()),
218218
..Default::default()
219219
},
220220
);
@@ -393,7 +393,7 @@ pub fn build_airflow_template_envs(
393393
AIRFLOW_KUBERNETES_EXECUTOR_NAMESPACE.into(),
394394
EnvVar {
395395
name: AIRFLOW_KUBERNETES_EXECUTOR_NAMESPACE.into(),
396-
value: cluster.namespace(),
396+
value: Some(cluster.namespace.to_string()),
397397
..Default::default()
398398
},
399399
);

rust/operator-binary/src/controller/mod.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use stackable_operator::{
1717
product_logging::framework::{ValidatedContainerLogConfigChoice, VectorContainerLogConfig},
1818
role_group_utils::ResourceNames,
1919
types::{
20-
kubernetes::{ConfigMapName, ListenerClassName, ListenerName, SecretName, Uid},
20+
kubernetes::{
21+
ConfigMapName, ListenerClassName, ListenerName, NamespaceName, SecretName, Uid,
22+
},
2123
operator::{
2224
ClusterName, ControllerName, OperatorName, ProductName, ProductVersion,
2325
RoleGroupName, RoleName,
@@ -120,6 +122,11 @@ pub struct ValidatedCluster {
120122
metadata: ObjectMeta,
121123
/// The cluster name as a type-safe value, used to build resource names and labels.
122124
pub name: ClusterName,
125+
/// The cluster's namespace as a type-safe value, captured during validation.
126+
pub namespace: NamespaceName,
127+
/// The cluster's UID as a type-safe value, captured during validation (used for owner
128+
/// references).
129+
pub uid: Uid,
123130
/// The product version as a valid label value, for the recommended `app.kubernetes.io/version`
124131
/// label. Derived from the resolved image's app-version label value.
125132
pub product_version: ProductVersion,
@@ -131,8 +138,9 @@ pub struct ValidatedCluster {
131138

132139
impl ValidatedCluster {
133140
pub fn new(
134-
airflow: &v1alpha2::AirflowCluster,
135141
name: ClusterName,
142+
namespace: NamespaceName,
143+
uid: Uid,
136144
image: ResolvedProductImage,
137145
cluster_config: ValidatedClusterConfig,
138146
role_groups: BTreeMap<AirflowRole, BTreeMap<RoleGroupName, AirflowRoleGroup>>,
@@ -145,12 +153,14 @@ impl ValidatedCluster {
145153
Self {
146154
// Capture only the identity fields needed to own child objects.
147155
metadata: ObjectMeta {
148-
name: Some(airflow.name_any()),
149-
namespace: airflow.namespace(),
150-
uid: airflow.uid(),
156+
name: Some(name.to_string()),
157+
namespace: Some(namespace.to_string()),
158+
uid: Some(uid.to_string()),
151159
..ObjectMeta::default()
152160
},
153161
name,
162+
namespace,
163+
uid,
154164
product_version,
155165
image,
156166
cluster_config,
@@ -159,11 +169,6 @@ impl ValidatedCluster {
159169
}
160170
}
161171

162-
/// The cluster's namespace, captured during validation.
163-
pub fn namespace(&self) -> Option<String> {
164-
self.metadata.namespace.clone()
165-
}
166-
167172
/// Whether the cluster has the given role configured (i.e. it has role groups for it).
168173
pub fn has_role(&self, role: &AirflowRole) -> bool {
169174
self.role_groups.contains_key(role)
@@ -356,13 +361,6 @@ impl NameIsValidLabelValue for ValidatedCluster {
356361

357362
impl HasUid for ValidatedCluster {
358363
fn to_uid(&self) -> Uid {
359-
Uid::from_str(
360-
&self
361-
.metadata
362-
.uid
363-
.clone()
364-
.expect("the uid is captured during validation"),
365-
)
366-
.expect("the uid is a valid Kubernetes UID")
364+
self.uid.clone()
367365
}
368366
}

rust/operator-binary/src/controller/validate.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use stackable_operator::{
1616
role_utils::{GenericRoleConfig, RoleGroup},
1717
v2::{
1818
builder::pod::container::{EnvVarName, EnvVarSet},
19+
controller_utils::{get_namespace, get_uid},
1920
product_logging::framework::{
2021
VectorContainerLogConfig, validate_logging_configuration_for_container,
2122
},
@@ -53,6 +54,16 @@ pub enum Error {
5354
cluster_name: String,
5455
},
5556

57+
#[snafu(display("failed to resolve namespace"))]
58+
ResolveNamespace {
59+
source: stackable_operator::v2::controller_utils::Error,
60+
},
61+
62+
#[snafu(display("failed to resolve uid"))]
63+
ResolveUid {
64+
source: stackable_operator::v2::controller_utils::Error,
65+
},
66+
5667
#[snafu(display("invalid role group name {role_group}"))]
5768
ParseRoleGroupName {
5869
source: stackable_operator::v2::macros::attributed_string_type::Error,
@@ -100,6 +111,8 @@ pub fn validate_cluster(
100111
ClusterName::from_str(&airflow.name_any()).with_context(|_| ParseClusterNameSnafu {
101112
cluster_name: airflow.name_any(),
102113
})?;
114+
let namespace = get_namespace(airflow).context(ResolveNamespaceSnafu)?;
115+
let uid = get_uid(airflow).context(ResolveUidSnafu)?;
103116

104117
// The Vector aggregator discovery ConfigMap name. Validity is already enforced by the
105118
// `ConfigMapName` type on the CRD; it is only required when the Vector agent is enabled.
@@ -162,8 +175,9 @@ pub fn validate_cluster(
162175
database_connection_details(airflow);
163176

164177
Ok(ValidatedCluster::new(
165-
airflow,
166178
cluster_name,
179+
namespace,
180+
uid,
167181
resolved_product_image,
168182
ValidatedClusterConfig {
169183
executor: airflow.spec.executor.clone(),

0 commit comments

Comments
 (0)