Skip to content
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

Quick fixes #2190

Merged
merged 3 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sources/api/schnauzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ http = "0.2"
lazy_static = "1.4"
log = "0.4"
models = { path = "../../models", version = "0.1.0" }
num_cpus = "1.0"
percent-encoding = "2.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
snafu = "0.7"
tokio = { version = "~1.14", default-features = false, features = ["macros", "rt-multi-thread"] } # LTS
url = "2.1"
num_cpus = "1.0"

[build-dependencies]
generate-readme = { version = "0.1", path = "../../generate-readme" }
28 changes: 12 additions & 16 deletions sources/api/schnauzer/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use dns_lookup::lookup_host;
use handlebars::{Context, Handlebars, Helper, Output, RenderContext, RenderError};
use lazy_static::lazy_static;
use num_cpus;
use serde_json::value::Value;
use snafu::{OptionExt, ResultExt};
use std::borrow::Borrow;
Expand Down Expand Up @@ -38,10 +37,10 @@ lazy_static! {
m.insert("sa-east-1", "328549459982");
m.insert("us-east-1", "328549459982");
m.insert("us-east-2", "328549459982");
m.insert("us-gov-east-1", "388230364387");
m.insert("us-gov-west-1", "347163068887");
m.insert("us-west-1", "328549459982");
m.insert("us-west-2", "328549459982");
m.insert("us-gov-west-1", "347163068887");
m.insert("us-gov-east-1", "388230364387");
m
};
}
Expand Down Expand Up @@ -592,7 +591,7 @@ pub fn default(
Value::Number(n) => n.to_string(),
Value::String(s) => s.to_string(),
// If no value is set, use the given default.
Value::Null => default.to_string(),
Value::Null => default,
// composite types unsupported
Value::Array(_) | Value::Object(_) => {
return Err(RenderError::from(
Expand Down Expand Up @@ -748,7 +747,7 @@ pub fn host(
let url_host = url.host_str().context(error::UrlHostSnafu { url_str })?;

// write it to the template
out.write(&url_host)
out.write(url_host)
.with_context(|_| error::TemplateWriteSnafu {
template: template_name.to_owned(),
})?;
Expand Down Expand Up @@ -794,7 +793,7 @@ pub fn goarch(
};

// write it to the template
out.write(&goarch)
out.write(goarch)
.with_context(|_| error::TemplateWriteSnafu {
template: template_name.to_owned(),
})?;
Expand Down Expand Up @@ -918,7 +917,9 @@ pub fn kube_reserve_memory(
Value::Number(n) => n.to_string(),
Value::String(s) => s.to_string(),
// If no value is set, use the given default.
Value::Null => { format!("{}Mi", (max_num_pods * 11 + 255).to_string()) }.to_string(),
Value::Null => {
format!("{}Mi", (max_num_pods * 11 + 255))
}
// composite types unsupported
_ => {
return Err(RenderError::from(
Expand Down Expand Up @@ -1075,7 +1076,7 @@ pub fn localhost_aliases(
trace!("Hosts from template: {:?}", hosts);

// If our hostname isn't resolveable, add it to the alias list.
if hostname.len() > 0 && !hostname_resolveable(hostname, hosts.as_ref()) {
if !hostname.is_empty() && !hostname_resolveable(hostname, hosts.as_ref()) {
results.push(hostname.to_owned());
}

Expand Down Expand Up @@ -1250,11 +1251,7 @@ fn kube_cpu_helper(num_cores: usize) -> Result<String, TemplateHelperError> {
KUBE_RESERVE_4_CORES + ((num_cores - 4.0) * KUBE_RESERVE_ADDITIONAL)
}
};
Ok(format!(
"{}{}",
cpu_to_reserve.floor().to_string(),
millicores_unit
))
Ok(format!("{}{}", cpu_to_reserve.floor(), millicores_unit))
}

/// Returns whether or not a hostname resolves to a non-loopback IP address.
Expand All @@ -1268,7 +1265,7 @@ fn hostname_resolveable(
// Note that DNS search paths in /etc/resolv.conf are not relevant here, as they are not checked when searching /etc/hosts.
if let Some(etc_hosts_entries) = configured_hosts {
for (_, alias_list) in etc_hosts_entries.iter_merged() {
if alias_list.iter().any(|alias| alias.to_string() == hostname) {
if alias_list.iter().any(|alias| alias == hostname) {
return true;
}
}
Expand Down Expand Up @@ -1966,8 +1963,7 @@ mod test_kube_reserve_cpu {

#[test]
fn kube_reserve_cpu_ok() {
setup_and_render_template(TEMPLATE, &json!({"not-the-setting": "hi"})).unwrap();
assert!(true);
assert!(setup_and_render_template(TEMPLATE, &json!({"not-the-setting": "hi"})).is_ok());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions sources/api/schnauzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ LIST_UPPER=a1,a2,x,y,b1,.c1
list_lower=a1,a2,x,y,b1,.c1
"###;

let result = registry.render_template(&tmpl, &data).unwrap();
let result = registry.render_template(tmpl, &data).unwrap();
assert_eq!(result, expected);
}

Expand All @@ -178,7 +178,7 @@ y"###;
let expected = "x
y";

let result = registry.render_template(&tmpl, &data).unwrap();
let result = registry.render_template(tmpl, &data).unwrap();
assert_eq!(result, expected);
}
}
3 changes: 1 addition & 2 deletions sources/api/schnauzer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ If the returned value is "baz", our generated value will be "foo-baz".

#![deny(rust_2018_idioms)]

use constants;
use snafu::{ensure, OptionExt, ResultExt};
use std::collections::HashMap;
use std::string::String;
Expand Down Expand Up @@ -135,7 +134,7 @@ fn usage() -> ! {

/// Parses args for the setting key name.
fn parse_args(mut args: env::Args) -> String {
let arg = args.nth(1).unwrap_or_else(|| usage());
let arg = args.nth(1).unwrap_or_else(|| "--help".to_string());
if arg == "--help" || arg == "-h" {
usage()
}
Expand Down
2 changes: 1 addition & 1 deletion sources/bottlerocket-variant/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ fn parse_ok() {
];

for test in tests {
let parsed = Variant::new(test.input.clone()).unwrap();
let parsed = Variant::new(test.input).unwrap();
assert_eq!(parsed, test.input);
assert_eq!(test.input, parsed);
assert_eq!(parsed.platform(), test.platform.to_string());
Expand Down
5 changes: 2 additions & 3 deletions sources/imdsclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use tokio::time::{timeout, Duration};
use tokio_retry::{strategy::FibonacciBackoff, Retry};

const BASE_URI: &str = "http://169.254.169.254";
const PINNED_SCHEMA: &str = "2021-01-03";
const PINNED_SCHEMA: &str = "2021-07-15";

// Currently only able to get fetch session tokens from `latest`.
const SESSION_TARGET: &str = "latest/api/token";
Expand Down Expand Up @@ -146,8 +146,7 @@ impl ImdsClient {
let ipv6_address = self
.fetch_string(&ipv6_address_target)
.await?
.map(|ipv6_addresses| ipv6_addresses.lines().next().map(|s| s.to_string()))
.flatten();
.and_then(|ipv6_addresses| ipv6_addresses.lines().next().map(|s| s.to_string()));
Ok(ipv6_address)
}

Expand Down