Skip to content

Commit 53c3d50

Browse files
committed
chore: migrate to new container builder
1 parent 4ba3965 commit 53c3d50

3 files changed

Lines changed: 24 additions & 23 deletions

File tree

rust/operator-binary/src/controller/build/resource/executor.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use stackable_operator::{
88
builder::{
99
configmap::ConfigMapBuilder,
1010
meta::ObjectMetaBuilder,
11-
pod::{PodBuilder, container::ContainerBuilder, security::PodSecurityContextBuilder},
11+
pod::{PodBuilder, security::PodSecurityContextBuilder},
1212
},
1313
crd::git_sync,
1414
k8s_openapi::{
1515
DeepMerge,
1616
api::core::v1::{ConfigMap, PodTemplateSpec},
1717
},
1818
kvp::{Label, LabelError},
19-
v2::builder::meta::ownerreference_from_resource,
19+
v2::builder::{meta::ownerreference_from_resource, pod::container::new_container_builder},
2020
};
2121

2222
use crate::{
@@ -42,11 +42,6 @@ use crate::{
4242

4343
#[derive(Snafu, Debug)]
4444
pub enum Error {
45-
#[snafu(display("invalid container name"))]
46-
InvalidContainerName {
47-
source: stackable_operator::builder::pod::container::Error,
48-
},
49-
5045
#[snafu(display("failed to configure graceful shutdown"))]
5146
GracefulShutdown {
5247
source: crate::controller::build::graceful_shutdown::Error,
@@ -114,8 +109,7 @@ pub fn build_executor_template_config_map(
114109

115110
// N.B. this "base" name is an airflow requirement and should not be changed!
116111
// See https://airflow.apache.org/docs/apache-airflow-providers-cncf-kubernetes/8.4.0/kubernetes_executor.html#base-image
117-
let mut airflow_container =
118-
ContainerBuilder::new(&Container::Base.to_string()).context(InvalidContainerNameSnafu)?;
112+
let mut airflow_container = new_container_builder(&Container::Base.to_container_name());
119113

120114
add_authentication_volumes_and_volume_mounts(
121115
authentication_config,

rust/operator-binary/src/controller/build/resource/statefulset.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use stackable_operator::{
44
meta::ObjectMetaBuilder,
55
pod::{
66
PodBuilder,
7-
container::ContainerBuilder,
87
resources::ResourceRequirementsBuilder,
98
security::PodSecurityContextBuilder,
109
volume::{
@@ -25,7 +24,10 @@ use stackable_operator::{
2524
kube::{ResourceExt, api::ObjectMeta},
2625
kvp::{Annotation, Label, LabelError},
2726
utils::COMMON_BASH_TRAP_FUNCTIONS,
28-
v2::{builder::meta::ownerreference_from_resource, types::operator::RoleGroupName},
27+
v2::{
28+
builder::{meta::ownerreference_from_resource, pod::container::new_container_builder},
29+
types::operator::RoleGroupName,
30+
},
2931
};
3032

3133
use crate::{
@@ -46,19 +48,14 @@ use crate::{
4648
controller_commons::{self, CONFIG_VOLUME_NAME, LOG_CONFIG_VOLUME_NAME, LOG_VOLUME_NAME},
4749
crd::{
4850
AirflowExecutor, AirflowRole, CONFIG_PATH, Container, HTTP_PORT_NAME, LISTENER_VOLUME_DIR,
49-
LISTENER_VOLUME_NAME, LOG_CONFIG_DIR, METRICS_PORT, METRICS_PORT_NAME, STACKABLE_LOG_DIR,
50-
TEMPLATE_LOCATION, TEMPLATE_VOLUME_NAME,
51+
LISTENER_VOLUME_NAME, LOG_CONFIG_DIR, METRICS_CONTAINER_NAME, METRICS_PORT,
52+
METRICS_PORT_NAME, STACKABLE_LOG_DIR, TEMPLATE_LOCATION, TEMPLATE_VOLUME_NAME,
5153
},
5254
};
5355

5456
#[derive(Snafu, Debug)]
5557
#[snafu(visibility(pub(crate)))]
5658
pub enum Error {
57-
#[snafu(display("invalid container name"))]
58-
InvalidContainerName {
59-
source: stackable_operator::builder::pod::container::Error,
60-
},
61-
6259
#[snafu(display("failed to configure graceful shutdown"))]
6360
GracefulShutdown {
6461
source: crate::controller::build::graceful_shutdown::Error,
@@ -154,8 +151,7 @@ pub fn build_server_rolegroup_statefulset(
154151
.service_account_name(service_account.name_any())
155152
.security_context(PodSecurityContextBuilder::new().fs_group(1000).build());
156153

157-
let mut airflow_container = ContainerBuilder::new(&Container::Airflow.to_string())
158-
.context(InvalidContainerNameSnafu)?;
154+
let mut airflow_container = new_container_builder(&Container::Airflow.to_container_name());
159155

160156
add_authentication_volumes_and_volume_mounts(
161157
authentication_config,
@@ -283,8 +279,7 @@ pub fn build_server_rolegroup_statefulset(
283279

284280
pb.add_container(airflow_container.build());
285281

286-
let metrics_container = ContainerBuilder::new("metrics")
287-
.context(InvalidContainerNameSnafu)?
282+
let metrics_container = new_container_builder(&METRICS_CONTAINER_NAME)
288283
.image_from_product_image(resolved_product_image)
289284
.command(vec![
290285
"/bin/bash".to_string(),

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ use stackable_operator::{
4242
role_utils::GenericCommonConfig,
4343
types::{
4444
common::Port,
45-
kubernetes::{ConfigMapName, ListenerClassName, ListenerName, SecretName, VolumeName},
45+
kubernetes::{
46+
ConfigMapName, ContainerName, ListenerClassName, ListenerName, SecretName,
47+
VolumeName,
48+
},
4649
},
4750
},
4851
versioned::versioned,
@@ -90,6 +93,7 @@ pub const HTTP_PORT_NAME: &str = "http";
9093
pub const HTTP_PORT: Port = Port(8080);
9194
pub const METRICS_PORT_NAME: &str = "metrics";
9295
pub const METRICS_PORT: Port = Port(9102);
96+
stackable_operator::constant!(pub METRICS_CONTAINER_NAME: ContainerName = "metrics");
9397

9498
const DEFAULT_AIRFLOW_GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_minutes_unchecked(2);
9599
const DEFAULT_WORKER_GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_minutes_unchecked(5);
@@ -828,6 +832,14 @@ pub enum Container {
828832
GitSync,
829833
}
830834

835+
impl Container {
836+
/// The type-safe container name for this variant (matching its kebab-case serialization).
837+
pub fn to_container_name(&self) -> ContainerName {
838+
ContainerName::from_str(&self.to_string())
839+
.expect("a Container variant name is a valid container name")
840+
}
841+
}
842+
831843
#[derive(Clone, Debug, Default, Fragment, JsonSchema, PartialEq)]
832844
#[fragment_attrs(
833845
derive(

0 commit comments

Comments
 (0)