feat: K8sFlavour #161
@ -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
|
||||||
&|| {
|
.groups()
|
||||||
discovery
|
.any(|g| g.name() == "project.openshift.io")
|
||||||
.groups()
|
{
|
||||||
.any(|g| g.name() == "project.openshift.io")
|
return Ok(KubernetesDistribution::OpenshiftFamily);
|
||||||
.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
|
|
||||||
}
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
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
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.clone()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_cluster_observability_operator_prometheus_application_score(
|
async fn get_cluster_observability_operator_prometheus_application_score(
|
||||||
|
Loading…
Reference in New Issue
Block a user
That is a clear naming problem. Should be either k3d for real by detecting it another way or k3sFamily just like OpenshiftFamily