Skip to content

Commit 3f57fd1

Browse files
feat: Support regular expressions in attributed_string_type (#88)
* feat: Add min_length and regex to attributed_string_type * chore: Regenerate charts * feat: Replace is_config_map_key in attributed_string_type with regex * chore: Move macros and types to separate modules * test: Update the integration test for the attributed_string_type * chore: Regenerate charts * feat: Add type SecretName
1 parent e72ccce commit 3f57fd1

File tree

26 files changed

+1350
-938
lines changed

26 files changed

+1350
-938
lines changed

deploy/helm/opensearch-operator/crds/crds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ spec:
4141
maxLength: 253
4242
minLength: 1
4343
nullable: true
44+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
4445
type: string
4546
type: object
4647
clusterOperation:
@@ -191,6 +192,7 @@ spec:
191192
maxLength: 253
192193
minLength: 1
193194
nullable: true
195+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
194196
type: string
195197
logging:
196198
default:
@@ -539,6 +541,7 @@ spec:
539541
maxLength: 253
540542
minLength: 1
541543
nullable: true
544+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
542545
type: string
543546
logging:
544547
default:

rust/operator-binary/src/controller.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ use crate::{
3333
v1alpha1::{self},
3434
},
3535
framework::{
36-
ClusterName, ControllerName, HasName, HasUid, ListenerClassName, NameIsValidLabelValue,
37-
NamespaceName, OperatorName, ProductName, ProductVersion, RoleGroupName, RoleName, Uid,
36+
HasName, HasUid, NameIsValidLabelValue,
3837
product_logging::framework::{ValidatedContainerLogConfigChoice, VectorContainerLogConfig},
3938
role_utils::{GenericProductSpecificCommonConfig, RoleGroupConfig},
39+
types::{
40+
kubernetes::{ListenerClassName, NamespaceName, Uid},
41+
operator::{
42+
ClusterName, ControllerName, OperatorName, ProductName, ProductVersion,
43+
RoleGroupName, RoleName,
44+
},
45+
},
4046
},
4147
};
4248

@@ -380,10 +386,13 @@ mod tests {
380386
controller::{OpenSearchNodeResources, ValidatedOpenSearchConfig},
381387
crd::{NodeRoles, v1alpha1},
382388
framework::{
383-
ClusterName, ListenerClassName, NamespaceName, OperatorName, ProductVersion,
384-
RoleGroupName, builder::pod::container::EnvVarSet,
389+
builder::pod::container::EnvVarSet,
385390
product_logging::framework::ValidatedContainerLogConfigChoice,
386391
role_utils::GenericProductSpecificCommonConfig,
392+
types::{
393+
kubernetes::{ListenerClassName, NamespaceName},
394+
operator::{ClusterName, OperatorName, ProductVersion, RoleGroupName},
395+
},
387396
},
388397
};
389398

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ use stackable_operator::{
1010
use strum::{EnumDiscriminants, IntoStaticStr};
1111

1212
use super::{Applied, ContextNames, KubernetesResources, Prepared};
13-
use crate::framework::{ClusterName, NamespaceName, Uid, cluster_resources::cluster_resources_new};
13+
use crate::framework::{
14+
cluster_resources::cluster_resources_new,
15+
types::{
16+
kubernetes::{NamespaceName, Uid},
17+
operator::ClusterName,
18+
},
19+
};
1420

1521
#[derive(Snafu, Debug, EnumDiscriminants)]
1622
#[strum_discriminants(derive(IntoStaticStr))]

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,15 @@ mod tests {
7979
},
8080
crd::{NodeRoles, v1alpha1},
8181
framework::{
82-
ClusterName, ControllerName, ListenerClassName, NamespaceName, OperatorName,
83-
ProductName, ProductVersion, RoleGroupName, builder::pod::container::EnvVarSet,
82+
builder::pod::container::EnvVarSet,
8483
role_utils::GenericProductSpecificCommonConfig,
84+
types::{
85+
kubernetes::{ListenerClassName, NamespaceName},
86+
operator::{
87+
ClusterName, ControllerName, OperatorName, ProductName, ProductVersion,
88+
RoleGroupName,
89+
},
90+
},
8591
},
8692
};
8793

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use crate::{
1010
controller::OpenSearchRoleGroupConfig,
1111
crd::v1alpha1,
1212
framework::{
13-
RoleGroupName, ServiceName,
1413
builder::pod::container::{EnvVarName, EnvVarSet},
1514
role_group_utils,
15+
types::{kubernetes::ServiceName, operator::RoleGroupName},
1616
},
1717
};
1818

