chore: Simplify k8s flavour detection algorithm and do not unwrap when it cannot be detected, just return Err
This commit is contained in:
parent
1cec398d4d
commit
2d3c32469c
@ -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
|
||||
.get_or_try_init(async || {
|
||||
let client = self.k8s_client().await.unwrap();
|
||||
@ -197,45 +197,22 @@ impl K8sAnywhereTopology {
|
||||
PreparationError::new(format!("Could not get server version: {}", e))
|
||||
})?;
|
||||
|
||||
let rules: &[&dyn Fn() -> Option<KubernetesDistribution>] = &[
|
||||
// OpenShift / OKD
|
||||
&|| {
|
||||
discovery
|
||||
.groups()
|
||||
.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)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
];
|
||||
// OpenShift / OKD
|
||||
if discovery
|
||||
.groups()
|
||||
.any(|g| g.name() == "project.openshift.io")
|
||||
{
|
||||
return Ok(KubernetesDistribution::OpenshiftFamily);
|
||||
}
|
||||
|
||||
rules.iter().find_map(|rule| rule()).ok_or_else(|| {
|
||||
PreparationError::new(
|
||||
"Unable to detect Kubernetes cluster distribution".to_string(),
|
||||
)
|
||||
})
|
||||
// K3d / K3s
|
||||
if version.git_version.contains("k3s") {
|
||||
return Ok(KubernetesDistribution::K3sFamily);
|
||||
}
|
||||
|
||||
return Ok(KubernetesDistribution::Default);
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.clone()
|
||||
}
|
||||
|
||||
async fn get_cluster_observability_operator_prometheus_application_score(
|
||||
|
Loading…
Reference in New Issue
Block a user