Skip to content

Commit 6e604b5

Browse files
committed
chore: version the crd
1 parent 81bd43a commit 6e604b5

File tree

10 files changed

+305
-287
lines changed

10 files changed

+305
-287
lines changed

rust/operator-binary/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use stackable_operator::commons::authentication::{ldap, oidc};
66

77
use crate::crd::{
88
authentication::{
9-
FlaskRolesSyncMoment, SupersetAuthenticationClassResolved,
9+
v1alpha1::FlaskRolesSyncMoment, SupersetAuthenticationClassResolved,
1010
SupersetClientAuthenticationDetailsResolved, DEFAULT_OIDC_PROVIDER,
1111
},
1212
SupersetConfigOptions,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod tests {
3232
};
3333

3434
use super::*;
35-
use crate::crd::SupersetCluster;
35+
use crate::crd::v1alpha1::SupersetCluster;
3636

3737
#[test]
3838
fn test_affinity_defaults() {

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

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use stackable_operator::{
1111
},
1212
schemars::{self, JsonSchema},
1313
};
14+
use stackable_versioned::versioned;
1415
use tracing::info;
1516

1617
// The assumed OIDC provider if no hint is given in the AuthClass
@@ -88,33 +89,36 @@ pub enum Error {
8889

8990
type Result<T, E = Error> = std::result::Result<T, E>;
9091

91-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
92-
#[serde(rename_all = "camelCase")]
93-
pub struct SupersetClientAuthenticationDetails {
94-
#[serde(flatten)]
95-
pub common: ClientAuthenticationDetails<()>,
96-
97-
/// Allow users who are not already in the FAB DB.
98-
/// Gets mapped to `AUTH_USER_REGISTRATION`
99-
#[serde(default = "default_user_registration")]
100-
pub user_registration: bool,
101-
102-
/// This role will be given in addition to any AUTH_ROLES_MAPPING.
103-
/// Gets mapped to `AUTH_USER_REGISTRATION_ROLE`
104-
#[serde(default = "default_user_registration_role")]
105-
pub user_registration_role: String,
106-
107-
/// If we should replace ALL the user's roles each login, or only on registration.
108-
/// Gets mapped to `AUTH_ROLES_SYNC_AT_LOGIN`
109-
#[serde(default)]
110-
pub sync_roles_at: FlaskRolesSyncMoment,
111-
}
92+
#[versioned(version(name = "v1alpha1"))]
93+
pub mod versioned {
94+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
95+
#[serde(rename_all = "camelCase")]
96+
pub struct SupersetClientAuthenticationDetails {
97+
#[serde(flatten)]
98+
pub common: ClientAuthenticationDetails<()>,
99+
100+
/// Allow users who are not already in the FAB DB.
101+
/// Gets mapped to `AUTH_USER_REGISTRATION`
102+
#[serde(default = "default_user_registration")]
103+
pub user_registration: bool,
104+
105+
/// This role will be given in addition to any AUTH_ROLES_MAPPING.
106+
/// Gets mapped to `AUTH_USER_REGISTRATION_ROLE`
107+
#[serde(default = "default_user_registration_role")]
108+
pub user_registration_role: String,
109+
110+
/// If we should replace ALL the user's roles each login, or only on registration.
111+
/// Gets mapped to `AUTH_ROLES_SYNC_AT_LOGIN`
112+
#[serde(default)]
113+
pub sync_roles_at: FlaskRolesSyncMoment,
114+
}
112115

113-
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
114-
pub enum FlaskRolesSyncMoment {
115-
#[default]
116-
Registration,
117-
Login,
116+
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
117+
pub enum FlaskRolesSyncMoment {
118+
#[default]
119+
Registration,
120+
Login,
121+
}
118122
}
119123

120124
/// Resolved and validated counter part for `SupersetClientAuthenticationDetails`.
@@ -123,7 +127,7 @@ pub struct SupersetClientAuthenticationDetailsResolved {
123127
pub authentication_classes_resolved: Vec<SupersetAuthenticationClassResolved>,
124128
pub user_registration: bool,
125129
pub user_registration_role: String,
126-
pub sync_roles_at: FlaskRolesSyncMoment,
130+
pub sync_roles_at: v1alpha1::FlaskRolesSyncMoment,
127131
}
128132

129133
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -147,7 +151,7 @@ pub fn default_user_registration_role() -> String {
147151

148152
impl SupersetClientAuthenticationDetailsResolved {
149153
pub async fn from(
150-
auth_details: &[SupersetClientAuthenticationDetails],
154+
auth_details: &[v1alpha1::SupersetClientAuthenticationDetails],
151155
client: &Client,
152156
) -> Result<SupersetClientAuthenticationDetailsResolved> {
153157
let resolve_auth_class = |auth_details: ClientAuthenticationDetails| async move {
@@ -157,7 +161,7 @@ impl SupersetClientAuthenticationDetailsResolved {
157161
}
158162

159163
pub async fn resolve<R>(
160-
auth_details: &[SupersetClientAuthenticationDetails],
164+
auth_details: &[v1alpha1::SupersetClientAuthenticationDetails],
161165
resolve_auth_class: impl Fn(ClientAuthenticationDetails) -> R,
162166
) -> Result<SupersetClientAuthenticationDetailsResolved>
163167
where
@@ -264,14 +268,14 @@ impl SupersetClientAuthenticationDetailsResolved {
264268
user_registration: user_registration.unwrap_or_else(default_user_registration),
265269
user_registration_role: user_registration_role
266270
.unwrap_or_else(default_user_registration_role),
267-
sync_roles_at: sync_roles_at.unwrap_or_else(FlaskRolesSyncMoment::default),
271+
sync_roles_at: sync_roles_at.unwrap_or_else(v1alpha1::FlaskRolesSyncMoment::default),
268272
})
269273
}
270274

271275
fn from_oidc(
272276
auth_class_name: &str,
273277
provider: &oidc::AuthenticationProvider,
274-
auth_details: &SupersetClientAuthenticationDetails,
278+
auth_details: &v1alpha1::SupersetClientAuthenticationDetails,
275279
) -> Result<SupersetAuthenticationClassResolved> {
276280
let oidc_provider = match &provider.provider_hint {
277281
None => {
@@ -346,7 +350,7 @@ mod tests {
346350
authentication_classes_resolved: Vec::default(),
347351
user_registration: default_user_registration(),
348352
user_registration_role: default_user_registration_role(),
349-
sync_roles_at: FlaskRolesSyncMoment::default()
353+
sync_roles_at: v1alpha1::FlaskRolesSyncMoment::default()
350354
},
351355
auth_details_resolved
352356
);
@@ -383,7 +387,7 @@ mod tests {
383387
}],
384388
user_registration: false,
385389
user_registration_role: "Gamma".into(),
386-
sync_roles_at: FlaskRolesSyncMoment::Login
390+
sync_roles_at: v1alpha1::FlaskRolesSyncMoment::Login
387391
},
388392
auth_details_resolved
389393
);
@@ -495,7 +499,7 @@ mod tests {
495499
],
496500
user_registration: false,
497501
user_registration_role: "Gamma".into(),
498-
sync_roles_at: FlaskRolesSyncMoment::Login
502+
sync_roles_at: v1alpha1::FlaskRolesSyncMoment::Login
499503
},
500504
auth_details_resolved
501505
);
@@ -901,7 +905,7 @@ mod tests {
901905
/// Fail if the given string cannot be deserialized.
902906
fn deserialize_superset_client_authentication_details(
903907
input: &str,
904-
) -> Vec<SupersetClientAuthenticationDetails> {
908+
) -> Vec<v1alpha1::SupersetClientAuthenticationDetails> {
905909
serde_yaml::from_str(input)
906910
.expect("The definition of the authentication configuration should be valid.")
907911
}

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

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use stackable_operator::{
55
kube::{CustomResource, ResourceExt},
66
schemars::{self, JsonSchema},
77
};
8+
use stackable_versioned::versioned;
89

910
#[derive(Snafu, Debug)]
1011
#[allow(clippy::enum_variant_names)]
@@ -14,48 +15,58 @@ pub enum Error {
1415
}
1516
type Result<T, E = Error> = std::result::Result<T, E>;
1617

17-
/// The DruidConnection resource can be used to automatically deploy a Druid datasource in Superset.
18-
/// Learn more about it in the [Superset operator usage guide](DOCS_BASE_URL_PLACEHOLDER/superset/usage-guide/connecting-druid).
19-
#[derive(Clone, CustomResource, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
20-
#[kube(
21-
group = "superset.stackable.tech",
22-
version = "v1alpha1",
23-
kind = "DruidConnection",
24-
plural = "druidconnections",
25-
status = "DruidConnectionStatus",
26-
namespaced,
27-
crates(
28-
kube_core = "stackable_operator::kube::core",
29-
k8s_openapi = "stackable_operator::k8s_openapi",
30-
schemars = "stackable_operator::schemars"
31-
)
32-
)]
33-
#[serde(rename_all = "camelCase")]
34-
pub struct DruidConnectionSpec {
35-
/// The Superset to connect.
36-
pub superset: ClusterRef,
37-
/// The Druid to connect.
38-
pub druid: ClusterRef,
39-
}
18+
#[versioned(version(name = "v1alpha1"))]
19+
pub mod versioned {
20+
/// The DruidConnection resource can be used to automatically deploy a Druid datasource in Superset.
21+
/// Learn more about it in the [Superset operator usage guide](DOCS_BASE_URL_PLACEHOLDER/superset/usage-guide/connecting-druid).
22+
#[derive(Clone, CustomResource, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
23+
#[versioned(k8s(
24+
group = "superset.stackable.tech",
25+
kind = "DruidConnection",
26+
plural = "druidconnections",
27+
status = "DruidConnectionStatus",
28+
namespaced,
29+
crates(
30+
kube_core = "stackable_operator::kube::core",
31+
k8s_openapi = "stackable_operator::k8s_openapi",
32+
schemars = "stackable_operator::schemars"
33+
)
34+
))]
35+
#[serde(rename_all = "camelCase")]
36+
pub struct DruidConnectionSpec {
37+
/// The Superset to connect.
38+
pub superset: ClusterRef,
39+
/// The Druid to connect.
40+
pub druid: ClusterRef,
41+
}
4042

