-
Notifications
You must be signed in to change notification settings - Fork 933
feat(server): conditional compilation of compute drivers #2163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ff78235
bbb1f6f
6355e70
9a1e04c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,25 @@ | |
|
|
||
| use crate::config_file; | ||
| use crate::defaults::LocalTlsPaths; | ||
| use openshell_core::{ComputeDriverKind, Error, Result}; | ||
| #[cfg(any( | ||
| feature = "driver-kubernetes", | ||
| feature = "driver-docker", | ||
| feature = "driver-podman", | ||
| feature = "driver-vm", | ||
| ))] | ||
| use openshell_core::ComputeDriverKind; | ||
| use openshell_core::{Error, Result}; | ||
| #[cfg(feature = "driver-docker")] | ||
| use openshell_driver_docker::DockerComputeConfig; | ||
| #[cfg(feature = "driver-kubernetes")] | ||
| use openshell_driver_kubernetes::KubernetesComputeConfig; | ||
| #[cfg(feature = "driver-podman")] | ||
| use openshell_driver_podman::PodmanComputeConfig; | ||
| use serde::Deserialize; | ||
| use std::collections::BTreeMap; | ||
| use std::path::PathBuf; | ||
|
|
||
| #[cfg(feature = "driver-vm")] | ||
| use super::VmComputeConfig; | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
|
|
@@ -39,13 +50,28 @@ impl From<&LocalTlsPaths> for GuestTlsPaths { | |
| #[derive(Clone, Copy)] | ||
| pub struct DriverStartupContext<'a> { | ||
| pub file: Option<&'a config_file::ConfigFile>, | ||
| // Consumed only by the docker/podman/vm runtime-defaults helpers below. | ||
| #[cfg_attr( | ||
| not(any( | ||
| feature = "driver-docker", | ||
| feature = "driver-podman", | ||
| feature = "driver-vm" | ||
| )), | ||
| allow(dead_code) | ||
| )] | ||
| pub guest_tls: Option<&'a GuestTlsPaths>, | ||
| #[cfg_attr( | ||
| not(any(feature = "driver-podman", feature = "driver-vm")), | ||
| allow(dead_code) | ||
| )] | ||
| pub gateway_port: u16, | ||
| #[cfg_attr(not(feature = "driver-vm"), allow(dead_code))] | ||
| pub gateway_tls_enabled: bool, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer With #[derive(Clone, Copy)]
pub struct DriverStartupContext<'a> {
pub file: Option<&'a config_file::ConfigFile>,
#[cfg(any(feature = "driver-docker", feature = "driver-podman", feature = "driver-vm"))]
pub guest_tls: Option<&'a GuestTlsPaths>,
#[cfg(any(feature = "driver-podman", feature = "driver-vm"))]
pub gateway_port: u16,
#[cfg(feature = "driver-vm")]
pub gateway_tls_enabled: bool,
pub endpoint_overrides: &'a BTreeMap<String, PathBuf>,
}The three construction sites ( |
||
| pub endpoint_overrides: &'a BTreeMap<String, PathBuf>, | ||
| } | ||
|
|
||
| /// Build the selected Kubernetes config from TOML plus runtime defaults. | ||
| #[cfg(feature = "driver-kubernetes")] | ||
| pub fn kubernetes_config_from_context( | ||
| context: DriverStartupContext<'_>, | ||
| ) -> Result<KubernetesComputeConfig> { | ||
|
|
@@ -54,6 +80,7 @@ pub fn kubernetes_config_from_context( | |
| Ok(cfg) | ||
| } | ||
|
|
||
| #[cfg(feature = "driver-kubernetes")] | ||
| pub fn kubernetes_config_for_k8s_sa_bootstrap( | ||
| file: Option<&config_file::ConfigFile>, | ||
| ) -> Result<KubernetesComputeConfig> { | ||
|
|
@@ -71,6 +98,7 @@ pub fn kubernetes_config_for_k8s_sa_bootstrap( | |
| } | ||
|
|
||
| /// Build the selected Podman config from TOML plus runtime defaults. | ||
| #[cfg(feature = "driver-podman")] | ||
| pub fn podman_config_from_context( | ||
| context: DriverStartupContext<'_>, | ||
| ) -> Result<PodmanComputeConfig> { | ||
|
|
@@ -80,6 +108,7 @@ pub fn podman_config_from_context( | |
| } | ||
|
|
||
| /// Build the selected Docker config from TOML plus runtime defaults. | ||
| #[cfg(feature = "driver-docker")] | ||
| pub fn docker_config_from_context( | ||
| context: DriverStartupContext<'_>, | ||
| ) -> Result<DockerComputeConfig> { | ||
|
|
@@ -89,6 +118,7 @@ pub fn docker_config_from_context( | |
| } | ||
|
|
||
| /// Build the selected VM config from TOML plus runtime defaults. | ||
| #[cfg(feature = "driver-vm")] | ||
| pub fn vm_config_from_context(context: DriverStartupContext<'_>) -> Result<VmComputeConfig> { | ||
| let mut cfg = driver_config_from_context(context, ComputeDriverKind::Vm.as_str())?; | ||
| apply_vm_runtime_defaults(&mut cfg, context); | ||
|
|
@@ -141,12 +171,14 @@ where | |
| }) | ||
| } | ||
|
|
||
| #[cfg(feature = "driver-kubernetes")] | ||
| fn apply_kubernetes_runtime_defaults(k8s: &mut KubernetesComputeConfig) { | ||
| if let Ok(size) = std::env::var("OPENSHELL_K8S_WORKSPACE_DEFAULT_STORAGE_SIZE") { | ||
| k8s.workspace_default_storage_size = size; | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "driver-podman")] | ||
| fn apply_podman_runtime_defaults( | ||
| podman: &mut PodmanComputeConfig, | ||
| context: DriverStartupContext<'_>, | ||
|
|
@@ -161,6 +193,7 @@ fn apply_podman_runtime_defaults( | |
| ); | ||
| } | ||
|
|
||
| #[cfg(feature = "driver-docker")] | ||
| fn apply_docker_runtime_defaults(cfg: &mut DockerComputeConfig, context: DriverStartupContext<'_>) { | ||
| apply_guest_tls_defaults_to_split_fields( | ||
| &mut cfg.guest_tls_ca, | ||
|
|
@@ -170,6 +203,7 @@ fn apply_docker_runtime_defaults(cfg: &mut DockerComputeConfig, context: DriverS | |
| ); | ||
| } | ||
|
|
||
| #[cfg(feature = "driver-vm")] | ||
| fn apply_vm_runtime_defaults(cfg: &mut VmComputeConfig, context: DriverStartupContext<'_>) { | ||
| if cfg.state_dir.as_os_str().is_empty() { | ||
| cfg.state_dir = VmComputeConfig::default_state_dir(); | ||
|
|
@@ -193,6 +227,7 @@ fn apply_vm_runtime_defaults(cfg: &mut VmComputeConfig, context: DriverStartupCo | |
| ); | ||
| } | ||
|
|
||
| #[cfg(feature = "driver-podman")] | ||
| fn apply_podman_env_overrides(podman: &mut PodmanComputeConfig) { | ||
| if let Ok(p) = std::env::var("OPENSHELL_PODMAN_SOCKET") { | ||
| podman.socket_path = PathBuf::from(p); | ||
|
|
@@ -221,6 +256,11 @@ fn validate_remote_driver_config(cfg: &RemoteDriverConfig, name: &str) -> Result | |
| ))) | ||
| } | ||
|
|
||
| #[cfg(any( | ||
| feature = "driver-docker", | ||
| feature = "driver-podman", | ||
| feature = "driver-vm" | ||
| ))] | ||
| fn apply_guest_tls_defaults_to_split_fields( | ||
| ca: &mut Option<PathBuf>, | ||
| cert: &mut Option<PathBuf>, | ||
|
|
@@ -263,6 +303,7 @@ mod tests { | |
| } | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "driver-kubernetes")] | ||
| fn k8s_sa_bootstrap_rejects_missing_kubernetes_driver_config() { | ||
| let err = kubernetes_config_for_k8s_sa_bootstrap(None).unwrap_err(); | ||
| assert!(err.to_string().contains("[openshell.drivers.kubernetes]")); | ||
|
|
@@ -274,6 +315,7 @@ mod tests { | |
| } | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "driver-kubernetes")] | ||
| fn k8s_sa_bootstrap_uses_configured_namespace_and_service_account() { | ||
| let file: config_file::ConfigFile = toml::from_str( | ||
| r#" | ||
|
|
@@ -292,6 +334,7 @@ service_account_name = "sandbox-sa" | |
| } | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "driver-podman")] | ||
| fn podman_config_reads_bind_mount_opt_in_from_driver_table() { | ||
| let file: config_file::ConfigFile = toml::from_str( | ||
| r" | ||
|
|
@@ -307,6 +350,7 @@ enable_bind_mounts = true | |
| } | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "driver-docker")] | ||
| fn docker_config_reads_bind_mount_opt_in_from_driver_table() { | ||
| let file: config_file::ConfigFile = toml::from_str( | ||
| r" | ||
|
|
@@ -383,6 +427,7 @@ socket_path = "/run/openshell/kyma.sock" | |
| } | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "driver-docker")] | ||
| fn docker_config_reports_selected_invalid_driver_table() { | ||
| let file: config_file::ConfigFile = toml::from_str( | ||
| r" | ||
|
|
@@ -401,6 +446,7 @@ unknown_docker_key = true | |
| } | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "driver-vm")] | ||
| fn vm_config_reports_selected_invalid_driver_table() { | ||
| let file: config_file::ConfigFile = toml::from_str( | ||
| r#" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.