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

imdsclient: better retries with tokio retry and timeout #1841

Merged
merged 2 commits into from
Dec 15, 2021
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
12 changes: 12 additions & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sources/api/early-boot-config/src/provider/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl PlatformDataProvider for AwsDataProvider {
) -> std::result::Result<Vec<SettingsJson>, Box<dyn std::error::Error>> {
let mut output = Vec::new();

let mut client = ImdsClient::new().await.context(error::ImdsClient)?;
let mut client = ImdsClient::new();

// Attempt to read from local file first on the `aws-dev` variant
#[cfg(bottlerocket_platform = "aws-dev")]
Expand Down
2 changes: 1 addition & 1 deletion sources/api/pluto/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ fn parse_args(mut args: env::Args) -> String {

async fn run() -> Result<()> {
let setting_name = parse_args(env::args());
let mut client = ImdsClient::new().await.context(error::ImdsClient)?;
let mut client = ImdsClient::new();

let setting = match setting_name.as_ref() {
"cluster-dns-ip" => get_cluster_dns_ip(&mut client).await,
Expand Down
2 changes: 1 addition & 1 deletion sources/api/shibaken/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl UserData {
/// Returns a list of public keys.
async fn fetch_public_keys_from_imds() -> Result<Vec<String>> {
info!("Connecting to IMDS");
let mut client = ImdsClient::new().await.context(error::ImdsClient)?;
let mut client = ImdsClient::new();
let public_keys = client
.fetch_public_ssh_keys()
.await
Expand Down
1 change: 1 addition & 0 deletions sources/imdsclient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ reqwest = { version = "0.11.1", default-features = false }
serde_json = "1"
snafu = "0.6"
tokio = { version = "~1.8", default-features = false, features = ["macros", "rt-multi-thread", "time"] } # LTS
tokio-retry = "0.3"
url = "2.1.1"

[build-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions sources/imdsclient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Current version: 0.1.0

The library uses IMDSv2 (session-oriented) requests over a pinned schema to guarantee compatibility.
Session tokens are fetched automatically and refreshed if the request receives a `401` response.
If an IMDS token fetch or query fails, the library will continue to retry with a fibonacci backoff
strategy until it is successful or times out. The default timeout is 300s to match the ifup timeout
set in wicked.service, but can configured using `.with_timeout` during client creation.

Each public method is explicitly targeted and return either bytes or a `String`.

Expand Down
Loading