feat: K8sFlavour #161

Merged
wjro merged 7 commits from feat/detect_k8s_flavour into master 2025-10-21 15:56:48 +00:00
Showing only changes of commit 2d3c32469c - Show all commits

View File

@ -184,7 +184,7 @@ impl K8sAnywhereTopology {
} }
} }
pub async fn get_k8s_distribution(&self) -> KubernetesDistribution { pub async fn get_k8s_distribution(&self) -> Result<&KubernetesDistribution, PreparationError> {
self.flavour self.flavour
.get_or_try_init(async || { .get_or_try_init(async || {
let client = self.k8s_client().await.unwrap(); let client = self.k8s_client().await.unwrap();
@ -197,45 +197,22 @@ impl K8sAnywhereTopology {
PreparationError::new(format!("Could not get server version: {}", e)) PreparationError::new(format!("Could not get server version: {}", e))
})?; })?;
let rules: &[&dyn Fn() -> Option<KubernetesDistribution>] = &[
// OpenShift / OKD // OpenShift / OKD
&|| { if discovery
discovery
.groups() .groups()
.any(|g| g.name() == "project.openshift.io") .any(|g| g.name() == "project.openshift.io")
.then_some(KubernetesDistribution::OpenshiftFamily)
},
// K3d / K3s
&|| {
version
.git_version
.contains("k3s")
.then_some(KubernetesDistribution::K3sFamily)
},
// Fallback Kubernetes K8s
&|| {
if !discovery
.groups()
.any(|g| g.name().ends_with("openshift.io"))
&& !version.git_version.contains("k3s")
&& !version.git_version.contains("k3d")
{ {
Some(KubernetesDistribution::Default) return Ok(KubernetesDistribution::OpenshiftFamily);
} else {
None
} }
},
];
rules.iter().find_map(|rule| rule()).ok_or_else(|| { // K3d / K3s
PreparationError::new( if version.git_version.contains("k3s") {
"Unable to detect Kubernetes cluster distribution".to_string(), return Ok(KubernetesDistribution::K3sFamily);
) }
})
return Ok(KubernetesDistribution::Default);
wjro marked this conversation as resolved Outdated

That is a clear naming problem. Should be either k3d for real by detecting it another way or k3sFamily just like OpenshiftFamily

That is a clear naming problem. Should be either k3d for real by detecting it another way or k3sFamily just like OpenshiftFamily
}) })
.await .await
.unwrap()
.clone()
} }
async fn get_cluster_observability_operator_prometheus_application_score( async fn get_cluster_observability_operator_prometheus_application_score(