Skip to content

Commit 1c0193e

Browse files
committed
moved validated structs to controller/mod.rs, renamed controller -> trino_controller, pass through validated cluster
1 parent 6154d03 commit 1c0193e

9 files changed

Lines changed: 178 additions & 153 deletions

File tree

rust/operator-binary/src/authentication/password/file.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use stackable_operator::{
1717
utils::COMMON_BASH_TRAP_FUNCTIONS,
1818
};
1919

20-
use crate::{authentication::password::PASSWORD_AUTHENTICATOR_NAME, controller::STACKABLE_LOG_DIR};
20+
use crate::{
21+
authentication::password::PASSWORD_AUTHENTICATOR_NAME, trino_controller::STACKABLE_LOG_DIR,
22+
};
2123

2224
// mounts
2325
const PASSWORD_DB_VOLUME_NAME: &str = "users";

rust/operator-binary/src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use crate::{
1010
authentication::TrinoAuthenticationConfig,
1111
catalog::config::CatalogConfig,
1212
config::{client_protocol, fault_tolerant_execution},
13-
controller::{STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR},
1413
crd::{
1514
CONFIG_DIR_NAME, Container, RW_CONFIG_DIR_NAME, STACKABLE_CLIENT_TLS_DIR,
1615
STACKABLE_INTERNAL_TLS_DIR, STACKABLE_MOUNT_INTERNAL_TLS_DIR,
1716
STACKABLE_MOUNT_SERVER_TLS_DIR, STACKABLE_SERVER_TLS_DIR, STACKABLE_TLS_STORE_PASSWORD,
1817
TrinoRole, v1alpha1,
1918
},
19+
trino_controller::{STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR},
2020
};
2121

2222
// TODO: replace with build::properties::ConfigFileName once command.rs moves under build/

