Skip to content

Commit

Permalink
agents: add endpoint override support in eks provider
Browse files Browse the repository at this point in the history
We add a configuration in EKS cluster resource agent to allow EKS
service endpoint override when querying cluster information for a
pre-existing cluster.
  • Loading branch information
etungsten committed Sep 8, 2023
1 parent da0d8fe commit 7f11d54
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 7 deletions.
18 changes: 14 additions & 4 deletions agent/utils/src/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub async fn aws_config(
assume_role: &Option<String>,
assume_role_session_duration: &Option<i32>,
region: &Option<String>,
endpoint_url: Option<String>,
setup_env: bool,
) -> Result<SdkConfig, Error> {
let region = region
Expand Down Expand Up @@ -70,10 +71,19 @@ pub async fn aws_config(
None => config_loader.credentials_provider(base_provider),
};

let config = config_loader
.region(Region::new(region.clone()))
.load()
.await;
let config = if let Some(endpoint) = endpoint_url {
config_loader
.region(Region::new(region.clone()))
.endpoint_url(endpoint)
.load()
.await
} else {
config_loader
.region(Region::new(region.clone()))
.load()
.await
};

if let (Some(role_arn), true) = (assume_role, setup_env) {
info!("Getting credentials for assumed role '{}'.", role_arn);
let sts_client = aws_sdk_sts::Client::new(&config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl Create for Ec2KarpenterCreator {
&spec.configuration.assume_role,
&None,
&Some(spec.configuration.region.clone()),
None,
true,
)
.await
Expand Down Expand Up @@ -908,6 +909,7 @@ impl Destroy for Ec2KarpenterDestroyer {
&spec.configuration.assume_role,
&None,
&Some(spec.configuration.region.clone()),
None,
true,
)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl Create for Ec2Creator {
&spec.configuration.assume_role,
&None,
&Some(spec.configuration.region.clone()),
None,
false,
)
.await
Expand Down Expand Up @@ -726,6 +727,7 @@ impl Destroy for Ec2Destroyer {
&memo.assume_role,
&None,
&Some(memo.region.clone()),
None,
false,
)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl Create for EcsCreator {
&spec.configuration.assume_role,
&None,
&spec.configuration.region,
None,
false,
)
.await
Expand Down Expand Up @@ -376,6 +377,7 @@ impl Destroy for EcsDestroyer {
&memo.assume_role,
&None,
&memo.region,
None,
false,
)
.await
Expand Down
1 change: 1 addition & 0 deletions bottlerocket/agents/src/bin/ecs-test-agent/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ where
&self.config.assume_role,
&None,
&self.config.region,
None,
false,
)
.await?;
Expand Down
1 change: 1 addition & 0 deletions bottlerocket/agents/src/bin/ecs-workload-agent/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ where
&self.config.assume_role,
&None,
&self.config.region,
None,
false,
)
.await?;
Expand Down
20 changes: 17 additions & 3 deletions bottlerocket/agents/src/bin/eks-resource-agent/eks_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ struct AwsClients {
}

impl AwsClients {
async fn new(shared_config: &SdkConfig) -> Self {
async fn new(shared_config: &SdkConfig, eks_config: &SdkConfig) -> Self {
Self {
eks_client: aws_sdk_eks::Client::new(shared_config),
eks_client: aws_sdk_eks::Client::new(eks_config),
ec2_client: aws_sdk_ec2::Client::new(shared_config),
iam_client: aws_sdk_iam::Client::new(shared_config),
cfn_client: aws_sdk_cloudformation::Client::new(shared_config),
Expand Down Expand Up @@ -336,11 +336,24 @@ impl Create for EksCreator {
&spec.configuration.assume_role,
&None,
&Some(cluster_config.region()),
None,
true,
)
.await
.context(Resources::Clear, "Error creating config")?;
let aws_clients = AwsClients::new(&shared_config).await;

let eks_sdk_config = aws_config(
&spec.secrets.get(AWS_CREDENTIALS_SECRET_NAME),
&spec.configuration.assume_role,
&None,
&Some(cluster_config.region()),
spec.configuration.eks_endpoint_url,
true,
)
.await
.context(Resources::Clear, "Error creating EKS client config")?;

let aws_clients = AwsClients::new(&shared_config, &eks_sdk_config).await;

info!("Determining cluster state");
memo.current_status = "Determining cluster state".to_string();
Expand Down Expand Up @@ -867,6 +880,7 @@ impl Destroy for EksDestroyer {
&memo.assume_role,
&None,
&memo.region.clone(),
None,
true,
)
.await
Expand Down
1 change: 1 addition & 0 deletions bottlerocket/agents/src/bin/k8s-workload-agent/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ where
&self.config.assume_role,
&None,
&None,
None,
true,
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl Create for MetalK8sClusterCreator {
&spec.configuration.assume_role,
&None,
&None,
None,
false,
)
.await
Expand Down Expand Up @@ -484,6 +485,7 @@ impl Destroy for MetalK8sClusterDestroyer {
&memo.assume_role,
&None,
&None,
None,
false,
)
.await
Expand Down
1 change: 1 addition & 0 deletions bottlerocket/agents/src/bin/migration-test-agent/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ where
&self.config.assume_role,
&None,
&Some(self.config.aws_region.clone()),
None,
false,
)
.await?;
Expand Down
2 changes: 2 additions & 0 deletions bottlerocket/agents/src/bin/sonobuoy-test-agent/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ where
&self.config.assume_role,
&None,
&None,
None,
true,
)
.await?;
Expand Down Expand Up @@ -114,6 +115,7 @@ where
&self.config.assume_role,
&None,
&None,
None,
true,
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl Create for VMCreator {
&spec.configuration.assume_role,
&None,
&None,
None,
false,
)
.await
Expand Down Expand Up @@ -607,6 +608,7 @@ impl Destroy for VMDestroyer {
&memo.assume_role,
&None,
&None,
None,
false,
)
.await
Expand Down
5 changes: 5 additions & 0 deletions bottlerocket/types/src/agent_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ pub struct EksClusterConfig {
/// The role that should be assumed when creating the cluster.
pub assume_role: Option<String>,

/// The endpoint to create the EKS client with.
/// This only applicable when the cluster already exists at some EKS service endpoint, and we'd
/// like to retrieve its details.
pub eks_endpoint_url: Option<String>,

#[serde(flatten)]
pub config: EksctlConfig,
}
Expand Down

0 comments on commit 7f11d54

Please sign in to comment.