fix: modifed naming scheme to OpenshiftFamily, K3sFamily, and defaultswitched discovery of openshiftfamily to look for projet.openshift.io
This commit is contained in:
parent
f073b7e5fb
commit
1cec398d4d
@ -48,10 +48,10 @@ struct K8sState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum K8sFlavour {
|
pub enum KubernetesDistribution {
|
||||||
Okd,
|
OpenshiftFamily,
|
||||||
K3d,
|
K3sFamily,
|
||||||
K8s,
|
Default,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -64,7 +64,7 @@ enum K8sSource {
|
|||||||
pub struct K8sAnywhereTopology {
|
pub struct K8sAnywhereTopology {
|
||||||
k8s_state: Arc<OnceCell<Option<K8sState>>>,
|
k8s_state: Arc<OnceCell<Option<K8sState>>>,
|
||||||
tenant_manager: Arc<OnceCell<K8sTenantManager>>,
|
tenant_manager: Arc<OnceCell<K8sTenantManager>>,
|
||||||
flavour: Arc<OnceCell<K8sFlavour>>,
|
flavour: Arc<OnceCell<KubernetesDistribution>>,
|
||||||
config: Arc<K8sAnywhereConfig>,
|
config: Arc<K8sAnywhereConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ impl K8sAnywhereTopology {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_k8s_flavour(&self) -> K8sFlavour {
|
pub async fn get_k8s_distribution(&self) -> KubernetesDistribution {
|
||||||
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,22 +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<K8sFlavour>] = &[
|
let rules: &[&dyn Fn() -> Option<KubernetesDistribution>] = &[
|
||||||
// OpenShift / OKD
|
// OpenShift / OKD
|
||||||
&|| {
|
&|| {
|
||||||
discovery
|
discovery
|
||||||
.groups()
|
.groups()
|
||||||
.any(|g| g.name().ends_with("openshift.io"))
|
.any(|g| g.name() == "project.openshift.io")
|
||||||
.then_some(K8sFlavour::Okd)
|
.then_some(KubernetesDistribution::OpenshiftFamily)
|
||||||
},
|
},
|
||||||
// K3d / K3s
|
// K3d / K3s
|
||||||
&|| {
|
&|| {
|
||||||
version
|
version
|
||||||
.git_version
|
.git_version
|
||||||
.contains("k3s")
|
.contains("k3s")
|
||||||
.then_some(K8sFlavour::K3d)
|
.then_some(KubernetesDistribution::K3sFamily)
|
||||||
},
|
},
|
||||||
// Vanilla Kubernetes
|
// Fallback Kubernetes K8s
|
||||||
&|| {
|
&|| {
|
||||||
if !discovery
|
if !discovery
|
||||||
.groups()
|
.groups()
|
||||||
@ -220,7 +220,7 @@ impl K8sAnywhereTopology {
|
|||||||
&& !version.git_version.contains("k3s")
|
&& !version.git_version.contains("k3s")
|
||||||
&& !version.git_version.contains("k3d")
|
&& !version.git_version.contains("k3d")
|
||||||
{
|
{
|
||||||
Some(K8sFlavour::K8s)
|
Some(KubernetesDistribution::Default)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -228,7 +228,9 @@ impl K8sAnywhereTopology {
|
|||||||
];
|
];
|
||||||
|
|
||||||
rules.iter().find_map(|rule| rule()).ok_or_else(|| {
|
rules.iter().find_map(|rule| rule()).ok_or_else(|| {
|
||||||
PreparationError::new("Unknown Kubernetes cluster flavour".to_string())
|
PreparationError::new(
|
||||||
|
"Unable to detect Kubernetes cluster distribution".to_string(),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
Loading…
Reference in New Issue
Block a user