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

pluto: don't error on missing settings #1783

Merged
merged 1 commit into from
Oct 21, 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
35 changes: 13 additions & 22 deletions sources/api/pluto/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::net::IpAddr;
pub(super) type Result<T> = std::result::Result<T, Error>;

pub(crate) struct AwsK8sInfo {
pub(crate) region: String,
pub(crate) cluster_name: String,
pub(crate) region: Option<String>,
pub(crate) cluster_name: Option<String>,
pub(crate) cluster_dns_ip: Option<IpAddr>,
}

Expand All @@ -16,8 +16,8 @@ pub(crate) struct AwsK8sInfo {
#[cfg(aws_k8s_variant)]
mod inner {
use super::*;
use snafu::{OptionExt, ResultExt, Snafu};
use constants;
use snafu::{ResultExt, Snafu};

#[derive(Debug, Snafu)]
pub(crate) enum Error {
Expand All @@ -27,9 +27,6 @@ mod inner {
uri: String,
},

#[snafu(display("The '{}' setting is missing", setting))]
Missing { setting: String },

#[snafu(display("Unable to deserialize Bottlerocket settings: {}", source))]
SettingsJson { source: serde_json::Error },
}
Expand All @@ -48,23 +45,17 @@ mod inner {
/// Gets the info that we need to know about the EKS cluster from the Bottlerocket API.
pub(crate) async fn get_aws_k8s_info() -> Result<AwsK8sInfo> {
let settings = get_settings().await?;
let kubernetes = settings.kubernetes.context(Missing {
setting: "kubernetes",
})?;
Ok(AwsK8sInfo {
region: settings
.aws
.context(Missing { setting: "aws" })?
.region
.context(Missing { setting: "region" })?
.into(),
cluster_name: kubernetes
.cluster_name
.context(Missing {
setting: "cluster-name",
})?
.into(),
cluster_dns_ip: kubernetes.cluster_dns_ip,
region: settings.aws.and_then(|a| a.region).map(|s| s.into()),
cluster_name: settings
.kubernetes
.as_ref()
.and_then(|k| k.cluster_name.clone())
.map(|s| s.into()),
cluster_dns_ip: settings
.kubernetes
.and_then(|k| k.cluster_dns_ip)
.map(|s| s.into()),
})
}
}
Expand Down
20 changes: 11 additions & 9 deletions sources/api/pluto/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,17 @@ async fn get_max_pods(client: &mut ImdsClient) -> Result<String> {
async fn get_cluster_dns_ip(client: &mut ImdsClient) -> Result<String> {
// Retrieve the kubernetes network configuration for the EKS cluster
if let Ok(aws_k8s_info) = api::get_aws_k8s_info().await.context(error::AwsInfo) {
if let Ok(config) =
eks::get_cluster_network_config(&aws_k8s_info.region, &aws_k8s_info.cluster_name)
if let (Some(region), Some(cluster_name)) = (aws_k8s_info.region, aws_k8s_info.cluster_name)
{
if let Ok(config) = eks::get_cluster_network_config(&region, &cluster_name)
.await
.context(error::EksError)
{
// Derive cluster-dns-ip from the service IPv4 CIDR
if let Some(ipv4_cidr) = config.service_ipv_4_cidr {
if let Ok(dns_ip) = get_dns_from_ipv4_cidr(&ipv4_cidr) {
return Ok(dns_ip);
{
// Derive cluster-dns-ip from the service IPv4 CIDR
if let Some(ipv4_cidr) = config.service_ipv_4_cidr {
if let Ok(dns_ip) = get_dns_from_ipv4_cidr(&ipv4_cidr) {
return Ok(dns_ip);
}
}
}
}
Expand Down Expand Up @@ -273,13 +275,13 @@ async fn get_node_ip(client: &mut ImdsClient) -> Result<String> {
what: "node ipv4 address",
}),
IpAddr::V6(_) => {
return Ok(client
return client
.fetch_primary_ipv6_address()
.await
.context(error::ImdsRequest)?
.context(error::ImdsNone {
what: "ipv6s associated with primary network interface",
})?);
});
}
}
}
Expand Down