Skip to content

Commit 89dafb2

Browse files
committed
refactor: use v2 ConfigMapName, SecretName, ListenerName in CRD
1 parent e40a044 commit 89dafb2

8 files changed

Lines changed: 90 additions & 44 deletions

File tree

extra/crds.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,19 @@ spec:
4242
properties:
4343
secretClass:
4444
description: Name of the SecretClass providing the keytab for the HBase services.
45+
maxLength: 253
46+
minLength: 1
47+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
4548
type: string
4649
required:
4750
- secretClass
4851
type: object
4952
tlsSecretClass:
5053
default: tls
5154
description: Name of the SecretClass providing the tls certificates for the WebUIs.
55+
maxLength: 253
56+
minLength: 1
57+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
5258
type: string
5359
required:
5460
- kerberos
@@ -82,19 +88,28 @@ spec:
8288
description: |-
8389
Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery)
8490
for an HDFS cluster.
91+
maxLength: 253
92+
minLength: 1
93+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
8594
type: string
8695
vectorAggregatorConfigMapName:
8796
description: |-
8897
Name of the Vector aggregator [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery).
8998
It must contain the key `ADDRESS` with the address of the Vector aggregator.
9099
Follow the [logging tutorial](https://docs.stackable.tech/home/nightly/tutorials/logging-vector-aggregator)
91100
to learn how to configure log aggregation with Vector.
101+
maxLength: 253
102+
minLength: 1
92103
nullable: true
104+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
93105
type: string
94106
zookeeperConfigMapName:
95107
description: |-
96108
Name of the [discovery ConfigMap](https://docs.stackable.tech/home/nightly/concepts/service_discovery)
97109
for a ZooKeeper cluster.
110+
maxLength: 253
111+
minLength: 1
112+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
98113
type: string
99114
required:
100115
- hdfsConfigMapName
@@ -247,7 +262,10 @@ spec:
247262
type: string
248263
listenerClass:
249264
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose this rolegroup.
265+
maxLength: 253
266+
minLength: 1
250267
nullable: true
268+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
251269
type: string
252270
logging:
253271
default:
@@ -668,7 +686,10 @@ spec:
668686
type: string
669687
listenerClass:
670688
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose this rolegroup.
689+
maxLength: 253
690+
minLength: 1
671691
nullable: true
692+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
672693
type: string
673694
logging:
674695
default:
@@ -1075,7 +1096,10 @@ spec:
10751096
type: string
10761097
listenerClass:
10771098
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose this rolegroup.
1099+
maxLength: 253
1100+
minLength: 1
10781101
nullable: true
1102+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
10791103
type: string
10801104
logging:
10811105
default:
@@ -1531,7 +1555,10 @@ spec:
15311555
type: string
15321556
listenerClass:
15331557
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose this rolegroup.
1558+
maxLength: 253
1559+
minLength: 1
15341560
nullable: true
1561+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
15351562
type: string
15361563
logging:
15371564
default:
@@ -1961,7 +1988,10 @@ spec:
19611988
type: string
19621989
listenerClass:
19631990
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose this rolegroup.
1991+
maxLength: 253
1992+
minLength: 1
19641993
nullable: true
1994+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
19651995
type: string
19661996
logging:
19671997
default:
@@ -2382,7 +2412,10 @@ spec:
23822412
type: string
23832413
listenerClass:
23842414
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose this rolegroup.
2415+
maxLength: 253
2416+
minLength: 1
23852417
nullable: true
2418+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
23862419
type: string
23872420
logging:
23882421
default:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn build_rolegroup_statefulset(
234234
.add_volume(Volume {
235235
name: HDFS_DISCOVERY_VOLUME_NAME.to_string(),
236236
config_map: Some(ConfigMapVolumeSource {
237-
name: cluster.cluster_config.hdfs_config_map_name.clone(),
237+
name: cluster.cluster_config.hdfs_config_map_name.to_string(),
238238
..Default::default()
239239
}),
240240
..Default::default()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use stackable_operator::{
1919
kvp::label::{recommended_labels, role_group_selector},
2020
role_group_utils::ResourceNames,
2121
types::{
22-
kubernetes::{NamespaceName, Uid},
22+
kubernetes::{ConfigMapName, NamespaceName, SecretClassName, Uid},
2323
operator::{
2424
ClusterName, ControllerName, OperatorName, ProductName, ProductVersion, RoleName,
2525
},
@@ -248,11 +248,11 @@ pub struct ValidatedClusterConfig {
248248
/// Whether HTTPS is enabled (a TLS `SecretClass` was configured).
249249
pub https_enabled: bool,
250250
/// The Kerberos `SecretClass` name, if Kerberos is enabled.
251-
pub kerberos_secret_class: Option<String>,
251+
pub kerberos_secret_class: Option<SecretClassName>,
252252
/// The HTTPS/TLS `SecretClass` name, if HTTPS is enabled.
253-
pub https_secret_class: Option<String>,
253+
pub https_secret_class: Option<SecretClassName>,
254254
/// The HDFS discovery ConfigMap name the cluster connects to.
255-
pub hdfs_config_map_name: String,
255+
pub hdfs_config_map_name: ConfigMapName,
256256
// Pre-resolved kerberos properties for hbase-site.xml (empty when kerberos is disabled).
257257
pub hbase_site_kerberos_config: BTreeMap<String, String>,
258258
// Pre-resolved kerberos properties for the discovery `hbase-site.xml` exposed to clients

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ pub enum Error {
8484
"the Vector aggregator discovery ConfigMap name is required when the Vector agent is enabled"
8585
))]
8686
MissingVectorAggregatorConfigMapName,
87-
88-
#[snafu(display("invalid Vector aggregator discovery ConfigMap name"))]
89-
ParseVectorAggregatorConfigMapName {
90-
source: stackable_operator::v2::macros::attributed_string_type::Error,
91-
},
9287
}
9388

9489
/// Validated logging configuration for the HBase and (optional) Vector container.
@@ -149,19 +144,17 @@ pub fn validate_cluster(
149144
let mut role_groups = BTreeMap::new();
150145
let mut role_configs = BTreeMap::new();
151146

152-
let hdfs_discovery_cm_name = &hbase.spec.cluster_config.hdfs_config_map_name;
147+
let hdfs_discovery_cm_name = hbase.spec.cluster_config.hdfs_config_map_name.as_ref();
153148
let cluster_name = hbase.name_any();
154149

155-
// The Vector aggregator discovery ConfigMap name (validated here so an invalid name fails
156-
// up-front). It is only required when the Vector agent is enabled for a role group.
150+
// The Vector aggregator discovery ConfigMap name. It is validated already at deserialize time
151+
// (it is a `ConfigMapName`), and only required when the Vector agent is enabled for a role
152+
// group.
157153
let vector_aggregator_config_map_name = hbase
158154
.spec
159155
.cluster_config
160156
.vector_aggregator_config_map_name
161-
.as_deref()
162-
.map(ConfigMapName::from_str)
163-
.transpose()
164-
.context(ParseVectorAggregatorConfigMapNameSnafu)?;
157+
.clone();
165158

166159
for hbase_role in HbaseRole::iter() {
167160
let group_configs = match hbase_role {
@@ -412,7 +405,7 @@ spec:
412405
let default_config = HbaseConfigFragment::default_config(
413406
&HbaseRole::Master,
414407
&hbase.name_any(),
415-
&hbase.spec.cluster_config.hdfs_config_map_name,
408+
hbase.spec.cluster_config.hdfs_config_map_name.as_ref(),
416409
);
417410

418411
let validated = with_validated_config::<

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl ZookeeperConnectionInformation {
7272
let zk_discovery_cm_name = &hbase.spec.cluster_config.zookeeper_config_map_name;
7373
let mut zk_discovery_cm = client
7474
.get::<ConfigMap>(
75-
zk_discovery_cm_name,
75+
zk_discovery_cm_name.as_ref(),
7676
hbase
7777
.namespace()
7878
.as_deref()
@@ -88,28 +88,28 @@ impl ZookeeperConnectionInformation {
8888
.as_mut()
8989
.and_then(|data| data.remove(ZOOKEEPER_DISCOVERY_CM_HOSTS_ENTRY))
9090
.context(MissingConfigMapEntrySnafu {
91-
cm_name: zk_discovery_cm_name.as_str(),
91+
cm_name: zk_discovery_cm_name.to_string(),
9292
entry: ZOOKEEPER_DISCOVERY_CM_HOSTS_ENTRY,
9393
})?;
9494
let mut chroot = zk_discovery_cm
9595
.data
9696
.as_mut()
9797
.and_then(|data| data.remove(ZOOKEEPER_DISCOVERY_CM_CHROOT_ENTRY))
9898
.context(MissingConfigMapEntrySnafu {
99-
cm_name: zk_discovery_cm_name.as_str(),
99+
cm_name: zk_discovery_cm_name.to_string(),
100100
entry: ZOOKEEPER_DISCOVERY_CM_CHROOT_ENTRY,
101101
})?;
102102
let port = zk_discovery_cm
103103
.data
104104
.as_mut()
105105
.and_then(|data| data.remove(ZOOKEEPER_DISCOVERY_CM_CLIENT_PORT_ENTRY))
106106
.context(MissingConfigMapEntrySnafu {
107-
cm_name: zk_discovery_cm_name.as_str(),
107+
cm_name: zk_discovery_cm_name.to_string(),
108108
entry: ZOOKEEPER_DISCOVERY_CM_CLIENT_PORT_ENTRY,
109109
})?
110110
.parse()
111111
.context(ParseZookeeperPortSnafu {
112-
cm_name: zk_discovery_cm_name.as_str(),
112+
cm_name: zk_discovery_cm_name.to_string(),
113113
entry: ZOOKEEPER_DISCOVERY_CM_CLIENT_PORT_ENTRY,
114114
})?;
115115

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::str::FromStr;
2+
13
use security::AuthenticationConfig;
24
use serde::{Deserialize, Serialize};
35
use stackable_operator::{
@@ -22,7 +24,11 @@ use stackable_operator::{
2224
schemars::{self, JsonSchema},
2325
shared::time::Duration,
2426
status::condition::{ClusterCondition, HasStatusCondition},
25-
v2::{config_overrides::KeyValueConfigOverrides, role_utils::JavaCommonConfig},
27+
v2::{
28+
config_overrides::KeyValueConfigOverrides,
29+
role_utils::JavaCommonConfig,
30+
types::kubernetes::{ConfigMapName, ListenerClassName, SecretClassName},
31+
},
2632
versioned::versioned,
2733
};
2834
use strum::{Display, EnumIter, EnumString};
@@ -140,23 +146,23 @@ pub mod versioned {
140146
pub rest_servers: Option<RestServerRoleType>,
141147
}
142148

143-
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
149+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
144150
#[serde(rename_all = "camelCase")]
145151
pub struct HbaseClusterConfig {
146152
/// Name of the [discovery ConfigMap](DOCS_BASE_URL_PLACEHOLDER/concepts/service_discovery)
147153
/// for an HDFS cluster.
148-
pub hdfs_config_map_name: String,
154+
pub hdfs_config_map_name: ConfigMapName,
149155

150156
/// Name of the Vector aggregator [discovery ConfigMap](DOCS_BASE_URL_PLACEHOLDER/concepts/service_discovery).
151157
/// It must contain the key `ADDRESS` with the address of the Vector aggregator.
152158
/// Follow the [logging tutorial](DOCS_BASE_URL_PLACEHOLDER/tutorials/logging-vector-aggregator)
153159
/// to learn how to configure log aggregation with Vector.
154160
#[serde(skip_serializing_if = "Option::is_none")]
155-
pub vector_aggregator_config_map_name: Option<String>,
161+
pub vector_aggregator_config_map_name: Option<ConfigMapName>,
156162

157163
/// Name of the [discovery ConfigMap](DOCS_BASE_URL_PLACEHOLDER/concepts/service_discovery)
158164
/// for a ZooKeeper cluster.
159-
pub zookeeper_config_map_name: String,
165+
pub zookeeper_config_map_name: ConfigMapName,
160166

161167
/// Settings related to user [authentication](DOCS_BASE_URL_PLACEHOLDER/usage-guide/security).
162168
pub authentication: Option<AuthenticationConfig>,
@@ -207,7 +213,7 @@ impl v1alpha1::HbaseCluster {
207213
self.kerberos_secret_class().is_some()
208214
}
209215

210-
pub fn kerberos_secret_class(&self) -> Option<String> {
216+
pub fn kerberos_secret_class(&self) -> Option<SecretClassName> {
211217
self.spec
212218
.cluster_config
213219
.authentication
@@ -220,7 +226,7 @@ impl v1alpha1::HbaseCluster {
220226
self.https_secret_class().is_some()
221227
}
222228

223-
pub fn https_secret_class(&self) -> Option<String> {
229+
pub fn https_secret_class(&self) -> Option<SecretClassName> {
224230
self.spec
225231
.cluster_config
226232
.authentication
@@ -332,7 +338,10 @@ impl HbaseConfigFragment {
332338
affinity: get_affinity(cluster_name, role, hdfs_discovery_cm_name),
333339
graceful_shutdown_timeout: Some(graceful_shutdown_timeout),
334340
requested_secret_lifetime: Some(requested_secret_lifetime),
335-
listener_class: Some(DEFAULT_LISTENER_CLASS.to_string()),
341+
listener_class: Some(
342+
ListenerClassName::from_str(DEFAULT_LISTENER_CLASS)
343+
.expect("DEFAULT_LISTENER_CLASS is a valid listener class name"),
344+
),
336345
}
337346
}
338347
}
@@ -359,7 +368,10 @@ impl RegionServerConfigFragment {
359368
cli_opts: None,
360369
},
361370
requested_secret_lifetime: Some(HbaseRole::DEFAULT_REGION_SECRET_LIFETIME),
362-
listener_class: Some(DEFAULT_LISTENER_CLASS.to_string()),
371+
listener_class: Some(
372+
ListenerClassName::from_str(DEFAULT_LISTENER_CLASS)
373+
.expect("DEFAULT_LISTENER_CLASS is a valid listener class name"),
374+
),
363375
}
364376
}
365377
}
@@ -401,7 +413,7 @@ pub enum Container {
401413
Vector,
402414
}
403415

404-
#[derive(Clone, Debug, Default, Fragment, JsonSchema, PartialEq)]
416+
#[derive(Clone, Debug, Fragment, JsonSchema, PartialEq)]
405417
#[fragment_attrs(
406418
derive(
407419
Clone,
@@ -439,7 +451,7 @@ pub struct HbaseConfig {
439451
pub requested_secret_lifetime: Option<Duration>,
440452

441453
/// This field controls which [ListenerClass](DOCS_BASE_URL_PLACEHOLDER/listener-operator/listenerclass.html) is used to expose this rolegroup.
442-
pub listener_class: String,
454+
pub listener_class: ListenerClassName,
443455
}
444456

445457
#[derive(Fragment, Clone, Debug, JsonSchema, PartialEq, Serialize, Deserialize)]
@@ -524,7 +536,7 @@ pub struct RegionServerConfig {
524536
pub region_mover: RegionMover,
525537

526538
/// This field controls which [ListenerClass](DOCS_BASE_URL_PLACEHOLDER/listener-operator/listenerclass.html) is used to expose this rolegroup.
527-
pub listener_class: String,
539+
pub listener_class: ListenerClassName,
528540
}
529541

530542
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
@@ -582,7 +594,7 @@ impl AnyServiceConfig {
582594
}
583595
}
584596

585-
pub fn listener_class(&self) -> String {
597+
pub fn listener_class(&self) -> ListenerClassName {
586598
match self {
587599
AnyServiceConfig::Master(config) => config.listener_class.clone(),
588600
AnyServiceConfig::RegionServer(config) => config.listener_class.clone(),

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1+
use std::str::FromStr;
2+
13
use serde::{Deserialize, Serialize};
24
use stackable_operator::{
35
commons::opa::OpaConfig,
46
schemars::{self, JsonSchema},
7+
v2::types::kubernetes::SecretClassName,
58
};
69

7-
#[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
10+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
811
#[serde(rename_all = "camelCase")]
912
pub struct AuthenticationConfig {
1013
/// Name of the SecretClass providing the tls certificates for the WebUIs.
1114
#[serde(default = "default_tls_secret_class")]
12-
pub tls_secret_class: String,
15+
pub tls_secret_class: SecretClassName,
1316

1417
/// Kerberos configuration.
1518
pub kerberos: KerberosConfig,
1619
}
1720

18-
fn default_tls_secret_class() -> String {
19-
"tls".to_string()
21+
fn default_tls_secret_class() -> SecretClassName {
22+
SecretClassName::from_str("tls").expect("\"tls\" is a valid secret class name")
2023
}
2124

22-
#[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
25+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
2326
#[serde(rename_all = "camelCase")]
2427
pub struct KerberosConfig {
2528
/// Name of the SecretClass providing the keytab for the HBase services.
26-
pub secret_class: String,
29+
pub secret_class: SecretClassName,
2730
}
2831
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
2932
#[serde(rename_all = "camelCase")]

0 commit comments

Comments
 (0)