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 1cec398d4d - Show all commits

View File

@ -48,10 +48,10 @@ struct K8sState {
}
#[derive(Debug, Clone)]
pub enum K8sFlavour {
Okd,
K3d,
K8s,
pub enum KubernetesDistribution {
OpenshiftFamily,
wjro marked this conversation as resolved Outdated

Should be OpenshiftFamily(Version) as we want the same behavior between okd and openshift.

Should be OpenshiftFamily(Version) as we want the same behavior between okd and openshift.
K3sFamily,
Default,
}
#[derive(Debug, Clone)]
@ -64,7 +64,7 @@ enum K8sSource {
pub struct K8sAnywhereTopology {
k8s_state: Arc<OnceCell<Option<K8sState>>>,
tenant_manager: Arc<OnceCell<K8sTenantManager>>,
flavour: Arc<OnceCell<K8sFlavour>>,
flavour: Arc<OnceCell<KubernetesDistribution>>,
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
.get_or_try_init(async || {
let client = self.k8s_client().await.unwrap();
@ -197,22 +197,22 @@ impl K8sAnywhereTopology {
PreparationError::new(format!("Could not get server version: {}", e))
})?;
let rules: &[&dyn Fn() -> Option<K8sFlavour>] = &[
let rules: &[&dyn Fn() -> Option<KubernetesDistribution>] = &[
// OpenShift / OKD
&|| {
discovery
.groups()
.any(|g| g.name().ends_with("openshift.io"))
.then_some(K8sFlavour::Okd)
.any(|g| g.name() == "project.openshift.io")
.then_some(KubernetesDistribution::OpenshiftFamily)
},
// K3d / K3s
&|| {
version
.git_version
.contains("k3s")
.then_some(K8sFlavour::K3d)
.then_some(KubernetesDistribution::K3sFamily)
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
},
// Vanilla Kubernetes
// Fallback Kubernetes K8s
&|| {
if !discovery
.groups()
@ -220,7 +220,7 @@ impl K8sAnywhereTopology {
&& !version.git_version.contains("k3s")
&& !version.git_version.contains("k3d")
{
Some(K8sFlavour::K8s)
Some(KubernetesDistribution::Default)
wjro marked this conversation as resolved Outdated

This is more of a fallback to a default than a true way to detect that we're running vanilla k8s (made by kubeadm for example).

Should be called Default or Fallback or Unknown but not k8s.

This is more of a fallback to a default than a true way to detect that we're running vanilla k8s (made by kubeadm for example). Should be called Default or Fallback or Unknown but not k8s.
} else {
None
}
@ -228,7 +228,9 @@ impl K8sAnywhereTopology {
];
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