Skip to content

Commit

Permalink
Put ClusterInfo in PodInfo
Browse files Browse the repository at this point in the history
Co-authored-by: Natalie Klestrup Röijezon <[email protected]>
  • Loading branch information
sbernauer and nightkr committed Oct 24, 2024
1 parent 93526f4 commit f8e01c5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 26 deletions.
4 changes: 1 addition & 3 deletions rust/operator-binary/src/backend/cert_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use stackable_operator::{
k8s_openapi::{api::core::v1::Secret, ByteString},
kube::{api::ObjectMeta, runtime::reflector::ObjectRef},
time::Duration,
utils::cluster_info::KubernetesClusterInfo,
};

use crate::{crd::CertManagerIssuer, external_crd, format::SecretData, utils::Unloggable};
Expand Down Expand Up @@ -84,7 +83,6 @@ impl SecretBackend for CertManager {

async fn get_secret_data(
&self,
cluster_info: &KubernetesClusterInfo,
selector: &SecretVolumeSelector,
pod_info: PodInfo,
) -> Result<SecretContents, Self::Error> {
Expand All @@ -97,7 +95,7 @@ impl SecretBackend for CertManager {
let mut ip_addresses = Vec::new();
for scope in &selector.scope {
for address in selector
.scope_addresses(cluster_info, &pod_info, scope)
.scope_addresses(&pod_info, scope)
.context(ScopeAddressesSnafu { scope })?
{
match address {
Expand Down
7 changes: 2 additions & 5 deletions rust/operator-binary/src/backend/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use std::{

use async_trait::async_trait;
use snafu::{ResultExt, Snafu};
use stackable_operator::{
kube::runtime::reflector::ObjectRef, utils::cluster_info::KubernetesClusterInfo,
};
use stackable_operator::kube::runtime::reflector::ObjectRef;

use crate::{
crd::{self, SecretClass},
Expand Down Expand Up @@ -60,12 +58,11 @@ impl<B: SecretBackend + Send + Sync> SecretBackend for DynamicAdapter<B> {

async fn get_secret_data(
&self,
cluster_info: &KubernetesClusterInfo,
selector: &super::SecretVolumeSelector,
pod_info: PodInfo,
) -> Result<super::SecretContents, Self::Error> {
self.0
.get_secret_data(cluster_info, selector, pod_info)
.get_secret_data(selector, pod_info)
.await
.map_err(|err| DynError(Box::new(err)))
}
Expand Down
2 changes: 0 additions & 2 deletions rust/operator-binary/src/backend/k8s_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use stackable_operator::{
},
kube::api::ListParams,
kvp::{LabelError, LabelSelectorExt, Labels},
utils::cluster_info::KubernetesClusterInfo,
};

use crate::{crd::SearchNamespace, format::SecretData, utils::Unloggable};
Expand Down Expand Up @@ -83,7 +82,6 @@ impl SecretBackend for K8sSearch {

async fn get_secret_data(
&self,
_cluster_info: &KubernetesClusterInfo,
selector: &SecretVolumeSelector,
pod_info: PodInfo,
) -> Result<SecretContents, Self::Error> {
Expand Down
17 changes: 10 additions & 7 deletions rust/operator-binary/src/backend/kerberos_keytab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub struct KerberosKeytab {
profile: KerberosProfile,
admin_keytab: Unloggable<Vec<u8>>,
admin_principal: KerberosPrincipal,
kubernetes_cluster_info: KubernetesClusterInfo,
}

impl KerberosKeytab {
Expand Down Expand Up @@ -127,6 +128,7 @@ impl KerberosKeytab {
profile,
admin_keytab: Unloggable(admin_keytab),
admin_principal,
kubernetes_cluster_info: client.kubernetes_cluster_info.clone(),
})
}
}
Expand All @@ -137,7 +139,6 @@ impl SecretBackend for KerberosKeytab {

async fn get_secret_data(
&self,
cluster_info: &KubernetesClusterInfo,
selector: &super::SecretVolumeSelector,
pod_info: super::pod_info::PodInfo,
) -> Result<super::SecretContents, Self::Error> {
Expand All @@ -150,6 +151,7 @@ impl SecretBackend for KerberosKeytab {
},
admin_keytab,
admin_principal,
kubernetes_cluster_info,
} = self;

let admin_server_clause = match admin {
Expand Down Expand Up @@ -203,11 +205,12 @@ cluster.local = {realm_name}
let mut pod_principals: Vec<KerberosPrincipal> = Vec::new();
for service_name in &selector.kerberos_service_names {
for scope in &selector.scope {
for addr in selector
.scope_addresses(cluster_info, &pod_info, scope)
.context(ScopeAddressesSnafu {
scope: scope.clone(),
})?
for addr in
selector
.scope_addresses(&pod_info, scope)
.context(ScopeAddressesSnafu {
scope: scope.clone(),
})?
{
if let Address::Dns(hostname) = addr {
pod_principals.push(
Expand Down Expand Up @@ -262,7 +265,7 @@ cluster.local = {realm_name}
},
},
},
cluster_info,
kubernetes_cluster_info,
)
.await
.context(ProvisionKeytabSnafu)?;
Expand Down
5 changes: 1 addition & 4 deletions rust/operator-binary/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use snafu::{OptionExt, Snafu};
use stackable_operator::{
k8s_openapi::chrono::{DateTime, FixedOffset},
time::Duration,
utils::cluster_info::KubernetesClusterInfo,
};
use std::{collections::HashSet, convert::Infallible, fmt::Debug};

Expand Down Expand Up @@ -178,12 +177,11 @@ impl SecretVolumeSelector {
/// Returns all addresses associated with a certain [`SecretScope`]
fn scope_addresses<'a>(
&'a self,
cluster_info: &KubernetesClusterInfo,
pod_info: &'a pod_info::PodInfo,
scope: &scope::SecretScope,
) -> Result<Vec<Address>, ScopeAddressesError> {
use scope_addresses_error::*;
let cluster_domain = &cluster_info.cluster_domain;
let cluster_domain = &pod_info.kubernetes_cluster_domain;
let namespace = &self.namespace;
Ok(match scope {
scope::SecretScope::Node => {
Expand Down Expand Up @@ -272,7 +270,6 @@ pub trait SecretBackend: Debug + Send + Sync {
/// Provision or load secret data from the source.
async fn get_secret_data(
&self,
cluster_info: &KubernetesClusterInfo,
selector: &SecretVolumeSelector,
pod_info: pod_info::PodInfo,
) -> Result<SecretContents, Self::Error>;
Expand Down
7 changes: 6 additions & 1 deletion rust/operator-binary/src/backend/pod_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use std::{
use futures::{StreamExt, TryStreamExt};
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::{
commons::listener::{AddressType, Listener, ListenerClass, PodListeners, ServiceType},
commons::{
listener::{AddressType, Listener, ListenerClass, PodListeners, ServiceType},
networking::DomainName,
},
k8s_openapi::api::core::v1::{Node, PersistentVolumeClaim, Pod},
kube::runtime::reflector::ObjectRef,
};
Expand Down Expand Up @@ -108,6 +111,7 @@ pub struct PodInfo {
pub node_name: String,
pub node_ips: Vec<IpAddr>,
pub listener_addresses: HashMap<String, Vec<Address>>,
pub kubernetes_cluster_domain: DomainName,
pub scheduling: SchedulingPodInfo,
}

Expand Down Expand Up @@ -166,6 +170,7 @@ impl PodInfo {
})
.collect::<Result<_, _>>()?,
listener_addresses,
kubernetes_cluster_domain: client.kubernetes_cluster_info.cluster_domain.clone(),
scheduling,
})
}
Expand Down
4 changes: 1 addition & 3 deletions rust/operator-binary/src/backend/tls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::{
k8s_openapi::chrono::{self, FixedOffset, TimeZone},
time::Duration,
utils::cluster_info::KubernetesClusterInfo,
};
use time::OffsetDateTime;

Expand Down Expand Up @@ -180,7 +179,6 @@ impl SecretBackend for TlsGenerate {
/// Then add the ca certificate and return these files for provisioning to the volume.
async fn get_secret_data(
&self,
cluster_info: &KubernetesClusterInfo,
selector: &super::SecretVolumeSelector,
pod_info: PodInfo,
) -> Result<SecretContents, Self::Error> {
Expand Down Expand Up @@ -251,7 +249,7 @@ impl SecretBackend for TlsGenerate {
for scope in &selector.scope {
addresses.extend(
selector
.scope_addresses(cluster_info, &pod_info, scope)
.scope_addresses(&pod_info, scope)
.context(ScopeAddressesSnafu { scope })?,
);
}
Expand Down
2 changes: 1 addition & 1 deletion rust/operator-binary/src/csi_server/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl Node for SecretProvisionerNode {
let pod_ref = ObjectRef::<Pod>::new(&selector.pod).within(&selector.namespace);
tracing::info!(pod = %pod_ref, ?selector, ?pod_info, ?backend, "issuing secret for Pod");
let data = backend
.get_secret_data(&self.client.kubernetes_cluster_info, &selector, pod_info)
.get_secret_data(&selector, pod_info)
.await
.context(publish_error::BackendGetSecretDataSnafu)?;
self.tag_pod(&self.client, &request.volume_id, &selector, &data)
Expand Down

0 comments on commit f8e01c5

Please sign in to comment.