Skip to content

Commit 5ce74ff

Browse files
authored
chore: Version CRD (#711)
* chore: migrate crd crate to operator-binary module. * remove unused dependencies * chore: add stackable-versioned dependency * reorganize specs for versioning * versioning for the TrinoCatalog spec * versioning for the TrinoCluster and referenced specs * fix rustdoc references * review feedback * review feedback (part 2)
1 parent fe40a83 commit 5ce74ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1885
-717
lines changed

Cargo.lock

Lines changed: 275 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 1150 additions & 211 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["rust/crd", "rust/operator-binary"]
2+
members = ["rust/operator-binary"]
33
resolver = "2"
44

55
[workspace.package]
@@ -18,14 +18,13 @@ const_format = "0.2"
1818
futures = { version = "0.3", features = ["compat"] }
1919
indoc = "2.0"
2020
openssl = "0.10"
21-
pin-project = "1.1"
2221
rstest = "0.24"
23-
semver = "1.0"
2422
serde = { version = "1.0", features = ["derive"] }
2523
serde_json = "1.0"
2624
serde_yaml = "0.9"
2725
snafu = "0.8"
2826
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.85.0" }
27+
stackable-versioned = { git = "https://github.com/stackabletech/operator-rs.git", features = ["k8s"], tag = "stackable-versioned-0.5.0" }
2928
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }
3029
strum = { version = "0.26", features = ["derive"] }
3130
tokio = { version = "1.40", features = ["full"] }

crate-hashes.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/crd/Cargo.toml

Lines changed: 0 additions & 22 deletions
This file was deleted.

rust/operator-binary/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ publish = false
1010
build = "build.rs"
1111

1212
[dependencies]
13-
stackable-trino-crd = { path = "../crd" }
1413

1514
anyhow.workspace = true
1615
async-trait.workspace = true
@@ -19,18 +18,20 @@ const_format.workspace = true
1918
futures.workspace = true
2019
indoc.workspace = true
2120
openssl.workspace = true
22-
pin-project.workspace = true
2321
product-config.workspace = true
24-
semver.workspace = true
2522
snafu.workspace = true
2623
stackable-operator.workspace = true
24+
stackable-versioned.workspace = true
2725
strum.workspace = true
2826
tokio.workspace = true
2927
tracing.workspace = true
3028
serde_yaml.workspace = true
29+
serde.workspace = true
30+
serde_json.workspace = true
3131

3232
[dev-dependencies]
3333
rstest.workspace = true
34+
serde_yaml.workspace = true
3435

3536
[build-dependencies]
3637
built.workspace = true

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

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ use stackable_operator::{
2222
k8s_openapi::api::core::v1::{Container, EnvVar, Volume, VolumeMount},
2323
kube::{runtime::reflector::ObjectRef, ResourceExt},
2424
};
25-
use stackable_trino_crd::{authentication::ResolvedAuthenticationClassRef, TrinoRole};
2625
use strum::EnumDiscriminants;
2726
use tracing::trace;
2827