rust/operator-binary/src/controller/build/config_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn build_rolegroup_config_map(
6868
role: &TrinoRole,
6969
rolegroup_ref: &RoleGroupRef<v1alpha1::TrinoCluster>,
7070
cluster_info: &KubernetesClusterInfo,
71-
recommended_labels: &ObjectLabels<'_, v1alpha1::TrinoCluster>,
71+
recommended_labels: &ObjectLabels<'_, ValidatedCluster>,
7272
) -> Result<ConfigMap> {
7373
let role_group_configs =
7474
cluster
@@ -217,7 +217,7 @@ pub fn build_rolegroup_config_map(
217217
pub fn build_rolegroup_catalog_config_map(
218218
cluster: &ValidatedCluster,
219219
rolegroup_ref: &RoleGroupRef<v1alpha1::TrinoCluster>,
220-
recommended_labels: &ObjectLabels<'_, v1alpha1::TrinoCluster>,
220+
recommended_labels: &ObjectLabels<'_, ValidatedCluster>,
221221
) -> Result<ConfigMap> {
222222
ConfigMapBuilder::new()
223223
.metadata(
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
//! Controller-level vocabulary: the [`ValidatedCluster`] type produced by the [`validate`] step
2+
//! and consumed by the [`build`] steps, plus the `dereference` / `validate` / `build` sub-modules.
3+
4+
use std::collections::BTreeMap;
5+
6+
use stackable_operator::{
7+
commons::product_image_selection::ResolvedProductImage,
8+
kube::{Resource, api::ObjectMeta},
9+
role_utils::JvmArgumentOverrides,
10+
v2::types::{
11+
kubernetes::{NamespaceName, Uid},
12+
operator::ClusterName,
13+
},
14+
};
15+
16+
use crate::{
17+
authentication::TrinoAuthenticationConfig,
18+
authorization::opa::TrinoOpaConfig,
19+
catalog::config::CatalogConfig,
20+
config::{
21+
client_protocol::ResolvedClientProtocolConfig,
22+
fault_tolerant_execution::ResolvedFaultTolerantExecutionConfig,
23+
},
24+
crd::{TrinoRole, discovery::TrinoPodRef, v1alpha1},
25+
};
26+
27+
pub(crate) mod build;
28+
pub(crate) mod dereference;
29+
pub(crate) mod validate;
30+
31+
pub use validate::{RoleGroupName, TrinoRoleGroupConfig};
32+
33+
#[derive(Clone, Debug)]
34+
pub struct ValidatedTls {
35+
pub server: Option<String>,
36+
pub internal: Option<String>,
37+
}
38+
39+
/// Cluster-wide settings, grouped to parallel `spec.clusterConfig` CRD.
40+
#[derive(Clone, Debug)]
41+
pub struct ValidatedClusterConfig {
42+
pub tls: ValidatedTls,
43+
pub authentication: TrinoAuthenticationConfig,
44+
pub authentication_enabled: bool,
45+
pub authorization: Option<TrinoOpaConfig>,
46+
pub fault_tolerant_execution: Option<ResolvedFaultTolerantExecutionConfig>,
47+
pub client_protocol: Option<ResolvedClientProtocolConfig>,
48+
pub coordinator_pod_refs: Vec<TrinoPodRef>,
49+
pub catalogs: Vec<CatalogConfig>,
50+
}
51+
52+
/// The validated TrinoCluster. The output of the validate step.
53+
#[derive(Clone, Debug)]
54+
pub struct ValidatedCluster {
55+
/// Metadata mirroring the source [`v1alpha1::TrinoCluster`] (name, namespace and UID).
56+
///
57+
/// Kept private and only exposed through the [`Resource`] implementation, so that a
58+
/// `ValidatedCluster` can be used directly as the owner of generated objects (e.g. to set
59+
/// owner references) without threading the raw `TrinoCluster` through the build step.
60+
metadata: ObjectMeta,
61+
pub name: ClusterName,
62+
pub namespace: NamespaceName,
63+
pub uid: Uid,
64+
pub image: ResolvedProductImage,
65+
pub product_version: u16,
66+
pub cluster_config: ValidatedClusterConfig,
67+
pub role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>>,
68+
/// Role-level JVM argument overrides per role. Required to render `jvm.config` in the build
69+
/// step without access to the raw [`v1alpha1::TrinoCluster`] (the role-group level overrides
70+
/// are carried by [`TrinoRoleGroupConfig::product_specific_common_config`]).
71+
pub role_jvm_argument_overrides: BTreeMap<TrinoRole, JvmArgumentOverrides>,
72+
}
73+
74+
impl ValidatedCluster {
75+
#[allow(clippy::too_many_arguments)]
76+
pub fn new(
77+
name: ClusterName,
78+
namespace: NamespaceName,
79+
uid: Uid,
80+
image: ResolvedProductImage,
81+
product_version: u16,
82+
cluster_config: ValidatedClusterConfig,
83+
role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>>,
84+
role_jvm_argument_overrides: BTreeMap<TrinoRole, JvmArgumentOverrides>,
85+
) -> Self {
86+
Self {
87+
metadata: ObjectMeta {
88+
name: Some(name.to_string()),
89+
namespace: Some(namespace.to_string()),
90+
uid: Some(uid.to_string()),
91+
..ObjectMeta::default()
92+
},
93+
name,
94+
namespace,
95+
uid,
96+
image,
97+
product_version,
98+
cluster_config,
99+
role_group_configs,
100+
role_jvm_argument_overrides,
101+
}
102+
}
103+
}
104+
105+
impl Resource for ValidatedCluster {
106+
type DynamicType = <v1alpha1::TrinoCluster as Resource>::DynamicType;
107+
type Scope = <v1alpha1::TrinoCluster as Resource>::Scope;
108+
109+
fn kind(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
110+
v1alpha1::TrinoCluster::kind(dt)
111+
}
112+
113+
fn group(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
114+
v1alpha1::TrinoCluster::group(dt)
115+
}
116+
117+
fn version(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
118+
v1alpha1::TrinoCluster::version(dt)
119+
}
120+
121+
fn plural(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
122+
v1alpha1::TrinoCluster::plural(dt)
123+
}
124+
125+
fn meta(&self) -> &ObjectMeta {
126+
&self.metadata
127+
}
128+
129+
fn meta_mut(&mut self) -> &mut ObjectMeta {
130+
&mut self.metadata
131+
}
132+
}

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

Lines changed: 6 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,18 @@ use std::{collections::BTreeMap, str::FromStr};
88
use snafu::{ResultExt, Snafu};
99
use stackable_operator::{
1010
cli::OperatorEnvironmentOptions,
11-
commons::product_image_selection::{self, ResolvedProductImage},
12-
kube::{Resource, ResourceExt as _, api::ObjectMeta},
11+
commons::product_image_selection,
12+
kube::ResourceExt as _,
1313
role_utils::{GenericRoleConfig, JavaCommonConfig, JvmArgumentOverrides},
14-
v2::{
15-
controller_utils::{get_cluster_name, get_namespace, get_uid},
16-
types::{
17-
kubernetes::{NamespaceName, Uid},
18-
operator::ClusterName,
19-
},
20-
},
14+
v2::controller_utils::{get_cluster_name, get_namespace, get_uid},
2115
};
2216
use strum::{EnumDiscriminants, IntoEnumIterator, IntoStaticStr};
2317

18+
use super::{ValidatedCluster, ValidatedClusterConfig, ValidatedTls};
2419
use crate::{
2520
authentication::{self, TrinoAuthenticationConfig, TrinoAuthenticationTypes},
26-
authorization::opa::TrinoOpaConfig,
27-
catalog::config::CatalogConfig,
28-
config::{
29-
client_protocol::ResolvedClientProtocolConfig,
30-
fault_tolerant_execution::ResolvedFaultTolerantExecutionConfig,
31-
},
3221
controller::dereference::DereferencedObjects,
33-
crd::{TrinoRole, discovery::TrinoPodRef, v1alpha1},
22+
crd::{TrinoRole, v1alpha1},
3423
framework::role_utils::with_validated_config,
3524
};
3625

@@ -98,107 +87,6 @@ pub type TrinoRoleGroupConfig = crate::framework::role_utils::RoleGroupConfig<
9887
v1alpha1::TrinoConfigOverrides,
9988
>;
10089

101-
#[derive(Clone, Debug)]
102-
pub struct ValidatedTls {
103-
pub server: Option<String>,
104-
pub internal: Option<String>,
105-
}
106-
107-
/// Cluster-wide settings, grouped to parallel `spec.clusterConfig` CRD.
108-
#[derive(Clone, Debug)]
109-
pub struct ValidatedClusterConfig {
110-
pub tls: ValidatedTls,
111-
pub authentication: TrinoAuthenticationConfig,
112-
pub authentication_enabled: bool,
113-
pub authorization: Option<TrinoOpaConfig>,
114-
pub fault_tolerant_execution: Option<ResolvedFaultTolerantExecutionConfig>,
115-
pub client_protocol: Option<ResolvedClientProtocolConfig>,
116-
pub coordinator_pod_refs: Vec<TrinoPodRef>,
117-
pub catalogs: Vec<CatalogConfig>,
118-
}
119-
120-
/// The validated TrinoCluster. The output of the validate step.
121-
#[derive(Clone, Debug)]
122-
pub struct ValidatedCluster {
123-
/// Metadata mirroring the source [`v1alpha1::TrinoCluster`] (name, namespace and UID).
124-
///
125-
/// Kept private and only exposed through the [`Resource`] implementation, so that a
126-
/// `ValidatedCluster` can be used directly as the owner of generated objects (e.g. to set
127-
/// owner references) without threading the raw `TrinoCluster` through the build step.
128-
metadata: ObjectMeta,
129-
pub name: ClusterName,
130-
pub namespace: NamespaceName,
131-
pub uid: Uid,
132-
pub image: ResolvedProductImage,
133-
pub product_version: u16,
134-
pub cluster_config: ValidatedClusterConfig,
135-
pub role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>>,
136-
/// Role-level JVM argument overrides per role. Required to render `jvm.config` in the build
137-
/// step without access to the raw [`v1alpha1::TrinoCluster`] (the role-group level overrides
138-
/// are carried by [`TrinoRoleGroupConfig::product_specific_common_config`]).
139-
pub role_jvm_argument_overrides: BTreeMap<TrinoRole, JvmArgumentOverrides>,
140-
}
141-
142-
impl ValidatedCluster {
143-
#[allow(clippy::too_many_arguments)]
144-
pub fn new(
145-
name: ClusterName,
146-
namespace: NamespaceName,
147-
uid: Uid,
148-
image: ResolvedProductImage,
149-
product_version: u16,
150-
cluster_config: ValidatedClusterConfig,
151-
role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>>,
152-
role_jvm_argument_overrides: BTreeMap<TrinoRole, JvmArgumentOverrides>,
153-
) -> Self {
154-
Self {
155-
metadata: ObjectMeta {
156-
name: Some(name.to_string()),
157-
namespace: Some(namespace.to_string()),
158-
uid: Some(uid.to_string()),
159-
..ObjectMeta::default()
160-
},
161-
name,
162-
namespace,
163-
uid,
164-
image,
165-
product_version,
166-
cluster_config,
167-
role_group_configs,
168-
role_jvm_argument_overrides,
169-
}
170-
}
171-
}
172-
173-
impl Resource for ValidatedCluster {
174-
type DynamicType = <v1alpha1::TrinoCluster as Resource>::DynamicType;
175-
type Scope = <v1alpha1::TrinoCluster as Resource>::Scope;
176-
177-
fn kind(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
178-
v1alpha1::TrinoCluster::kind(dt)
179-
}
180-
181-
fn group(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
182-
v1alpha1::TrinoCluster::group(dt)
183-
}
184-
185-
fn version(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
186-
v1alpha1::TrinoCluster::version(dt)
187-
}
188-
189-
fn plural(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
190-
v1alpha1::TrinoCluster::plural(dt)
191-
}
192-
193-
fn meta(&self) -> &ObjectMeta {
194-
&self.metadata
195-
}
196-
197-
fn meta_mut(&mut self) -> &mut ObjectMeta {
198-
&mut self.metadata
199-
}
200-
}
201-
20290
/// Validates the cluster spec and dereferenced inputs.
20391
pub fn validate(
20492
trino: &v1alpha1::TrinoCluster,
@@ -211,7 +99,7 @@ pub fn validate(
21199
.spec
212100
.image
213101
.resolve(
214-
super::CONTAINER_IMAGE_BASE_NAME,
102+
crate::trino_controller::CONTAINER_IMAGE_BASE_NAME,
215103
&operator_environment.image_repository,
216104
crate::built_info::PKG_VERSION,
217105
)

rust/operator-binary/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ use stackable_operator::{
3333
};
3434

3535
use crate::{
36-
controller::{FULL_CONTROLLER_NAME, OPERATOR_NAME},
3736
crd::{
3837
TrinoCluster, TrinoClusterVersion,
3938
catalog::{TrinoCatalog, TrinoCatalogVersion},
4039
v1alpha1,
4140
},
41+
trino_controller::{FULL_CONTROLLER_NAME, OPERATOR_NAME},
4242
webhooks::conversion::create_webhook_server,
4343
};
4444

@@ -53,6 +53,7 @@ mod framework;
5353
mod listener;
5454
mod operations;
5555
mod service;
56+
mod trino_controller;
5657
mod webhooks;
5758

5859
mod built_info {
@@ -195,9 +196,9 @@ async fn main() -> anyhow::Result<()> {
195196
)
196197
.graceful_shutdown_on(sigterm_watcher.handle())
197198
.run(
198-
controller::reconcile_trino,
199-
controller::error_policy,
200-
Arc::new(controller::Ctx {
199+
trino_controller::reconcile_trino,
200+
trino_controller::error_policy,
201+
Arc::new(trino_controller::Ctx {
201202
client: client.clone(),
202203
operator_environment,
203204
}),

rust/operator-binary/src/operations/pdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use stackable_operator::{
77
};
88

99
use crate::{
10-
controller::{CONTROLLER_NAME, OPERATOR_NAME},
1110
crd::{APP_NAME, TrinoRole, v1alpha1},
11+
trino_controller::{CONTROLLER_NAME, OPERATOR_NAME},
1212
};
1313

1414
#[derive(Snafu, Debug)]

0 commit comments

Comments
 (0)