@@ -296,9 +296,12 @@ mod tests {
296296
controller::{ValidatedLogging, ValidatedOpenSearchConfig},
297297
crd::NodeRoles,
298298
framework::{
299-
ClusterName, ListenerClassName, NamespaceName, ProductVersion, RoleGroupName,
300299
product_logging::framework::ValidatedContainerLogConfigChoice,
301300
role_utils::GenericProductSpecificCommonConfig,
301+
types::{
302+
kubernetes::{ListenerClassName, NamespaceName},
303+
operator::{ClusterName, ProductVersion, RoleGroupName},
304+
},
302305
},
303306
};
304307

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,15 @@ mod tests {
241241
},
242242
crd::{NodeRoles, v1alpha1},
243243
framework::{
244-
ClusterName, ControllerName, ListenerClassName, NamespaceName, OperatorName,
245-
ProductName, ProductVersion, RoleGroupName, builder::pod::container::EnvVarSet,
244+
builder::pod::container::EnvVarSet,
246245
role_utils::GenericProductSpecificCommonConfig,
246+
types::{
247+
kubernetes::{ListenerClassName, NamespaceName},
248+
operator::{
249+
ClusterName, ControllerName, OperatorName, ProductName, ProductVersion,
250+
RoleGroupName,
251+
},
252+
},
247253
},
248254
};
249255

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use crate::{
4242
},
4343
crd::v1alpha1,
4444
framework::{
45-
PersistentVolumeClaimName, RoleGroupName, ServiceAccountName, ServiceName, VolumeName,
4645
builder::{
4746
meta::ownerreference_from_resource,
4847
pod::{
@@ -55,6 +54,10 @@ use crate::{
5554
STACKABLE_LOG_DIR, ValidatedContainerLogConfigChoice, vector_container,
5655
},
5756
role_group_utils::ResourceNames,
57+
types::{
58+
kubernetes::{PersistentVolumeClaimName, ServiceAccountName, ServiceName, VolumeName},
59+
operator::RoleGroupName,
60+
},
5861
},
5962
};
6063

@@ -663,11 +666,19 @@ mod tests {
663666
},
664667
crd::{NodeRoles, v1alpha1},
665668
framework::{
666-
ClusterName, ConfigMapName, ControllerName, ListenerClassName, NamespaceName,
667-
OperatorName, ProductName, ProductVersion, RoleGroupName, ServiceAccountName,
668-
ServiceName, builder::pod::container::EnvVarSet,
669+
builder::pod::container::EnvVarSet,
669670
product_logging::framework::VectorContainerLogConfig,
670671
role_utils::GenericProductSpecificCommonConfig,
672+
types::{
673+
kubernetes::{
674+
ConfigMapName, ListenerClassName, NamespaceName, ServiceAccountName,
675+
ServiceName,
676+
},
677+
operator::{
678+
ClusterName, ControllerName, OperatorName, ProductName, ProductVersion,
679+
RoleGroupName,
680+
},
681+
},
671682
},
672683
};
673684

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ use super::{
1818
use crate::{
1919
crd::v1alpha1::{self},
2020
framework::{
21-
ClusterName, ConfigMapName, NamespaceName, Uid,
2221
builder::pod::container::{EnvVarName, EnvVarSet},
2322
product_logging::framework::{
2423
VectorContainerLogConfig, validate_logging_configuration_for_container,
2524
},
2625
role_utils::{GenericProductSpecificCommonConfig, RoleGroupConfig, with_validated_config},
26+
types::{
27+
kubernetes::{ConfigMapName, NamespaceName, Uid},
28+
operator::ClusterName,
29+
},
2730
},
2831
};
2932

@@ -45,24 +48,34 @@ pub enum Error {
4548
GetVectorAggregatorConfigMapName {},
4649

4750
#[snafu(display("failed to set cluster name"))]
48-
ParseClusterName { source: crate::framework::Error },
51+
ParseClusterName {
52+
source: crate::framework::macros::attributed_string_type::Error,
53+
},
4954

5055
#[snafu(display("failed to set cluster namespace"))]
51-
ParseClusterNamespace { source: crate::framework::Error },
56+
ParseClusterNamespace {
57+
source: crate::framework::macros::attributed_string_type::Error,
58+
},
5259

5360
#[snafu(display("failed to set UID"))]
54-
ParseClusterUid { source: crate::framework::Error },
61+
ParseClusterUid {
62+
source: crate::framework::macros::attributed_string_type::Error,
63+
},
5564

5665
#[snafu(display("failed to parse environment variable"))]
5766
ParseEnvironmentVariable {
5867
source: crate::framework::builder::pod::container::Error,
5968
},
6069

6170
#[snafu(display("failed to set product version"))]
62-
ParseProductVersion { source: crate::framework::Error },
71+
ParseProductVersion {
72+
source: crate::framework::macros::attributed_string_type::Error,
73+
},
6374

6475
#[snafu(display("failed to set role-group name"))]
65-
ParseRoleGroupName { source: crate::framework::Error },
76+
ParseRoleGroupName {
77+
source: crate::framework::macros::attributed_string_type::Error,
78+
},
6679

6780
#[snafu(display("failed to resolve product image"))]
6881
ResolveProductImage {
@@ -277,13 +290,18 @@ mod tests {
277290
v1alpha1::{self},
278291
},
279292
framework::{
280-
ClusterName, ConfigMapName, ControllerName, ListenerClassName, NamespaceName,
281-
OperatorName, ProductName, ProductVersion, RoleGroupName,
282293
builder::pod::container::{EnvVarName, EnvVarSet},
283294
product_logging::framework::{
284295
ValidatedContainerLogConfigChoice, VectorContainerLogConfig,
285296
},
286297
role_utils::{GenericProductSpecificCommonConfig, RoleGroupConfig},
298+
types::{
299+
kubernetes::{ConfigMapName, ListenerClassName, NamespaceName},
300+
operator::{
301+
ClusterName, ControllerName, OperatorName, ProductName, ProductVersion,
302+
RoleGroupName,
303+
},
304+
},
287305
},
288306
};
289307

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ use strum::{Display, EnumIter};
2929
use crate::{
3030
constant,
3131
framework::{
32-
ClusterName, ConfigMapName, ContainerName, ListenerClassName, NameIsValidLabelValue,
33-
ProductName, RoleName, role_utils::GenericProductSpecificCommonConfig,
32+
NameIsValidLabelValue,
33+
role_utils::GenericProductSpecificCommonConfig,
34+
types::{
35+
kubernetes::{ConfigMapName, ContainerName, ListenerClassName},
36+
operator::{ClusterName, ProductName, RoleName},
37+
},
3438
},
3539
};
3640

0 commit comments

Comments
 (0)