Skip to content

Commit 126da64

Browse files
committed
refactor: switch to v2 ConfigMapName, SecretName, ListenerName in CRD
1 parent 285edd2 commit 126da64

9 files changed

Lines changed: 52 additions & 34 deletions

File tree

extra/crds.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ spec:
4040
properties:
4141
secretClass:
4242
description: Name of the SecretClass providing the keytab for the HBase services.
43+
maxLength: 253
44+
minLength: 1
45+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
4346
type: string
4447
required:
4548
- secretClass
@@ -84,6 +87,9 @@ spec:
8487
providing information about the HDFS cluster.
8588
See also the [Stackable Operator for HDFS](https://docs.stackable.tech/home/nightly/hdfs/) to learn
8689
more about setting up an HDFS cluster.
90+
maxLength: 253
91+
minLength: 1
92+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
8793
type: string
8894
required:
8995
- configMap
@@ -352,7 +358,10 @@ spec:
352358
It must contain the key `ADDRESS` with the address of the Vector aggregator.
353359
Follow the [logging tutorial](https://docs.stackable.tech/home/nightly/tutorials/logging-vector-aggregator)
354360
to learn how to configure log aggregation with Vector.
361+
maxLength: 253
362+
minLength: 1
355363
nullable: true
364+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
356365
type: string
357366
required:
358367
- metadataDatabase
@@ -872,6 +881,9 @@ spec:
872881
listenerClass:
873882
default: cluster-internal
874883
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose the metastore.
884+
maxLength: 253
885+
minLength: 1
886+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
875887
type: string
876888
podDisruptionBudget:
877889
default:

rust/operator-binary/src/controller.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use stackable_operator::{
4040
kvp::label::{recommended_labels, role_group_selector},
4141
role_group_utils::ResourceNames,
4242
types::{
43-
kubernetes::ListenerName,
43+
kubernetes::{ListenerClassName, ListenerName, SecretClassName},
4444
operator::{ControllerName, OperatorName, ProductName, ProductVersion, RoleName},
4545
},
4646
},
@@ -456,7 +456,7 @@ pub struct ValidatedClusterConfig {
456456
pub s3_connection_spec: Option<s3::v1alpha1::ConnectionSpec>,
457457
pub hive_opa_config: Option<HiveOpaConfig>,
458458
/// The Kerberos `SecretClass` name, if Kerberos is enabled.
459-
pub kerberos_secret_class: Option<String>,
459+
pub kerberos_secret_class: Option<SecretClassName>,
460460
/// Kerberos-related `hive-site.xml` entries (empty when Kerberos is disabled).
461461
pub kerberos_config: BTreeMap<String, String>,
462462
/// Whether a `core-site.xml` with `hadoop.security.authentication=kerberos` is
@@ -468,7 +468,7 @@ pub struct ValidatedClusterConfig {
468468
#[derive(Clone, Debug)]
469469
pub struct ValidatedRoleConfig {
470470
pub pdb: stackable_operator::commons::pdb::PdbConfig,
471-
pub listener_class: String,
471+
pub listener_class: ListenerClassName,
472472
}
473473

474474
pub async fn reconcile_hive(

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use std::collections::BTreeMap;
1+
use std::{collections::BTreeMap, str::FromStr};
22

33
use stackable_operator::{
44
client::Client,
55
commons::opa::{OpaApiVersion, OpaConfig},
66
k8s_openapi::api::core::v1::ConfigMap,
77
kube::ResourceExt,
8+
v2::types::kubernetes::VolumeName,
89
};
910

1011
use crate::crd::v1alpha1::HiveCluster;
@@ -33,7 +34,9 @@ const OPA_AUTHORIZATION_POLICY_URL_PARTITION: &str =
3334
"com.bosch.bdps.opa.authorization.policy.url.partition";
3435
const OPA_AUTHORIZATION_POLICY_URL_USER: &str = "com.bosch.bdps.opa.authorization.policy.url.user";
3536

36-
pub const OPA_TLS_VOLUME_NAME: &str = "opa-tls";
37+
// Typed name for the OPA TLS secret-operator volume, reusing the existing `"opa-tls"` string
38+
// value so the produced volume/mount name is unchanged.
39+
stackable_operator::constant!(pub(crate) OPA_TLS_VOLUME_NAME: VolumeName = "opa-tls");
3740

3841
pub struct HiveOpaConfig {
3942
/// Endpoint for OPA, e.g.
@@ -124,6 +127,6 @@ impl HiveOpaConfig {
124127
pub fn tls_ca_cert_mount_path(&self) -> Option<String> {
125128
self.tls_secret_class
126129
.as_ref()
127-
.map(|_| format!("/stackable/secrets/{OPA_TLS_VOLUME_NAME}"))
130+
.map(|_| format!("/stackable/secrets/{}", &*OPA_TLS_VOLUME_NAME))
128131
}
129132
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use snafu::{OptionExt, Snafu};
2-
use stackable_operator::crd::listener::v1alpha1::{Listener, ListenerPort, ListenerSpec};
2+
use stackable_operator::{
3+
crd::listener::v1alpha1::{Listener, ListenerPort, ListenerSpec},
4+
v2::types::kubernetes::ListenerClassName,
5+
};
36

47
use crate::{
58
controller::{ValidatedCluster, build::PLACEHOLDER_LISTENER_ROLE_GROUP},
@@ -53,7 +56,7 @@ pub fn build_listener_connection_string(
5356
pub fn build_role_listener(
5457
cluster: &ValidatedCluster,
5558
hive_role: &HiveRole,
56-
listener_class: &String,
59+
listener_class: &ListenerClassName,
5760
) -> Listener {
5861
// The role listener is a role-level (not role-group-level) object, so there is no real
5962
// role-group name; "none" is used as a placeholder for the recommended labels.
@@ -65,7 +68,7 @@ pub fn build_role_listener(
6568
.build();
6669

6770
let spec = ListenerSpec {
68-
class_name: Some(listener_class.to_owned()),
71+
class_name: Some(listener_class.to_string()),
6972
ports: Some(listener_ports()),
7073
..Default::default()
7174
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
209209
})
210210
{
211211
container_builder
212-
.add_volume_mount(OPA_TLS_VOLUME_NAME, &tls_mount_path)
212+
.add_volume_mount(&*OPA_TLS_VOLUME_NAME, &tls_mount_path)
213213
.context(AddVolumeMountSnafu)?;
214214

215-
let opa_tls_volume = VolumeBuilder::new(OPA_TLS_VOLUME_NAME)
215+
let opa_tls_volume = VolumeBuilder::new(&*OPA_TLS_VOLUME_NAME)
216216
.ephemeral(
217217
SecretOperatorVolumeSourceBuilder::new(
218218
tls_secret_class,

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ pub enum Error {
9191
"the Vector aggregator discovery ConfigMap name is required when the Vector agent is enabled"
9292
))]
9393
MissingVectorAggregatorConfigMapName,
94-
95-
#[snafu(display("invalid Vector aggregator discovery ConfigMap name"))]
96-
ParseVectorAggregatorConfigMapName {
97-
source: stackable_operator::v2::macros::attributed_string_type::Error,
98-
},
9994
}
10095

10196
/// Validated logging configuration for the Hive metastore and (optional) Vector container.
@@ -183,16 +178,13 @@ pub fn validate_cluster(
183178

184179
let default_config = MetaStoreConfig::default_config(name.as_ref(), &hive_role);
185180

186-
// The Vector aggregator discovery ConfigMap name (validated here so an invalid name fails
187-
// up-front). It is only required when the Vector agent is enabled for a role group.
181+
// The Vector aggregator discovery ConfigMap name. It is only required when the Vector agent is
182+
// enabled for a role group; validity is already enforced by the `ConfigMapName` type on the CRD.
188183
let vector_aggregator_config_map_name = hive
189184
.spec
190185
.cluster_config
191186
.vector_aggregator_config_map_name
192-
.as_deref()
193-
.map(ConfigMapName::from_str)
194-
.transpose()
195-
.context(ParseVectorAggregatorConfigMapNameSnafu)?;
187+
.clone();
196188

197189
let mut groups: BTreeMap<RoleGroupName, HiveRoleGroupConfig> = BTreeMap::new();
198190
for (rg_name, rg) in &role.role_groups {

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::str::FromStr;
2+
13
use databases::MetadataDatabaseConnection;
24
/// Re-export of the shared product-logging spec data types (test-only).
35
///
@@ -36,8 +38,12 @@ use stackable_operator::{
3638
shared::time::Duration,
3739
status::condition::{ClusterCondition, HasStatusCondition},
3840
v2::{
39-
config_overrides::KeyValueConfigOverrides, role_utils::JavaCommonConfig,
40-
types::common::Port,
41+
config_overrides::KeyValueConfigOverrides,
42+
role_utils::JavaCommonConfig,
43+
types::{
44+
common::Port,
45+
kubernetes::{ConfigMapName, ListenerClassName, SecretClassName},
46+
},
4147
},
4248
versioned::versioned,
4349
};
@@ -76,8 +82,9 @@ pub const STACKABLE_TRUST_STORE_PASSWORD: &str = "changeit";
7682
pub const DEFAULT_LISTENER_CLASS: &str = "cluster-internal";
7783

7884
// used by crds to define a default listener_class name
79-
pub fn metastore_default_listener_class() -> String {
80-
DEFAULT_LISTENER_CLASS.to_owned()
85+
pub fn metastore_default_listener_class() -> ListenerClassName {
86+
ListenerClassName::from_str(DEFAULT_LISTENER_CLASS)
87+
.expect("the default listener class is a valid listener class name")
8188
}
8289

8390
const DEFAULT_METASTORE_GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_minutes_unchecked(5);
@@ -154,7 +161,7 @@ pub mod versioned {
154161

155162
/// This field controls which [ListenerClass](DOCS_BASE_URL_PLACEHOLDER/listener-operator/listenerclass.html) is used to expose the metastore.
156163
#[serde(default = "metastore_default_listener_class")]
157-
pub listener_class: String,
164+
pub listener_class: ListenerClassName,
158165
}
159166

160167
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
@@ -185,7 +192,7 @@ pub mod versioned {
185192
/// Follow the [logging tutorial](DOCS_BASE_URL_PLACEHOLDER/tutorials/logging-vector-aggregator)
186193
/// to learn how to configure log aggregation with Vector.
187194
#[serde(skip_serializing_if = "Option::is_none")]
188-
pub vector_aggregator_config_map_name: Option<String>,
195+
pub vector_aggregator_config_map_name: Option<ConfigMapName>,
189196
}
190197

191198
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Merge, PartialEq, Serialize)]
@@ -228,7 +235,7 @@ impl v1alpha1::HiveCluster {
228235
self.kerberos_secret_class().is_some()
229236
}
230237

231-
pub fn kerberos_secret_class(&self) -> Option<String> {
238+
pub fn kerberos_secret_class(&self) -> Option<SecretClassName> {
232239
self.spec
233240
.cluster_config
234241
.authentication
@@ -253,7 +260,7 @@ pub struct HdfsConnection {
253260
/// providing information about the HDFS cluster.
254261
/// See also the [Stackable Operator for HDFS](DOCS_BASE_URL_PLACEHOLDER/hdfs/) to learn
255262
/// more about setting up an HDFS cluster.
256-
pub config_map: String,
263+
pub config_map: ConfigMapName,
257264
}
258265

259266
#[derive(Clone, Debug, Display, EnumString, EnumIter, Eq, Hash, Ord, PartialEq, PartialOrd)]

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use serde::{Deserialize, Serialize};
22
use stackable_operator::{
33
commons::opa::OpaConfig,
44
schemars::{self, JsonSchema},
5+
v2::types::kubernetes::SecretClassName,
56
};
67

7-
#[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
8+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
89
#[serde(rename_all = "camelCase")]
910
pub struct AuthenticationConfig {
1011
/// Kerberos configuration.
@@ -19,9 +20,9 @@ pub struct AuthorizationConfig {
1920
pub opa: Option<OpaConfig>,
2021
}
2122

22-
#[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
23+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
2324
#[serde(rename_all = "camelCase")]
2425
pub struct KerberosConfig {
2526
/// Name of the SecretClass providing the keytab for the HBase services.
26-
pub secret_class: String,
27+
pub secret_class: SecretClassName,
2728
}

rust/operator-binary/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn references_config_map(
196196
};
197197

198198
match &hive.spec.cluster_config.hdfs {
199-
Some(hdfs_connection) => hdfs_connection.config_map == config_map.name_any(),
199+
Some(hdfs_connection) => hdfs_connection.config_map.as_ref() == config_map.name_any(),
200200
None => false,
201201
}
202202
}

0 commit comments

Comments
 (0)