Skip to content

Commit c6cefe5

Browse files
committed
refactor: use SecretName, ListenerName, ConfigMapName
1 parent 093c3fa commit c6cefe5

8 files changed

Lines changed: 74 additions & 37 deletions

File tree

extra/crds.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ spec:
354354
properties:
355355
configMap:
356356
description: Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) providing information about the HDFS cluster.
357+
maxLength: 253
358+
minLength: 1
359+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
357360
type: string
358361
required:
359362
- configMap
@@ -638,6 +641,9 @@ spec:
638641
properties:
639642
configMap:
640643
description: Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) providing information about the HDFS cluster.
644+
maxLength: 253
645+
minLength: 1
646+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
641647
type: string
642648
required:
643649
- configMap
@@ -898,7 +904,10 @@ spec:
898904
This setting controls:
899905
- Which cert the servers should use to authenticate themselves against other servers
900906
- Which ca.crt to use when validating the other server
907+
maxLength: 253
908+
minLength: 1
901909
nullable: true
910+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
902911
type: string
903912
serverSecretClass:
904913
default: tls
@@ -907,7 +916,10 @@ spec:
907916
This setting controls:
908917
- If TLS encryption is used at all
909918
- Which cert the servers should use to authenticate themselves against the client
919+
maxLength: 253
920+
minLength: 1
910921
nullable: true
922+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
911923
type: string
912924
type: object
913925
vectorAggregatorConfigMapName:
@@ -916,7 +928,10 @@ spec:
916928
It must contain the key `ADDRESS` with the address of the Vector aggregator.
917929
Follow the [logging tutorial](https://docs.stackable.tech/home/nightly/tutorials/logging-vector-aggregator)
918930
to learn how to configure log aggregation with Vector.
931+
maxLength: 253
932+
minLength: 1
919933
nullable: true
934+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
920935
type: string
921936
required:
922937
- catalogLabelSelector
@@ -1529,6 +1544,9 @@ spec:
15291544
listenerClass:
15301545
default: cluster-internal
15311546
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose the coordinator.
1547+
maxLength: 253
1548+
minLength: 1
1549+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
15321550
type: string
15331551
podDisruptionBudget:
15341552
default:
@@ -3517,6 +3535,9 @@ spec:
35173535
properties:
35183536
configMap:
35193537
description: Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) providing information about the HDFS cluster.
3538+
maxLength: 253
3539+
minLength: 1
3540+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
35203541
type: string
35213542
required:
35223543
- configMap
@@ -3526,6 +3547,9 @@ spec:
35263547
properties:
35273548
configMap:
35283549
description: Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) providing information about the Hive metastore.
3550+
maxLength: 253
3551+
minLength: 1
3552+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
35293553
type: string
35303554
required:
35313555
- configMap
@@ -3787,6 +3811,9 @@ spec:
37873811
properties:
37883812
configMap:
37893813
description: Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) providing information about the HDFS cluster.
3814+
maxLength: 253
3815+
minLength: 1
3816+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
37903817
type: string
37913818
required:
37923819
- configMap
@@ -3796,6 +3823,9 @@ spec:
37963823
properties:
37973824
configMap:
37983825
description: Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) providing information about the Hive metastore.
3826+
maxLength: 253
3827+
minLength: 1
3828+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
37993829
type: string
38003830
required:
38013831
- configMap
@@ -3966,6 +3996,9 @@ spec:
39663996
properties:
39673997
configMap:
39683998
description: Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) providing information about the HDFS cluster.
3999+
maxLength: 253
4000+
minLength: 1
4001+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
39694002
type: string
39704003
required:
39714004
- configMap
@@ -3980,6 +4013,9 @@ spec:
39804013
properties:
39814014
configMap:
39824015
description: Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery) providing information about the Hive metastore.
4016+
maxLength: 253
4017+
minLength: 1
4018+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
39834019
type: string
39844020
required:
39854021
- configMap

