Skip to content

Commit 4ba3965

Browse files
committed
refactor: use VolumeName and Port types
1 parent 3368ac8 commit 4ba3965

7 files changed

Lines changed: 43 additions & 37 deletions

File tree

rust/operator-binary/src/airflow_controller.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub async fn reconcile_airflow(
354354
&validated_cluster.image,
355355
&Vec::<EnvVar>::from(validated_rg_config.env_overrides.clone()),
356356
&airflow.volume_mounts(),
357-
LOG_VOLUME_NAME,
357+
LOG_VOLUME_NAME.as_ref(),
358358
&validated_rg_config
359359
.config
360360
.logging
@@ -484,7 +484,7 @@ async fn build_executor_template(
484484
&validated_cluster.image,
485485
&env_vars_from_overrides(&common_config.env_overrides),
486486
&airflow.volume_mounts(),
487-
LOG_VOLUME_NAME,
487+
LOG_VOLUME_NAME.as_ref(),
488488
&merged_executor_config
489489
.logging
490490
.for_container(&Container::GitSync),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ pub fn build_executor_template_config_map(
134134
))
135135
.add_volume_mounts(cluster.volume_mounts())
136136
.context(AddVolumeMountSnafu)?
137-
.add_volume_mount(CONFIG_VOLUME_NAME, CONFIG_PATH)
137+
.add_volume_mount(&*CONFIG_VOLUME_NAME, CONFIG_PATH)
138138
.context(AddVolumeMountSnafu)?
139-
.add_volume_mount(LOG_CONFIG_VOLUME_NAME, LOG_CONFIG_DIR)
139+
.add_volume_mount(&*LOG_CONFIG_VOLUME_NAME, LOG_CONFIG_DIR)
140140
.context(AddVolumeMountSnafu)?
141-
.add_volume_mount(LOG_VOLUME_NAME, STACKABLE_LOG_DIR)
141+
.add_volume_mount(&*LOG_VOLUME_NAME, STACKABLE_LOG_DIR)
142142
.context(AddVolumeMountSnafu)?;
143143

144144
add_git_sync_resources(

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ use stackable_operator::{
1414
builder::pod::container::EnvVarSet,
1515
product_logging::framework::{VectorContainerLogConfig, vector_container},
1616
role_group_utils::ResourceNames,
17-
types::kubernetes::{ContainerName, VolumeName},
17+
types::kubernetes::ContainerName,
1818
},
1919
};
2020

21-
use crate::crd::authentication::{
22-
AirflowAuthenticationClassResolved, AirflowClientAuthenticationDetailsResolved,
21+
use crate::{
22+
controller_commons::{CONFIG_VOLUME_NAME, LOG_VOLUME_NAME},
23+
crd::authentication::{
24+
AirflowAuthenticationClassResolved, AirflowClientAuthenticationDetailsResolved,
25+
},
2326
};
2427

2528
#[derive(Snafu, Debug)]
@@ -112,10 +115,6 @@ pub(crate) fn add_git_sync_resources(
112115
}
113116

114117
stackable_operator::constant!(VECTOR_CONTAINER_NAME: ContainerName = "vector");
115-
// Typed volume names required by the v2 `vector_container`. Their values match the `&str`
116-
// constants in `controller_commons` used elsewhere to build the same volumes.
117-
stackable_operator::constant!(CONFIG_VOLUME_NAME_TYPED: VolumeName = "config");
118-
stackable_operator::constant!(LOG_VOLUME_NAME_TYPED: VolumeName = "log");
119118

120119
/// Builds the Vector log-collection sidecar container from the up-front-validated logging config.
121120
pub(crate) fn build_logging_container(
@@ -128,8 +127,8 @@ pub(crate) fn build_logging_container(
128127
resolved_product_image,
129128
vector_log_config,
130129
resource_names,
131-
&CONFIG_VOLUME_NAME_TYPED,
132-
&LOG_VOLUME_NAME_TYPED,
130+
&CONFIG_VOLUME_NAME,
131+
&LOG_VOLUME_NAME,
133132
EnvVarSet::new(),
134133
)
135134
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use stackable_operator::{
66
meta::ownerreference_from_resource,
77
service::{Scheme, Scraping, prometheus_annotations, prometheus_labels},
88
},
9-
types::{common::Port, operator::RoleGroupName},
9+
types::operator::RoleGroupName,
1010
},
1111
};
1212

@@ -69,7 +69,7 @@ pub fn build_rolegroup_metrics_service(
6969
&Scraping::Enabled,
7070
&Scheme::Http,
7171
"/metrics",
72-
&Port(METRICS_PORT),
72+
&METRICS_PORT,
7373
))
7474
.build(),
7575
spec: Some(ServiceSpec {

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,26 +197,27 @@ pub fn build_server_rolegroup_statefulset(
197197
.add_volume_mounts(volume_mounts)
198198
.context(AddVolumeMountSnafu)?;
199199
airflow_container
200-
.add_volume_mount(CONFIG_VOLUME_NAME, CONFIG_PATH)
200+
.add_volume_mount(&*CONFIG_VOLUME_NAME, CONFIG_PATH)
201201
.context(AddVolumeMountSnafu)?;
202202
airflow_container
203-
.add_volume_mount(LOG_CONFIG_VOLUME_NAME, LOG_CONFIG_DIR)
203+
.add_volume_mount(&*LOG_CONFIG_VOLUME_NAME, LOG_CONFIG_DIR)
204204
.context(AddVolumeMountSnafu)?;
205205
airflow_container
206-
.add_volume_mount(LOG_VOLUME_NAME, STACKABLE_LOG_DIR)
206+
.add_volume_mount(&*LOG_VOLUME_NAME, STACKABLE_LOG_DIR)
207207
.context(AddVolumeMountSnafu)?;
208208

209209
if let AirflowExecutor::KubernetesExecutors { .. } = executor {
210210
airflow_container
211-
.add_volume_mount(TEMPLATE_VOLUME_NAME, TEMPLATE_LOCATION)
211+
.add_volume_mount(&*TEMPLATE_VOLUME_NAME, TEMPLATE_LOCATION)
212212
.context(AddVolumeMountSnafu)?;
213213
}
214214

215215
// for roles with an http endpoint
216216
if let Some(http_port) = airflow_role.get_http_port() {
217+
let http_port = i32::from(http_port);
217218
let probe = Probe {
218219
tcp_socket: Some(TCPSocketAction {
219-
port: IntOrString::Int(http_port.into()),
220+
port: IntOrString::Int(http_port),
220221
..TCPSocketAction::default()
221222
}),
222223
initial_delay_seconds: Some(60),
@@ -226,7 +227,7 @@ pub fn build_server_rolegroup_statefulset(
226227
};
227228
airflow_container.readiness_probe(probe.clone());
228229
airflow_container.liveness_probe(probe);
229-
airflow_container.add_container_port(HTTP_PORT_NAME, http_port.into());
230+
airflow_container.add_container_port(HTTP_PORT_NAME, http_port);
230231
}
231232

232233
let mut pvcs: Option<Vec<PersistentVolumeClaim>> = None;
@@ -249,7 +250,7 @@ pub fn build_server_rolegroup_statefulset(
249250
pvcs = Some(vec![pvc]);
250251

251252
airflow_container
252-
.add_volume_mount(LISTENER_VOLUME_NAME, LISTENER_VOLUME_DIR)
253+
.add_volume_mount(&*LISTENER_VOLUME_NAME, LISTENER_VOLUME_DIR)
253254
.context(AddVolumeMountSnafu)?;
254255
}
255256

@@ -326,7 +327,7 @@ pub fn build_server_rolegroup_statefulset(
326327

327328
if let AirflowExecutor::KubernetesExecutors { .. } = executor {
328329
pb.add_volume(
329-
VolumeBuilder::new(TEMPLATE_VOLUME_NAME)
330+
VolumeBuilder::new(&*TEMPLATE_VOLUME_NAME)
330331
.with_config_map(validated_cluster.executor_template_configmap_name())
331332
.build(),
332333
)

rust/operator-binary/src/controller_commons.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::str::FromStr;
2+
13
use stackable_operator::{
24
builder::pod::volume::VolumeBuilder,
35
k8s_openapi::api::core::v1::{ConfigMapVolumeSource, EmptyDirVolumeSource, Volume},
@@ -8,13 +10,14 @@ use stackable_operator::{
810
CustomContainerLogConfig,
911
},
1012
},
13+
v2::types::kubernetes::VolumeName,
1114
};
1215

1316
use crate::crd::MAX_LOG_FILES_SIZE;
1417

15-
pub const CONFIG_VOLUME_NAME: &str = "config";
16-
pub const LOG_CONFIG_VOLUME_NAME: &str = "log-config";
17-
pub const LOG_VOLUME_NAME: &str = "log";
18+
stackable_operator::constant!(pub CONFIG_VOLUME_NAME: VolumeName = "config");
19+
stackable_operator::constant!(pub LOG_CONFIG_VOLUME_NAME: VolumeName = "log-config");
20+
stackable_operator::constant!(pub LOG_VOLUME_NAME: VolumeName = "log");
1821

1922
pub fn create_volumes(
2023
config_map_name: &str,
@@ -23,12 +26,12 @@ pub fn create_volumes(
2326
let mut volumes = Vec::new();
2427

2528
volumes.push(
26-
VolumeBuilder::new(CONFIG_VOLUME_NAME)
29+
VolumeBuilder::new(&*CONFIG_VOLUME_NAME)
2730
.with_config_map(config_map_name)
2831
.build(),
2932
);
3033
volumes.push(Volume {
31-
name: LOG_VOLUME_NAME.into(),
34+
name: LOG_VOLUME_NAME.to_string(),
3235
empty_dir: Some(EmptyDirVolumeSource {
3336
medium: None,
3437
size_limit: Some(product_logging::framework::calculate_log_volume_size_limit(
@@ -46,7 +49,7 @@ pub fn create_volumes(
4649
}) = log_config
4750
{
4851
volumes.push(Volume {
49-
name: LOG_CONFIG_VOLUME_NAME.into(),
52+
name: LOG_CONFIG_VOLUME_NAME.to_string(),
5053
config_map: Some(ConfigMapVolumeSource {
5154
name: config_map.into(),
5255
..ConfigMapVolumeSource::default()
@@ -55,7 +58,7 @@ pub fn create_volumes(
5558
});
5659
} else {
5760
volumes.push(Volume {
58-
name: LOG_CONFIG_VOLUME_NAME.into(),
61+
name: LOG_CONFIG_VOLUME_NAME.to_string(),
5962
config_map: Some(ConfigMapVolumeSource {
6063
name: config_map_name.into(),
6164
..ConfigMapVolumeSource::default()

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ use stackable_operator::{
4040
config_overrides::KeyValueConfigOverrides,
4141
flask_config_writer::{FlaskAppConfigOptions, PythonType},
4242
role_utils::GenericCommonConfig,
43-
types::kubernetes::{ConfigMapName, ListenerClassName, ListenerName, SecretName},
43+
types::{
44+
common::Port,
45+
kubernetes::{ConfigMapName, ListenerClassName, ListenerName, SecretName, VolumeName},
46+
},
4447
},
4548
versioned::versioned,
4649
};
@@ -76,17 +79,17 @@ pub const LOG_CONFIG_DIR: &str = "/stackable/app/log_config";
7679
pub const AIRFLOW_HOME: &str = "/stackable/airflow";
7780
pub const AIRFLOW_CONFIG_FILENAME: &str = "webserver_config.py";
7881

79-
pub const TEMPLATE_VOLUME_NAME: &str = "airflow-executor-pod-template";
82+
stackable_operator::constant!(pub TEMPLATE_VOLUME_NAME: VolumeName = "airflow-executor-pod-template");
8083
pub const TEMPLATE_LOCATION: &str = "/templates";
8184
pub const TEMPLATE_NAME: &str = "airflow_executor_pod_template.yaml";
8285

83-
pub const LISTENER_VOLUME_NAME: &str = "listener";
86+
stackable_operator::constant!(pub LISTENER_VOLUME_NAME: VolumeName = "listener");
8487
pub const LISTENER_VOLUME_DIR: &str = "/stackable/listener";
8588

8689
pub const HTTP_PORT_NAME: &str = "http";
87-
pub const HTTP_PORT: u16 = 8080;
90+
pub const HTTP_PORT: Port = Port(8080);
8891
pub const METRICS_PORT_NAME: &str = "metrics";
89-
pub const METRICS_PORT: u16 = 9102;
92+
pub const METRICS_PORT: Port = Port(9102);
9093

9194
const DEFAULT_AIRFLOW_GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_minutes_unchecked(2);
9295
const DEFAULT_WORKER_GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_minutes_unchecked(5);
@@ -719,7 +722,7 @@ impl AirflowRole {
719722

720723
/// Will be used to expose service ports and - by extension - which roles should be
721724
/// created as services.
722-
pub fn get_http_port(&self) -> Option<u16> {
725+
pub fn get_http_port(&self) -> Option<Port> {
723726
match &self {
724727
AirflowRole::Webserver => Some(HTTP_PORT),
725728
AirflowRole::Scheduler => None,

0 commit comments

Comments
 (0)