29-
use crate::authentication::{
30-
oidc::{OidcAuthenticator, TrinoOidcAuthentication},
31-
password::{
32-
file::FileAuthenticator, ldap::LdapAuthenticator, TrinoPasswordAuthentication,
33-
TrinoPasswordAuthenticator,
28+
use crate::{
29+
authentication::{
30+
oidc::{OidcAuthenticator, TrinoOidcAuthentication},
31+
password::{
32+
file::FileAuthenticator, ldap::LdapAuthenticator, TrinoPasswordAuthentication,
33+
TrinoPasswordAuthenticator,
34+
},
3435
},
36+
crd::{authentication::ResolvedAuthenticationClassRef, TrinoRole},
3537
};
3638

3739
pub(crate) mod oidc;
@@ -85,14 +87,14 @@ pub struct TrinoAuthenticationConfig {
8587
/// All extra config files required for authentication for each role.
8688
config_files: HashMap<TrinoRole, BTreeMap<String, String>>,
8789
/// Additional env variables for a certain role and container
88-
env_vars: HashMap<TrinoRole, BTreeMap<stackable_trino_crd::Container, Vec<EnvVar>>>,
90+
env_vars: HashMap<TrinoRole, BTreeMap<crate::crd::Container, Vec<EnvVar>>>,
8991
/// All extra container commands for a certain role and container
90-
commands: HashMap<TrinoRole, BTreeMap<stackable_trino_crd::Container, Vec<String>>>,
92+
commands: HashMap<TrinoRole, BTreeMap<crate::crd::Container, Vec<String>>>,
9193
/// Additional volumes like secret mounts, user file database etc.
9294
volumes: Vec<Volume>,
9395
/// Additional volume mounts for each role and container. Shared volumes have to be added
9496
/// manually in each container.
95-
volume_mounts: HashMap<TrinoRole, BTreeMap<stackable_trino_crd::Container, Vec<VolumeMount>>>,
97+
volume_mounts: HashMap<TrinoRole, BTreeMap<crate::crd::Container, Vec<VolumeMount>>>,
9698
/// Additional side car container for the provided role
9799
sidecar_containers: HashMap<TrinoRole, Vec<Container>>,
98100
}
@@ -157,29 +159,27 @@ impl TrinoAuthenticationConfig {
157159
.add_volumes(self.volumes())
158160
.context(AddVolumeSnafu)?;
159161

160-
let affected_containers = vec![
161-
stackable_trino_crd::Container::Prepare,
162-
stackable_trino_crd::Container::Trino,
163-
];
162+
let affected_containers =
163+
vec![crate::crd::Container::Prepare, crate::crd::Container::Trino];
164164

165165
for container in &affected_containers {
166166
let volume_mounts = self.volume_mounts(role, container);
167167

168168
match container {
169-
stackable_trino_crd::Container::Prepare => {
169+
crate::crd::Container::Prepare => {
170170
prepare_builder
171171
.add_volume_mounts(volume_mounts)
172172
.context(AddVolumeMountSnafu)?;
173173
}
174-
stackable_trino_crd::Container::Trino => {
174+
crate::crd::Container::Trino => {
175175
trino_builder
176176
.add_volume_mounts(volume_mounts)
177177
.context(AddVolumeMountSnafu)?;
178178
}
179179
// handled internally
180-
stackable_trino_crd::Container::PasswordFileUpdater => {}
180+
crate::crd::Container::PasswordFileUpdater => {}
181181
// nothing to do here
182-
stackable_trino_crd::Container::Vector => {}
182+
crate::crd::Container::Vector => {}
183183
}
184184
}
185185

@@ -220,7 +220,7 @@ impl TrinoAuthenticationConfig {
220220
pub fn add_env_vars(
221221
&mut self,
222222
role: TrinoRole,
223-
container: stackable_trino_crd::Container,
223+
container: crate::crd::Container,
224224
env_var: Vec<EnvVar>,
225225
) {
226226
self.env_vars
@@ -235,7 +235,7 @@ impl TrinoAuthenticationConfig {
235235
pub fn add_commands(
236236
&mut self,
237237
role: TrinoRole,
238-
container: stackable_trino_crd::Container,
238+
container: crate::crd::Container,
239239
commands: Vec<String>,
240240
) {
241241
self.commands
@@ -265,7 +265,7 @@ impl TrinoAuthenticationConfig {
265265
pub fn add_volume_mount(
266266
&mut self,
267267
role: TrinoRole,
268-
container: stackable_trino_crd::Container,
268+
container: crate::crd::Container,
269269
volume_mount: VolumeMount,
270270
) {
271271
let current_volume_mounts = self
@@ -288,7 +288,7 @@ impl TrinoAuthenticationConfig {
288288
pub fn add_volume_mounts(
289289
&mut self,
290290
role: TrinoRole,
291-
container: stackable_trino_crd::Container,
291+
container: crate::crd::Container,
292292
volume_mounts: Vec<VolumeMount>,
293293
) {
294294
for volume_mount in volume_mounts {
@@ -319,11 +319,7 @@ impl TrinoAuthenticationConfig {
319319
}
320320

321321
/// Retrieve additional env vars for a given role and container.
322-
pub fn env_vars(
323-
&self,
324-
role: &TrinoRole,
325-
container: &stackable_trino_crd::Container,
326-
) -> Vec<EnvVar> {
322+
pub fn env_vars(&self, role: &TrinoRole, container: &crate::crd::Container) -> Vec<EnvVar> {
327323
self.env_vars
328324
.get(role)
329325
.cloned()
@@ -334,11 +330,7 @@ impl TrinoAuthenticationConfig {
334330
}
335331

336332
/// Retrieve additional container commands for a given role and container.
337-
pub fn commands(
338-
&self,
339-
role: &TrinoRole,
340-
container: &stackable_trino_crd::Container,
341-
) -> Vec<String> {
333+
pub fn commands(&self, role: &TrinoRole, container: &crate::crd::Container) -> Vec<String> {
342334
self.commands
343335
.get(role)
344336
.cloned()
@@ -357,7 +349,7 @@ impl TrinoAuthenticationConfig {
357349
pub fn volume_mounts(
358350
&self,
359351
role: &TrinoRole,
360-
container: &stackable_trino_crd::Container,
352+
container: &crate::crd::Container,
361353
) -> Vec<VolumeMount> {
362354
if let Some(volume_mounts) = self.volume_mounts.get(role) {
363355
volume_mounts.get(container).cloned().unwrap_or_default()
@@ -565,9 +557,9 @@ impl TryFrom<Vec<ResolvedAuthenticationClassRef>> for TrinoAuthenticationTypes {
565557
#[cfg(test)]
566558
mod tests {
567559
use stackable_operator::commons::authentication::oidc::ClientAuthenticationOptions;
568-
use stackable_trino_crd::RW_CONFIG_DIR_NAME;
569560

570561
use super::*;
562+
use crate::crd::RW_CONFIG_DIR_NAME;
571563

572564
const OIDC_AUTH_CLASS_1: &str = "oidc-auth-1";
573565
const FILE_AUTH_CLASS_1: &str = "file-auth-1";
@@ -800,17 +792,15 @@ mod tests {
800792
fn test_trino_password_authenticator_volume_mounts() {
801793
// nothing for workers
802794
assert!(setup_authentication_config()
803-
.volume_mounts(&TrinoRole::Worker, &stackable_trino_crd::Container::Trino,)
795+
.volume_mounts(&TrinoRole::Worker, &crate::crd::Container::Trino,)
804796
.is_empty());
805797
assert!(setup_authentication_config()
806-
.volume_mounts(&TrinoRole::Worker, &stackable_trino_crd::Container::Prepare,)
798+
.volume_mounts(&TrinoRole::Worker, &crate::crd::Container::Prepare,)
807799
.is_empty());
808800

809801
// coordinator - main container
810-
let coordinator_main_mounts = setup_authentication_config().volume_mounts(
811-
&TrinoRole::Coordinator,
812-
&stackable_trino_crd::Container::Trino,
813-
);
802+
let coordinator_main_mounts = setup_authentication_config()
803+
.volume_mounts(&TrinoRole::Coordinator, &crate::crd::Container::Trino);
814804

815805
// we expect one user password db mount
816806
assert_eq!(coordinator_main_mounts.len(), 1);
@@ -828,30 +818,24 @@ mod tests {
828818

829819
// nothing for workers
830820
assert!(auth_config
831-
.commands(&TrinoRole::Worker, &stackable_trino_crd::Container::Trino)
821+
.commands(&TrinoRole::Worker, &crate::crd::Container::Trino)
832822
.is_empty());
833823
assert!(auth_config_with_ldap_bind
834-
.commands(&TrinoRole::Worker, &stackable_trino_crd::Container::Trino)
824+
.commands(&TrinoRole::Worker, &crate::crd::Container::Trino)
835825
.is_empty());
836826

837827
// we expect 0 entries because no bind credentials env export
838828
assert_eq!(
839829
auth_config
840-
.commands(
841-
&TrinoRole::Coordinator,
842-
&stackable_trino_crd::Container::Trino
843-
)
830+
.commands(&TrinoRole::Coordinator, &crate::crd::Container::Trino)
844831
.len(),
845832
0
846833
);
847834

848835
// We expect 8 entries because of "set +x", "set -x" and 2x user:password bind credential env export
849836
assert_eq!(
850837
auth_config_with_ldap_bind
851-
.commands(
852-
&TrinoRole::Coordinator,
853-
&stackable_trino_crd::Container::Trino
854-
)
838+
.commands(&TrinoRole::Coordinator, &crate::crd::Container::Trino)
855839
.len(),
856840
8
857841
);

rust/operator-binary/src/authentication/oidc/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
44
use snafu::{ResultExt, Snafu};
55
use stackable_operator::commons::{authentication::oidc, tls_verification::TlsClientDetailsError};
6-
use stackable_trino_crd::{TrinoRole, STACKABLE_CLIENT_TLS_DIR};
76

8-
use crate::{authentication::TrinoAuthenticationConfig, command};
7+
use crate::{
8+
authentication::TrinoAuthenticationConfig,
9+
command,
10+
crd::{TrinoRole, STACKABLE_CLIENT_TLS_DIR},
11+
};
912

1013
// Trino properties
1114
const HTTP_SERVER_AUTHENTICATION_OAUTH2_CLIENT_ID: &str =
@@ -115,7 +118,7 @@ impl TrinoOidcAuthentication {
115118

116119
oauth2_authentication_config.add_env_vars(
117120
TrinoRole::Coordinator,
118-
stackable_trino_crd::Container::Trino,
121+
crate::crd::Container::Trino,
119122
oidc::AuthenticationProvider::client_credentials_env_var_mounts(
120123
authenticator.client_credentials_secret,
121124
),
@@ -159,12 +162,12 @@ impl TrinoOidcAuthentication {
159162
oauth2_authentication_config.add_volumes(tls_volumes);
160163
oauth2_authentication_config.add_volume_mounts(
161164
TrinoRole::Coordinator,
162-
stackable_trino_crd::Container::Prepare,
165+
crate::crd::Container::Prepare,
163166
tls_mounts.clone(),
164167
);
165168
oauth2_authentication_config.add_volume_mounts(
166169
TrinoRole::Worker,
167-
stackable_trino_crd::Container::Prepare,
170+
crate::crd::Container::Prepare,
168171
tls_mounts,
169172
);
170173

@@ -178,7 +181,7 @@ impl TrinoOidcAuthentication {
178181
if let Some(path) = authenticator.oidc.tls.tls_ca_cert_mount_path() {
179182
oauth2_authentication_config.add_commands(
180183
TrinoRole::Coordinator,
181-
stackable_trino_crd::Container::Prepare,
184+
crate::crd::Container::Prepare,
182185
command::add_cert_to_truststore(&path, STACKABLE_CLIENT_TLS_DIR, "oidc-idp"),
183186
);
184187
}
@@ -210,9 +213,9 @@ mod tests {
210213
use std::mem;
211214

212215
use rstest::rstest;
213-
use stackable_trino_crd::Container;
214216

215217
use super::*;
218+
use crate::crd::Container;
216219

217220
const IDP_PORT: u16 = 8080;
218221
const IDP_SCOPE_1: &str = "openid";

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,16 @@ pub fn build_password_file_update_container(
116116
resolved_product_image: &ResolvedProductImage,
117117
volume_mounts: Vec<VolumeMount>,
118118
) -> Result<Container, Error> {
119-
let mut cb_pw_file_updater =
120-
ContainerBuilder::new(&stackable_trino_crd::Container::PasswordFileUpdater.to_string())
121-
.expect(
122-
"Invalid container name. This should not happen, as the container name is fixed",
123-
);
119+
let mut cb_pw_file_updater = ContainerBuilder::new(
120+
&crate::crd::Container::PasswordFileUpdater.to_string(),
121+
)
122+
.expect("Invalid container name. This should not happen, as the container name is fixed");
124123

125124
let mut commands = vec![];
126125

127126
commands.push(product_logging::framework::capture_shell_output(
128127
STACKABLE_LOG_DIR,
129-
&stackable_trino_crd::Container::PasswordFileUpdater.to_string(),
128+
&crate::crd::Container::PasswordFileUpdater.to_string(),
130129
// we do not access any of the crd config options for this and just log it to file
131130
&AutomaticContainerLogConfig::default(),
132131
));

0 commit comments

Comments
 (0)