Skip to content

Commit f79ea92

Browse files
committed
refactor: use v2 ConfigMapName, SecretName, ListenerName
1 parent 6050b18 commit f79ea92

7 files changed

Lines changed: 53 additions & 25 deletions

File tree

extra/crds.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ spec:
5757
properties:
5858
serverSecretClass:
5959
description: Name of the SecretClass which will provide TLS certificates for the OPA server.
60+
maxLength: 253
61+
minLength: 1
62+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
6063
type: string
6164
required:
6265
- serverSecretClass
@@ -94,6 +97,9 @@ spec:
9497
permissions `User.ReadAll` and `GroupMemberShip.ReadAll`.
9598
9699
Must contain the fields `clientId` and `clientSecret`.
100+
maxLength: 253
101+
minLength: 1
102+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
97103
type: string
98104
port:
99105
description: Port of the identity provider. If TLS is used defaults to `443`, otherwise to `80`.
@@ -191,6 +197,9 @@ spec:
191197
type: object
192198
kerberosSecretClassName:
193199
description: The name of the Kerberos SecretClass.
200+
maxLength: 253
201+
minLength: 1
202+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
194203
type: string
195204
ldapServer:
196205
description: Hostname of the domain controller, e.g. `ad-ds-1.contoso.com`.
@@ -422,6 +431,9 @@ spec:
422431
Name of a Secret that contains client credentials of a Keycloak account with permission to read user metadata.
423432
424433
Must contain the fields `clientId` and `clientSecret`.
434+
maxLength: 253
435+
minLength: 1
436+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
425437
type: string
426438
hostname:
427439
description: Hostname of the identity provider, e.g. `my.keycloak.corp`.
@@ -510,7 +522,10 @@ spec:
510522
description: |-
511523
Name of the Vector aggregator discovery ConfigMap.
512524
It must contain the key `ADDRESS` with the address of the Vector aggregator.
525+
maxLength: 253
526+
minLength: 1
513527
nullable: true
528+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
514529
type: string
515530
type: object
516531
clusterOperation:
@@ -1834,6 +1849,9 @@ spec:
18341849
properties:
18351850
serverSecretClass:
18361851
description: Name of the SecretClass which will provide TLS certificates for the OPA server.
1852+
maxLength: 253
1853+
minLength: 1
1854+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
18371855
type: string
18381856
required:
18391857
- serverSecretClass
@@ -1886,6 +1904,9 @@ spec:
18861904
type: object
18871905
kerberosSecretClassName:
18881906
description: The name of the Kerberos SecretClass.
1907+
maxLength: 253
1908+
minLength: 1
1909+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
18891910
type: string
18901911
ldapServer:
18911912
description: Hostname of the domain controller, e.g. `ad-ds-1.contoso.com`.
@@ -1949,6 +1970,9 @@ spec:
19491970
permissions `User.ReadAll` and `GroupMemberShip.ReadAll`.
19501971
19511972
Must contain the fields `clientId` and `clientSecret`.
1973+
maxLength: 253
1974+
minLength: 1
1975+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
19521976
type: string
19531977
port:
19541978
description: Port of the identity provider. If TLS is used defaults to `443`, otherwise to `80`.
@@ -2199,6 +2223,9 @@ spec:
21992223
Name of a Secret that contains client credentials of a Keycloak account with permission to read user metadata.
22002224
22012225
Must contain the fields `clientId` and `clientSecret`.
2226+
maxLength: 253
2227+
minLength: 1
2228+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
22022229
type: string
22032230
hostname:
22042231
description: Hostname of the identity provider, e.g. `my.keycloak.corp`.
@@ -2287,7 +2314,10 @@ spec:
22872314
description: |-
22882315
Name of the Vector aggregator discovery ConfigMap.
22892316
It must contain the key `ADDRESS` with the address of the Vector aggregator.
2317+
maxLength: 253
2318+
minLength: 1
22902319
nullable: true
2320+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
22912321
type: string
22922322
type: object
22932323
clusterOperation:

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub fn build_server_rolegroup_daemonset(
413413
VolumeBuilder::new(TLS_VOLUME_NAME.as_ref())
414414
.ephemeral(
415415
SecretOperatorVolumeSourceBuilder::new(
416-
&tls.server_secret_class,
416+
tls.server_secret_class.to_string(),
417417
// OPA needs the full TLS keypair (public cert + private key) to serve HTTPS.
418418
SecretClassVolumeProvisionParts::PublicPrivate,
419419
)
@@ -466,7 +466,7 @@ pub fn build_server_rolegroup_daemonset(
466466
user_info_fetcher::v1alpha2::Backend::ActiveDirectory(ad) => {
467467
pb.add_volume(
468468
SecretClassVolume::new(
469-
ad.kerberos_secret_class_name.clone(),
469+
ad.kerberos_secret_class_name.to_string(),
470470
Some(SecretClassVolumeScope {
471471
pod: false,
472472
node: false,
@@ -505,7 +505,7 @@ pub fn build_server_rolegroup_daemonset(
505505
pb.add_volume(
506506
VolumeBuilder::new(USER_INFO_FETCHER_CREDENTIALS_VOLUME_NAME.as_ref())
507507
.secret(SecretVolumeSource {
508-
secret_name: Some(keycloak.client_credentials_secret.clone()),
508+
secret_name: Some(keycloak.client_credentials_secret.to_string()),
509509
..Default::default()
510510
})
511511
.build(),
@@ -526,7 +526,7 @@ pub fn build_server_rolegroup_daemonset(
526526
pb.add_volume(
527527
VolumeBuilder::new(USER_INFO_FETCHER_CREDENTIALS_VOLUME_NAME.as_ref())
528528
.secret(SecretVolumeSource {
529-
secret_name: Some(entra.client_credentials_secret.clone()),
529+
secret_name: Some(entra.client_credentials_secret.to_string()),
530530
..Default::default()
531531
})
532532
.build(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn build_discovery_config_map(
5959
cm_builder.metadata(metadata).add_data("OPA", url);
6060

6161
if let Some(tls) = &cluster.cluster_config.tls {
62-
cm_builder.add_data("OPA_SECRET_CLASS", &tls.server_secret_class);
62+
cm_builder.add_data("OPA_SECRET_CLASS", tls.server_secret_class.to_string());
6363
}
6464

6565
cm_builder.build().context(BuildConfigMapSnafu)

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ pub enum Error {
7676
"the Vector agent is enabled but no Vector aggregator discovery ConfigMap name is set"
7777
))]
7878
MissingVectorAggregatorConfigMapName,
79-
80-
#[snafu(display("the Vector aggregator discovery ConfigMap name is invalid"))]
81-
ParseVectorAggregatorConfigMapName {
82-
source: stackable_operator::v2::macros::attributed_string_type::Error,
83-
},
8479
}
8580

8681
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -144,16 +139,14 @@ pub fn validate(
144139
)
145140
.context(ResolveProductImageSnafu)?;
146141

147-
// The Vector aggregator discovery ConfigMap name (validated here so an invalid name fails
148-
// up-front). It is only required when the Vector agent is enabled for a role group.
142+
// The Vector aggregator discovery ConfigMap name. Validated at deserialization by the
143+
// `ConfigMapName` newtype on the CRD field. It is only required when the Vector agent is
144+
// enabled for a role group.
149145
let vector_aggregator_config_map_name = opa
150146
.spec
151147
.cluster_config
152148
.vector_aggregator_config_map_name
153-
.as_deref()
154-
.map(ConfigMapName::from_str)
155-
.transpose()
156-
.context(ParseVectorAggregatorConfigMapNameSnafu)?;
149+
.clone();
157150

158151
let mut role_group_configs = BTreeMap::new();
159152
for opa_role in OpaRole::iter() {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ use stackable_operator::{
1818
schemars::{self, JsonSchema},
1919
shared::time::Duration,
2020
status::condition::{ClusterCondition, HasStatusCondition},
21-
v2::{config_overrides::JsonOrKeyValueConfigOverrides, role_utils::GenericCommonConfig},
21+
v2::{
22+
config_overrides::JsonOrKeyValueConfigOverrides,
23+
role_utils::GenericCommonConfig,
24+
types::kubernetes::{ConfigMapName, SecretClassName},
25+
},
2226
versioned::versioned,
2327
};
2428
use strum::{Display, EnumIter, EnumString};
@@ -85,7 +89,7 @@ pub mod versioned {
8589
/// Name of the Vector aggregator discovery ConfigMap.
8690
/// It must contain the key `ADDRESS` with the address of the Vector aggregator.
8791
#[serde(skip_serializing_if = "Option::is_none")]
88-
pub vector_aggregator_config_map_name: Option<String>,
92+
pub vector_aggregator_config_map_name: Option<ConfigMapName>,
8993

9094
/// This field controls which type of Service the operator creates for this OpaCluster:
9195
///
@@ -125,7 +129,7 @@ pub mod versioned {
125129
#[serde(rename_all = "camelCase")]
126130
pub struct OpaTls {
127131
/// Name of the SecretClass which will provide TLS certificates for the OPA server.
128-
pub server_secret_class: String,
132+
pub server_secret_class: SecretClassName,
129133
}
130134

131135
// TODO: Temporary solution until listener-operator is finished

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use stackable_operator::{
99
},
1010
schemars::{self, JsonSchema},
1111
shared::time::Duration,
12+
v2::types::kubernetes::{SecretClassName, SecretName},
1213
versioned::versioned,
1314
};
1415

@@ -75,7 +76,7 @@ pub mod versioned {
7576
/// Name of a Secret that contains client credentials of a Keycloak account with permission to read user metadata.
7677
///
7778
/// Must contain the fields `clientId` and `clientSecret`.
78-
pub client_credentials_secret: String,
79+
pub client_credentials_secret: SecretName,
7980

8081
/// The Keycloak realm that OPA's Keycloak account (as specified by `credentialsSecretName` exists in).
8182
///
@@ -90,7 +91,7 @@ pub mod versioned {
9091
#[serde(rename_all = "camelCase")]
9192
pub struct AasBackend {
9293
/// Hostname of the identity provider, e.g. `my.aas.corp`.
93-
pub hostname: String,
94+
pub hostname: HostName,
9495

9596
/// Port of the identity provider. Defaults to port 5000.
9697
#[serde(default = "aas_default_port")]
@@ -101,13 +102,13 @@ pub mod versioned {
101102
#[serde(rename_all = "camelCase")]
102103
pub struct ActiveDirectoryBackend {
103104
/// Hostname of the domain controller, e.g. `ad-ds-1.contoso.com`.
104-
pub ldap_server: String,
105+
pub ldap_server: HostName,
105106

106107
/// The root Distinguished Name (DN) where users and groups are located.
107108
pub base_distinguished_name: String,
108109

109110
/// The name of the Kerberos SecretClass.
110-
pub kerberos_secret_class_name: String,
111+
pub kerberos_secret_class_name: SecretClassName,
111112

112113
/// Use a TLS connection. If not specified then no TLS will be used.
113114
#[serde(flatten)]
@@ -155,7 +156,7 @@ pub mod versioned {
155156
/// permissions `User.ReadAll` and `GroupMemberShip.ReadAll`.
156157
///
157158
/// Must contain the fields `clientId` and `clientSecret`.
158-
pub client_credentials_secret: String,
159+
pub client_credentials_secret: SecretName,
159160
}
160161

161162
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]

rust/user-info-fetcher/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async fn resolve_backend(
129129
Ok(ResolvedBackend::ExperimentalXfscAas(resolved))
130130
}
131131
v1alpha2::Backend::ActiveDirectory(config) => Ok(ResolvedBackend::ActiveDirectory {
132-
ldap_server: config.ldap_server,
132+
ldap_server: config.ldap_server.to_string(),
133133
tls: config.tls,
134134
base_distinguished_name: config.base_distinguished_name,
135135
custom_attribute_mappings: config.custom_attribute_mappings,

0 commit comments

Comments
 (0)