rust/operator-binary/src/catalog/commons.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl ExtendCatalogConfig for MetastoreConnection {
3737
_trino_version: u16,
3838
) -> Result<(), FromTrinoCatalogError> {
3939
let hive_cm: ConfigMap = client
40-
.get(&self.config_map, catalog_namespace.as_ref())
40+
.get(self.config_map.as_ref(), catalog_namespace.as_ref())
4141
.await
4242
.with_context(|_| FailedToGetDiscoveryConfigMapSnafu {
4343
catalog: catalog_name.to_string(),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ pub fn build_group_listener(
3232
recommended_labels: Labels,
3333
listener_class: String,
3434
listener_group_name: String,
35-
) -> Result<Listener, Error> {
36-
Ok(Listener {
35+
) -> Listener {
36+
Listener {
3737
metadata: ObjectMetaBuilder::new()
3838
.name_and_namespace(cluster)
3939
.name(listener_group_name)
@@ -46,7 +46,7 @@ pub fn build_group_listener(
4646
..ListenerSpec::default()
4747
},
4848
status: None,
49-
})
49+
}
5050
}
5151

5252
pub fn build_group_listener_pvc(

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ pub enum Error {
9898
"the Vector aggregator discovery ConfigMap name is required when the Vector agent is enabled"
9999
))]
100100
MissingVectorAggregatorConfigMapName,
101-
102-
#[snafu(display("invalid Vector aggregator discovery ConfigMap name"))]
103-
ParseVectorAggregatorConfigMapName {
104-
source: stackable_operator::v2::macros::attributed_string_type::Error,
105-
},
106101
}
107102

108103
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -208,10 +203,7 @@ pub fn validate(
208203
.spec
209204
.cluster_config
210205
.vector_aggregator_config_map_name
211-
.as_deref()
212-
.map(ConfigMapName::from_str)
213-
.transpose()
214-
.context(ParseVectorAggregatorConfigMapNameSnafu)?;
206+
.clone();
215207

216208
let mut role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>> =
217209
BTreeMap::new();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn get_affinity(
3939
.map(|hive_cluster_name| {
4040
affinity_between_role_pods(
4141
"hive",
42-
hive_cluster_name, // The discovery cm has the same name as the HiveCluster itself
42+
hive_cluster_name.as_ref(), // The discovery cm has the same name as the HiveCluster itself
4343
"metastore",
4444
50,
4545
)
@@ -67,7 +67,7 @@ pub fn get_affinity(
6767
.map(|hdfs_cluster_name| {
6868
affinity_between_role_pods(
6969
"hdfs",
70-
hdfs_cluster_name, // The discovery cm has the same name as the HdfsCluster itself
70+
hdfs_cluster_name.as_ref(), // The discovery cm has the same name as the HdfsCluster itself
7171
"datanode",
7272
50,
7373
)
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
use serde::{Deserialize, Serialize};
2-
use stackable_operator::schemars::{self, JsonSchema};
2+
use stackable_operator::{
3+
schemars::{self, JsonSchema},
4+
v2::types::kubernetes::ConfigMapName,
5+
};
36

47
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
58
#[serde(rename_all = "camelCase")]
69
pub struct MetastoreConnection {
710
/// Name of the [discovery ConfigMap](DOCS_BASE_URL_PLACEHOLDER/concepts/service_discovery) providing information about the Hive metastore.
8-
pub config_map: String,
11+
pub config_map: ConfigMapName,
912
}
1013

1114
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
1215
#[serde(rename_all = "camelCase")]
1316
pub struct HdfsConnection {
1417
/// Name of the [discovery ConfigMap](DOCS_BASE_URL_PLACEHOLDER/concepts/service_discovery) providing information about the HDFS cluster.
15-
pub config_map: String,
18+
pub config_map: ConfigMapName,
1619
}

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use stackable_operator::{
3737
role_group_utils::ResourceNames,
3838
role_utils::JavaCommonConfig,
3939
types::{
40-
kubernetes::NamespaceName,
40+
kubernetes::{ConfigMapName, ListenerClassName, NamespaceName, SecretClassName},
4141
operator::{ClusterName, RoleGroupName, RoleName},
4242
},
4343
},
@@ -174,7 +174,7 @@ pub mod versioned {
174174

175175
/// This field controls which [ListenerClass](DOCS_BASE_URL_PLACEHOLDER/listener-operator/listenerclass.html) is used to expose the coordinator.
176176
#[serde(default = "coordinator_default_listener_class")]
177-
pub listener_class: String,
177+
pub listener_class: ListenerClassName,
178178
}
179179

180180
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Merge, PartialEq, Serialize)]
@@ -292,7 +292,7 @@ pub mod versioned {
292292
/// Follow the [logging tutorial](DOCS_BASE_URL_PLACEHOLDER/tutorials/logging-vector-aggregator)
293293
/// to learn how to configure log aggregation with Vector.
294294
#[serde(skip_serializing_if = "Option::is_none")]
295-
pub vector_aggregator_config_map_name: Option<String>,
295+
pub vector_aggregator_config_map_name: Option<ConfigMapName>,
296296
}
297297

298298
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
@@ -328,7 +328,7 @@ pub mod versioned {
328328
default = "tls_secret_class_default",
329329
skip_serializing_if = "Option::is_none"
330330
)]
331-
pub server_secret_class: Option<String>,
331+
pub server_secret_class: Option<SecretClassName>,
332332
/// Only affects internal communication. Use mutual verification between Trino nodes
333333
/// This setting controls:
334334
/// - Which cert the servers should use to authenticate themselves against other servers
@@ -337,7 +337,7 @@ pub mod versioned {
337337
default = "tls_secret_class_default",
338338
skip_serializing_if = "Option::is_none"
339339
)]
340-
pub internal_secret_class: Option<String>,
340+
pub internal_secret_class: Option<SecretClassName>,
341341
}
342342

343343
#[derive(Clone, Debug, Default, JsonSchema, PartialEq, Fragment)]
@@ -379,8 +379,9 @@ impl Default for v1alpha1::TrinoCoordinatorRoleConfig {
379379
}
380380
}
381381

382-
fn coordinator_default_listener_class() -> String {
383-
"cluster-internal".to_string()
382+
fn coordinator_default_listener_class() -> ListenerClassName {
383+
ListenerClassName::from_str("cluster-internal")
384+
.expect("the default listener class name must be valid")
384385
}
385386

386387
impl Default for v1alpha1::TrinoTls {
@@ -392,8 +393,11 @@ impl Default for v1alpha1::TrinoTls {
392393
}
393394
}
394395

395-
fn tls_secret_class_default() -> Option<String> {
396-
Some(TLS_DEFAULT_SECRET_CLASS.to_string())
396+
fn tls_secret_class_default() -> Option<SecretClassName> {
397+
Some(
398+
SecretClassName::from_str(TLS_DEFAULT_SECRET_CLASS)
399+
.expect("the default TLS SecretClass name must be valid"),
400+
)
397401
}
398402

399403
#[derive(
@@ -419,7 +423,7 @@ pub enum TrinoRole {
419423
}
420424

421425
impl TrinoRole {
422-
pub fn listener_class_name(&self, trino: &v1alpha1::TrinoCluster) -> Option<String> {
426+
pub fn listener_class_name(&self, trino: &v1alpha1::TrinoCluster) -> Option<ListenerClassName> {
423427
match self {
424428
Self::Coordinator => trino
425429
.spec
@@ -606,7 +610,11 @@ impl v1alpha1::TrinoCluster {
606610
/// Return user provided server TLS settings
607611
pub fn get_server_tls(&self) -> Option<&str> {
608612
let spec: &v1alpha1::TrinoClusterSpec = &self.spec;
609-
spec.cluster_config.tls.server_secret_class.as_deref()
613+
spec.cluster_config
614+
.tls
615+
.server_secret_class
616+
.as_ref()
617+
.map(|secret_class| secret_class.as_ref())
610618
}
611619

612620
/// Return if client TLS should be set depending on settings for authentication and client TLS.
@@ -617,7 +625,11 @@ impl v1alpha1::TrinoCluster {
617625
/// Return user provided internal TLS settings.
618626
pub fn get_internal_tls(&self) -> Option<&str> {
619627
let spec: &v1alpha1::TrinoClusterSpec = &self.spec;
620-
spec.cluster_config.tls.internal_secret_class.as_deref()
628+
spec.cluster_config
629+
.tls
630+
.internal_secret_class
631+
.as_ref()
632+
.map(|secret_class| secret_class.as_ref())
621633
}
622634
}
623635

rust/operator-binary/src/trino_controller.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ pub enum Error {
150150
source: stackable_operator::cluster_resources::Error,
151151
},
152152

153-
#[snafu(display("failed to configure listener"))]
154-
ListenerConfiguration {
155-
source: build::resource::listener::Error,
156-
},
157-
158153
#[snafu(display("failed to create internal secret"))]
159154
CreateInternalSecret {
160155
source: random_secret_creation::Error,
@@ -369,8 +364,7 @@ pub async fn reconcile_trino(
369364
validated_cluster.recommended_labels(trino_role, "none"),
370365
listener_class.to_string(),
371366
listener_group_name,
372-
)
373-
.context(ListenerConfigurationSnafu)?;
367+
);
374368

375369
cluster_resources
376370
.add(client, role_group_listener)

0 commit comments

Comments
 (0)