Skip to content

Commit 114343b

Browse files
committed
fix: move logic to tls module
1 parent b5d59f4 commit 114343b

File tree

4 files changed

+14
-124
lines changed

4 files changed

+14
-124
lines changed

docs/modules/secret-operator/pages/scope.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ For example, a TLS certificate provisioned by the xref:secretclass.adoc#backend-
5959
xref:#node[] and xref:#pod[] would contain the following values in its `subjectAlternateName` (SAN) extension field:
6060

6161
* The node's IP address
62-
* The node's fully qualified domain name (`my-node.example.com`, trailing dots are removed)
63-
* The pod's fully qualified domain name (`my-pod.my-service.my-namespace.svc.cluster.local`, trailing dots are removed)
62+
* The node's fully qualified domain name (`my-node.example.com`, without a trailing dot)
63+
* The pod's fully qualified domain name (`my-pod.my-service.my-namespace.svc.cluster.local`, without a trailing dot)

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

Lines changed: 3 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,11 @@ impl SecretVolumeSelector {
179179
scope: &scope::SecretScope,
180180
) -> Result<Vec<Address>, ScopeAddressesError> {
181181
use scope_addresses_error::*;
182-
// Turn FQDNs into bare domain names by removing the trailing dots
183-
let cluster_domain = pod_info.kubernetes_cluster_domain.trim_end_matches(".");
182+
let cluster_domain = &pod_info.kubernetes_cluster_domain;
184183
let namespace = &self.namespace;
185184
Ok(match scope {
186185
scope::SecretScope::Node => {
187-
let mut addrs = vec![Address::Dns(pod_info.node_name.trim_end_matches(".").to_owned())];
186+
let mut addrs = vec![Address::Dns(pod_info.node_name.clone())];
188187
addrs.extend(pod_info.node_ips.iter().copied().map(Address::Ip));
189188
addrs
190189
}
@@ -209,13 +208,7 @@ impl SecretVolumeSelector {
209208
.listener_addresses
210209
.get(name)
211210
.context(NoListenerAddressesSnafu { listener: name })?
212-
.iter()
213-
.map(|addr| match addr {
214-
// Turn FQDNs into bare domain names by removing the trailing dots
215-
Address::Dns(dns) => Address::Dns(dns.trim_end_matches(".").to_string()),
216-
_ => addr.clone(),
217-
})
218-
.collect(),
211+
.to_vec(),
219212
})
220213
}
221214

@@ -304,114 +297,3 @@ impl SecretBackendError for Infallible {
304297
match *self {}
305298
}
306299
}
307-
308-
#[cfg(test)]
309-
mod tests {
310-
use std::collections::HashMap;
311-
312-
use pod_info::PodInfo;
313-
314-
use super::*;
315-
316-
#[test]
317-
fn test_scope_addresses_without_trailing_dot() {
318-
let pod_info = construct_pod_info("cluster.local");
319-
320-
assert_eq!(
321-
calculate_scope(&pod_info, &SecretScope::Pod),
322-
vec![
323-
dns("my-sts.default.svc.cluster.local"),
324-
dns("my-sts-0.my-sts.default.svc.cluster.local"),
325-
ip("10.0.0.42"),
326-
]
327-
);
328-
329-
assert_eq!(
330-
calculate_scope(
331-
&pod_info,
332-
&SecretScope::Service {
333-
name: "my-service".to_owned()
334-
}
335-
),
336-
vec![dns("my-service.default.svc.cluster.local"),]
337-
);
338-
339-
assert_eq!(
340-
calculate_scope(&pod_info, &SecretScope::Node),
341-
vec![dns("my-node"), ip("192.168.0.1"),]
342-
);
343-
}
344-
345-
#[test]
346-
fn test_scope_addresses_with_trailing_dot() {
347-
let pod_info = construct_pod_info("custom.cluster.local.");
348-
349-
assert_eq!(
350-
calculate_scope(&pod_info, &SecretScope::Pod),
351-
vec![
352-
dns("my-sts.default.svc.custom.cluster.local"),
353-
dns("my-sts-0.my-sts.default.svc.custom.cluster.local"),
354-
ip("10.0.0.42"),
355-
]
356-
);
357-
358-
assert_eq!(
359-
calculate_scope(
360-
&pod_info,
361-
&SecretScope::Service {
362-
name: "my-service".to_owned()
363-
}
364-
),
365-
vec![
366-
dns("my-service.default.svc.custom.cluster.local")
367-
]
368-
);
369-
370-
assert_eq!(
371-
calculate_scope(&pod_info, &SecretScope::Node),
372-
vec![dns("my-node"), ip("192.168.0.1"),]
373-
);
374-
}
375-
376-
fn construct_pod_info(cluster_domain: &str) -> PodInfo {
377-
PodInfo {
378-
pod_ips: vec!["10.0.0.42".parse().unwrap()],
379-
service_name: Some("my-sts".to_owned()),
380-
node_name: "my-node".to_owned(),
381-
node_ips: vec!["192.168.0.1".parse().unwrap()],
382-
listener_addresses: HashMap::from([]),
383-
kubernetes_cluster_domain: cluster_domain.parse().unwrap(),
384-
scheduling: SchedulingPodInfo {
385-
namespace: "default".to_owned(),
386-
volume_listener_names: HashMap::new(),
387-
has_node_scope: false,
388-
},
389-
}
390-
}
391-
392-
fn calculate_scope(pod_info: &PodInfo, scope: &SecretScope) -> Vec<Address> {
393-
let secret_volume_selector = construct_secret_volume_selector();
394-
secret_volume_selector
395-
.scope_addresses(pod_info, scope)
396-
.unwrap()
397-
}
398-
399-
fn dns(dns: &str) -> Address {
400-
Address::Dns(dns.to_owned())
401-
}
402-
403-
fn ip(ip: &str) -> Address {
404-
Address::Ip(ip.parse().unwrap())
405-
}
406-
407-
fn construct_secret_volume_selector() -> SecretVolumeSelector {
408-
serde_yaml::from_str(
409-
r#"
410-
secrets.stackable.tech/class: tls
411-
csi.storage.k8s.io/pod.name: my-sts-0
412-
csi.storage.k8s.io/pod.namespace: default
413-
"#,
414-
)
415-
.unwrap()
416-
}
417-
}

rust/operator-binary/src/backend/pod_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl PodInfo {
175175
}
176176
}
177177

178-
#[derive(Debug, Clone, PartialEq)]
178+
#[derive(Debug, Clone)]
179179
pub enum Address {
180180
Dns(String),
181181
Ip(IpAddr),

rust/operator-binary/src/backend/tls/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ impl SecretBackend for TlsGenerate {
252252
.context(ScopeAddressesSnafu { scope })?,
253253
);
254254
}
255+
for address in &mut addresses {
256+
if let Address::Dns(dns) = address {
257+
// Turn FQDNs into bare domain names by removing the trailing dot
258+
if dns.ends_with('.') {
259+
dns.pop();
260+
}
261+
}
262+
}
255263
let ca = self
256264
.ca_manager
257265
.find_certificate_authority_for_signing(not_after)

0 commit comments

Comments
 (0)