Skip to content

Commit

Permalink
Merge pull request #60 from arnaldo2792/nvidia-settings-api
Browse files Browse the repository at this point in the history
feat: drop nvidia-device-plugin feature
  • Loading branch information
arnaldo2792 authored Sep 10, 2024
2 parents 28f3c66 + 25b5ea5 commit 4ad8f9e
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 38 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ members = [
"bottlerocket-settings-models/settings-extensions/host-containers",
"bottlerocket-settings-models/settings-extensions/kernel",
"bottlerocket-settings-models/settings-extensions/kubernetes",
"bottlerocket-settings-models/settings-extensions/kubelet-device-plugins",
"bottlerocket-settings-models/settings-extensions/metrics",
"bottlerocket-settings-models/settings-extensions/motd",
"bottlerocket-settings-models/settings-extensions/network",
Expand Down Expand Up @@ -74,6 +75,7 @@ settings-extension-ecs = { path = "./bottlerocket-settings-models/settings-exten
settings-extension-host-containers = { path = "./bottlerocket-settings-models/settings-extensions/host-containers", version = "0.1" }
settings-extension-kernel = { path = "./bottlerocket-settings-models/settings-extensions/kernel", version = "0.1" }
settings-extension-kubernetes = { path = "./bottlerocket-settings-models/settings-extensions/kubernetes", version = "0.1" }
settings-extension-kubelet-device-plugins = { path = "./bottlerocket-settings-models/settings-extensions/kubelet-device-plugins", version = "0.1" }
settings-extension-metrics = { path = "./bottlerocket-settings-models/settings-extensions/metrics", version = "0.1" }
settings-extension-motd = { path = "./bottlerocket-settings-models/settings-extensions/motd", version = "0.1" }
settings-extension-network = { path = "./bottlerocket-settings-models/settings-extensions/network", version = "0.1" }
Expand Down
25 changes: 0 additions & 25 deletions bottlerocket-settings-models/modeled-types/src/kubernetes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,11 +1445,6 @@ mod test_hostname_override_source {
}

// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
// Define the DevicePlugin struct
#[model(impl_default = true)]
pub struct K8sDevicePluginsSettings {
nvidia: NvidiaDevicePluginSettings,
}

/// NvidiaRuntimeSettings contains the container runtime settings for Nvidia gpu.
#[model(impl_default = true)]
Expand Down Expand Up @@ -1477,26 +1472,6 @@ pub enum NvidiaDeviceListStrategy {
mod tests {
use super::*;

#[test]
fn test_serde_k8s_device_plugins() {
let test_json = r#"{"nvidia":{"pass-device-specs":true,"device-id-strategy":"index","device-list-strategy":"volume-mounts"}}"#;

let device_plugins: K8sDevicePluginsSettings = serde_json::from_str(test_json).unwrap();
assert_eq!(
device_plugins,
K8sDevicePluginsSettings {
nvidia: Some(NvidiaDevicePluginSettings {
pass_device_specs: Some(true),
device_id_strategy: Some(NvidiaDeviceIdStrategy::Index),
device_list_strategy: Some(NvidiaDeviceListStrategy::VolumeMounts),
}),
}
);

let results = serde_json::to_string(&device_plugins).unwrap();
assert_eq!(results, test_json);
}

#[test]
fn test_serde_nvidia_device_plugins() {
let test_json = r#"{"pass-device-specs":false,"device-id-strategy":"uuid","device-list-strategy":"envvar"}"#;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "settings-extension-kubelet-device-plugins"
version = "0.1.0"
authors = ["Arnaldo Garcia Rincon <[email protected]>"]
license = "Apache-2.0 OR MIT"
edition = "2021"
publish = false

[dependencies]
bottlerocket-modeled-types.workspace = true
bottlerocket-model-derive.workspace = true
bottlerocket-settings-sdk.workspace = true
env_logger.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true

[lints]
workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[extension]
supported-versions = [
"v1"
]
default-version = "v1"

[v1]
[v1.validation.cross-validates]

[v1.templating]
helpers = []

[v1.generation.requires]
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! Settings related to Kubelet Device Plugins
use bottlerocket_model_derive::model;
use bottlerocket_modeled_types::NvidiaDevicePluginSettings;
use bottlerocket_settings_sdk::{GenerateResult, SettingsModel};
use std::convert::Infallible;

#[model(impl_default = true)]
pub struct KubeletDevicePluginsV1 {
nvidia: NvidiaDevicePluginSettings,
}

type Result<T> = std::result::Result<T, Infallible>;

impl SettingsModel for KubeletDevicePluginsV1 {
type PartialKind = Self;
type ErrorKind = Infallible;

fn get_version() -> &'static str {
"v1"
}

fn set(_current_value: Option<Self>, _target: Self) -> Result<()> {
// Set anything that can be parsed as ECSSettingsV1.
Ok(())
}

fn generate(
existing_partial: Option<Self::PartialKind>,
_dependent_settings: Option<serde_json::Value>,
) -> Result<GenerateResult<Self::PartialKind, Self>> {
Ok(GenerateResult::Complete(
existing_partial.unwrap_or_default(),
))
}

fn validate(_value: Self, _validated_settings: Option<serde_json::Value>) -> Result<()> {
// KubeletDevicePluginsV1 is validated during deserialization.
Ok(())
}
}

#[cfg(test)]
mod test {
use super::*;
use bottlerocket_modeled_types::{NvidiaDeviceIdStrategy, NvidiaDeviceListStrategy};

#[test]
fn test_generate_kubelet_device_plugins() {
let generated = KubeletDevicePluginsV1::generate(None, None).unwrap();
assert_eq!(
generated,
GenerateResult::Complete(KubeletDevicePluginsV1 { nvidia: None })
);
}

#[test]
fn test_serde_kubelet_device_plugins() {
let test_json = r#"{"nvidia":{"pass-device-specs":true,"device-id-strategy":"index","device-list-strategy":"volume-mounts"}}"#;

let device_plugins: KubeletDevicePluginsV1 = serde_json::from_str(test_json).unwrap();
assert_eq!(
device_plugins,
KubeletDevicePluginsV1 {
nvidia: Some(NvidiaDevicePluginSettings {
pass_device_specs: Some(true),
device_id_strategy: Some(NvidiaDeviceIdStrategy::Index),
device_list_strategy: Some(NvidiaDeviceListStrategy::VolumeMounts),
}),
}
);

let results = serde_json::to_string(&device_plugins).unwrap();
assert_eq!(results, test_json);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use bottlerocket_settings_sdk::{BottlerocketSetting, NullMigratorExtensionBuilder};
use settings_extension_kubelet_device_plugins::KubeletDevicePluginsV1;
use std::process::ExitCode;

fn main() -> ExitCode {
env_logger::init();

match NullMigratorExtensionBuilder::with_name("kubelet-device-plugin")
.with_models(vec![BottlerocketSetting::<KubeletDevicePluginsV1>::model()])
.build()
{
Ok(extension) => extension.run(),
Err(e) => {
println!("{}", e);
ExitCode::FAILURE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ edition = "2021"
publish = false

[features]
# With the 'nvidia-device-plugin' feature enabled, the compilation
# includes NVIDIA GPU-related code, for instance, NvidiaDevicePluginSettings.
nvidia-device-plugin = []

[dependencies]
bottlerocket-modeled-types.workspace = true
Expand All @@ -24,4 +21,4 @@ toml.workspace = true
workspace = true

[dev-dependencies]
settings-extension-kubernetes = { workspace = true, features = ["nvidia-device-plugin"] }
settings-extension-kubernetes = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Modeled types for creating Kubernetes settings.
use bottlerocket_model_derive::model;
#[cfg(feature = "nvidia-device-plugin")]
use bottlerocket_modeled_types::K8sDevicePluginsSettings;
use bottlerocket_modeled_types::{
CpuManagerPolicy, CredentialProvider, DNSDomain, Identifier, IntegerPercent, KernelCpuSetValue,
KubernetesAuthenticationMode, KubernetesBootstrapToken, KubernetesCPUManagerPolicyOption,
Expand Down Expand Up @@ -96,8 +94,6 @@ pub struct KubernetesSettingsV1 {
hostname_override_source: KubernetesHostnameOverrideSource,
// Generated in `k8s-1.25+` variants only
seccomp_default: bool,
#[cfg(feature = "nvidia-device-plugin")]
device_plugins: K8sDevicePluginsSettings,
}

type Result<T> = std::result::Result<T, Infallible>;
Expand Down Expand Up @@ -195,8 +191,6 @@ mod test {
hostname_override: None,
hostname_override_source: None,
seccomp_default: None,
#[cfg(feature = "nvidia-device-plugin")]
device_plugins: None,
})
);
}
Expand Down
4 changes: 1 addition & 3 deletions bottlerocket-settings-models/settings-models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ publish = false
exclude = ["README.md"]

[features]
# With the 'nvidia-device-plugin' feature enabled, the compilation
# includes NVIDIA GPU-related code, for instance, NvidiaDevicePluginSettings.
nvidia-device-plugin = ["settings-extension-kubernetes/nvidia-device-plugin"]

[dependencies]
libc.workspace = true
Expand All @@ -37,6 +34,7 @@ settings-extension-ecs.workspace = true
settings-extension-host-containers.workspace = true
settings-extension-kernel.workspace = true
settings-extension-kubernetes.workspace = true
settings-extension-kubelet-device-plugins.workspace = true
settings-extension-metrics.workspace = true
settings-extension-motd.workspace = true
settings-extension-network.workspace = true
Expand Down
1 change: 1 addition & 0 deletions bottlerocket-settings-models/settings-models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub use settings_extension_dns::{self, DnsSettingsV1};
pub use settings_extension_ecs::{self, ECSSettingsV1};
pub use settings_extension_host_containers::{self, HostContainersSettingsV1};
pub use settings_extension_kernel::{self, KernelSettingsV1};
pub use settings_extension_kubelet_device_plugins::{self, KubeletDevicePluginsV1};
pub use settings_extension_kubernetes::{self, KubernetesSettingsV1};
pub use settings_extension_metrics::{self, MetricsSettingsV1};
pub use settings_extension_motd::{self, MotdV1};
Expand Down

0 comments on commit 4ad8f9e

Please sign in to comment.