-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from arnaldo2792/nvidia-settings-api
feat: drop nvidia-device-plugin feature
- Loading branch information
Showing
10 changed files
with
129 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
bottlerocket-settings-models/settings-extensions/kubelet-device-plugins/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 13 additions & 0 deletions
13
...et-settings-models/settings-extensions/kubelet-device-plugins/kubelet-device-plugins.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
75 changes: 75 additions & 0 deletions
75
bottlerocket-settings-models/settings-extensions/kubelet-device-plugins/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
bottlerocket-settings-models/settings-extensions/kubelet-device-plugins/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters