mirror of
https://github.com/kata-containers/kata-containers.git
synced 2026-04-09 05:23:43 +00:00
kata-deploy: Fix clippy warnings across crate
Fix all clippy warnings triggered by -D warnings: - install.rs: remove useless .into() conversions on PathBuf values and replace vec! with an array literal where a Vec is not needed - utils/toml.rs: replace while-let-on-iterator with a for loop and drop the now-unnecessary mut on the iterator binding - main.rs: replace match-with-single-pattern with if-let in two places dealing with experimental_setup_snapshotter - utils/yaml.rs: extract repeated serde_yaml::Value::String key into a local variable, removing needless borrows on temporary values Signed-off-by: Fabiano Fidêncio <ffidencio@nvidia.com> Made-with: Cursor
This commit is contained in:
@@ -341,10 +341,10 @@ fn copy_artifacts(src: &str, dst: &str) -> Result<()> {
|
||||
if let Ok(rel) = link_target.strip_prefix(src_path) {
|
||||
Path::new(dst).join(rel)
|
||||
} else {
|
||||
link_target.into()
|
||||
link_target
|
||||
}
|
||||
} else {
|
||||
link_target.into()
|
||||
link_target
|
||||
};
|
||||
|
||||
if let Some(parent) = dst_path.parent() {
|
||||
@@ -385,7 +385,7 @@ fn copy_artifacts(src: &str, dst: &str) -> Result<()> {
|
||||
}
|
||||
|
||||
fn set_executable_permissions(dir: &str) -> Result<()> {
|
||||
let bin_paths = vec!["bin", "runtime-rs/bin"];
|
||||
let bin_paths = ["bin", "runtime-rs/bin"];
|
||||
|
||||
for bin_path in bin_paths.iter() {
|
||||
let bin_dir = Path::new(dir).join(bin_path);
|
||||
|
||||
@@ -177,36 +177,30 @@ async fn install(config: &config::Config, runtime: &str) -> Result<()> {
|
||||
}
|
||||
|
||||
// Validate snapshotter if needed
|
||||
match config.experimental_setup_snapshotter.as_ref() {
|
||||
Some(snapshotter) => {
|
||||
let non_empty_snapshotters: Vec<_> =
|
||||
snapshotter.iter().filter(|s| !s.is_empty()).collect();
|
||||
if let Some(snapshotter) = config.experimental_setup_snapshotter.as_ref() {
|
||||
let non_empty_snapshotters: Vec<_> = snapshotter.iter().filter(|s| !s.is_empty()).collect();
|
||||
|
||||
if !non_empty_snapshotters.is_empty() {
|
||||
if runtime == "crio" {
|
||||
log::warn!("EXPERIMENTAL_SETUP_SNAPSHOTTER is being ignored!");
|
||||
log::warn!("Snapshotter is a containerd specific option.");
|
||||
} else {
|
||||
for s in &non_empty_snapshotters {
|
||||
match s.as_str() {
|
||||
"erofs" => {
|
||||
runtime::containerd::containerd_erofs_snapshotter_version_check(
|
||||
config,
|
||||
)
|
||||
if !non_empty_snapshotters.is_empty() {
|
||||
if runtime == "crio" {
|
||||
log::warn!("EXPERIMENTAL_SETUP_SNAPSHOTTER is being ignored!");
|
||||
log::warn!("Snapshotter is a containerd specific option.");
|
||||
} else {
|
||||
for s in &non_empty_snapshotters {
|
||||
match s.as_str() {
|
||||
"erofs" => {
|
||||
runtime::containerd::containerd_erofs_snapshotter_version_check(config)
|
||||
.await?;
|
||||
}
|
||||
"nydus" => {}
|
||||
_ => {
|
||||
return Err(anyhow::anyhow!(
|
||||
"{s} is not a supported snapshotter by kata-deploy"
|
||||
));
|
||||
}
|
||||
}
|
||||
"nydus" => {}
|
||||
_ => {
|
||||
return Err(anyhow::anyhow!(
|
||||
"{s} is not a supported snapshotter by kata-deploy"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
runtime::containerd::setup_containerd_config_files(runtime, config).await?;
|
||||
@@ -216,15 +210,12 @@ async fn install(config: &config::Config, runtime: &str) -> Result<()> {
|
||||
runtime::configure_cri_runtime(config, runtime).await?;
|
||||
|
||||
if runtime != "crio" {
|
||||
match config.experimental_setup_snapshotter.as_ref() {
|
||||
Some(snapshotters) => {
|
||||
for snapshotter in snapshotters {
|
||||
artifacts::snapshotters::install_snapshotter(snapshotter, config).await?;
|
||||
artifacts::snapshotters::configure_snapshotter(snapshotter, runtime, config)
|
||||
.await?;
|
||||
}
|
||||
if let Some(snapshotters) = config.experimental_setup_snapshotter.as_ref() {
|
||||
for snapshotter in snapshotters {
|
||||
artifacts::snapshotters::install_snapshotter(snapshotter, config).await?;
|
||||
artifacts::snapshotters::configure_snapshotter(snapshotter, runtime, config)
|
||||
.await?;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ fn parse_toml_path(path: &str) -> Result<Vec<String>> {
|
||||
let mut parts = Vec::new();
|
||||
let mut current = String::new();
|
||||
let mut in_quotes = false;
|
||||
let mut chars = path.chars().peekable();
|
||||
let chars = path.chars().peekable();
|
||||
|
||||
while let Some(ch) = chars.next() {
|
||||
for ch in chars {
|
||||
match ch {
|
||||
'"' => {
|
||||
in_quotes = !in_quotes;
|
||||
|
||||
@@ -37,15 +37,14 @@ pub fn set_yaml_value(file_path: &Path, key_path: &str, value: serde_yaml::Value
|
||||
} else {
|
||||
// Navigate/create intermediate mappings
|
||||
if let Some(map) = current.as_mapping_mut() {
|
||||
if !map.contains_key(&serde_yaml::Value::String(part.to_string())) {
|
||||
let key = serde_yaml::Value::String(part.to_string());
|
||||
if !map.contains_key(&key) {
|
||||
map.insert(
|
||||
serde_yaml::Value::String(part.to_string()),
|
||||
key.clone(),
|
||||
serde_yaml::Value::Mapping(serde_yaml::Mapping::new()),
|
||||
);
|
||||
}
|
||||
current = map
|
||||
.get_mut(&serde_yaml::Value::String(part.to_string()))
|
||||
.unwrap();
|
||||
current = map.get_mut(&key).unwrap();
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("Path component '{part}' is not a mapping"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user