41-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
42-
#[serde(rename_all = "camelCase")]
43-
pub struct ClusterRef {
44-
/// The name of the stacklet.
45-
pub name: String,
46-
/// The namespace. Defaults to the namespace of the `DruidConnection` if it is not specified.
47-
pub namespace: Option<String>,
48-
}
43+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
44+
#[serde(rename_all = "camelCase")]
45+
pub struct ClusterRef {
46+
/// The name of the stacklet.
47+
pub name: String,
48+
/// The namespace. Defaults to the namespace of the `DruidConnection` if it is not specified.
49+
pub namespace: Option<String>,
50+
}
4951

50-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)]
51-
#[serde(rename_all = "camelCase")]
52-
pub struct DruidConnectionStatus {
53-
#[serde(skip_serializing_if = "Option::is_none")]
54-
pub started_at: Option<Time>,
55-
pub condition: DruidConnectionStatusCondition,
52+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)]
53+
#[serde(rename_all = "camelCase")]
54+
pub struct DruidConnectionStatus {
55+
#[serde(skip_serializing_if = "Option::is_none")]
56+
pub started_at: Option<Time>,
57+
pub condition: DruidConnectionStatusCondition,
58+
}
59+
60+
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
61+
pub enum DruidConnectionStatusCondition {
62+
Pending,
63+
Importing,
64+
Ready,
65+
Failed,
66+
}
5667
}
5768

58-
impl DruidConnection {
69+
impl v1alpha1::DruidConnection {
5970
pub fn job_name(&self) -> String {
6071
format!("{}-import", self.name_unchecked())
6172
}
@@ -95,43 +106,35 @@ impl DruidConnection {
95106
}
96107
}
97108

98-
impl DruidConnectionStatus {
109+
impl v1alpha1::DruidConnectionStatus {
99110
pub fn new() -> Self {
100111
Self {
101112
started_at: Some(Time(Utc::now())),
102-
condition: DruidConnectionStatusCondition::Pending,
113+
condition: v1alpha1::DruidConnectionStatusCondition::Pending,
103114
}
104115
}
105116

106117
pub fn importing(&self) -> Self {
107118
let mut new = self.clone();
108-
new.condition = DruidConnectionStatusCondition::Importing;
119+
new.condition = v1alpha1::DruidConnectionStatusCondition::Importing;
109120
new
110121
}
111122

112123
pub fn ready(&self) -> Self {
113124
let mut new = self.clone();
114-
new.condition = DruidConnectionStatusCondition::Ready;
125+
new.condition = v1alpha1::DruidConnectionStatusCondition::Ready;
115126
new
116127
}
117128

118129
pub fn failed(&self) -> Self {
119130
let mut new = self.clone();
120-
new.condition = DruidConnectionStatusCondition::Failed;
131+
new.condition = v1alpha1::DruidConnectionStatusCondition::Failed;
121132
new
122133
}
123134
}
124135

125-
impl Default for DruidConnectionStatus {
136+
impl Default for v1alpha1::DruidConnectionStatus {
126137
fn default() -> Self {
127138
Self::new()
128139
}
129140
}
130-
131-
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
132-
pub enum DruidConnectionStatusCondition {
133-
Pending,
134-
Importing,
135-
Ready,
136-
Failed,
137-
}

0 commit comments

Comments
 (0)