Skip to content

Commit ca5cd1d

Browse files
authored
Merge pull request #773 from ecpullen/metal
Metal: Add metal k8s resource provider
2 parents 609fe27 + 8d2a1de commit ca5cd1d

File tree

20 files changed

+1076
-122
lines changed

20 files changed

+1076
-122
lines changed

Cargo.lock

Lines changed: 113 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,35 @@ COPY --from=build-src /usr/share/licenses/testsys /licenses/testsys
147147

148148
CMD dockerd --storage-driver vfs &>/dev/null & ./vsphere-k8s-cluster-resource-agent
149149

150+
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
151+
# Builds the Metal K8s cluster resource agent image
152+
FROM public.ecr.aws/amazonlinux/amazonlinux:2 as metal-k8s-cluster-resource-agent
153+
154+
RUN yum install -y \
155+
openssh-clients \
156+
tar \
157+
&& yum clean all
158+
RUN amazon-linux-extras install -y docker
159+
160+
# Copy eksctl
161+
COPY --from=tools /eksctl /usr/bin/eksctl
162+
COPY --from=tools /licenses/eksctl /licenses/eksctl
163+
164+
# Copy eksctl-anywhere
165+
COPY --from=tools /eksctl-anywhere /usr/bin/eksctl-anywhere
166+
COPY --from=tools /licenses/eksctl-anywhere /licenses/eksctl-anywhere
167+
168+
# Copy kubectl
169+
COPY --from=tools /kubectl /usr/local/bin/kubectl
170+
COPY --from=tools /licenses/kubernetes /licenses/kubernetes
171+
172+
# Copy binary
173+
COPY --from=build-src /src/bottlerocket/agents/bin/metal-k8s-cluster-resource-agent ./
174+
# Copy licenses
175+
COPY --from=build-src /usr/share/licenses/testsys /licenses/testsys
176+
177+
CMD dockerd --storage-driver vfs &>/dev/null & ./metal-k8s-cluster-resource-agent
178+
150179
# =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
151180
# Builds the ECS test agent image
152181
FROM public.ecr.aws/amazonlinux/amazonlinux:2 as ecs-test-agent

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TESTSYS_BUILD_GOPROXY ?= direct
2323
# to the project.
2424
IMAGES = controller sonobuoy-test-agent ec2-resource-agent eks-resource-agent ecs-resource-agent \
2525
migration-test-agent vsphere-vm-resource-agent vsphere-k8s-cluster-resource-agent ecs-test-agent \
26-
k8s-workload-agent ecs-workload-agent
26+
k8s-workload-agent ecs-workload-agent metal-k8s-cluster-resource-agent
2727

2828
# Store targets for tagging images
2929
TAG_IMAGES = $(addprefix tag-, $(IMAGES))
@@ -139,7 +139,7 @@ tools:
139139
./tools
140140

141141
# Build the container image for a testsys agent
142-
eks-resource-agent ec2-resource-agent ecs-resource-agent vsphere-vm-resource-agent vsphere-k8s-cluster-resource-agent sonobuoy-test-agent migration-test-agent ecs-test-agent k8s-workload-agent ecs-workload-agent: show-variables fetch
142+
eks-resource-agent ec2-resource-agent ecs-resource-agent vsphere-vm-resource-agent vsphere-k8s-cluster-resource-agent sonobuoy-test-agent migration-test-agent ecs-test-agent k8s-workload-agent ecs-workload-agent metal-k8s-cluster-resource-agent: show-variables fetch
143143
docker build $(DOCKER_BUILD_FLAGS) \
144144
--build-arg ARCH="$(TESTSYS_BUILD_HOST_UNAME_ARCH)" \
145145
--build-arg BUILDER_IMAGE="$(BUILDER_IMAGE)" \

agent/utils/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ agent-common = { version = "0.0.5", path = "../../agent/agent-common" }
1010
aws-config = "0.54"
1111
aws-credential-types = "0.54"
1212
aws-types = "0.54"
13+
aws-sdk-iam = "0.24"
14+
aws-sdk-ssm = "0.24"
1315
aws-sdk-sts = "0.24"
1416
aws-smithy-types = "0.54"
1517
base64 = "0.20"

agent/utils/src/error.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use aws_sdk_iam::error::{AttachRolePolicyError, CreateRoleError, GetRoleError};
2+
use aws_sdk_ssm::error::{CreateActivationError, DescribeInstanceInformationError};
13
use aws_sdk_sts::error::AssumeRoleError;
24
use aws_sdk_sts::types::SdkError;
35
use snafu::Snafu;
@@ -12,18 +14,61 @@ pub enum Error {
1214
source: SdkError<AssumeRoleError>,
1315
},
1416

17+
#[snafu(display(
18+
"Failed to attach policy '{}' to role '{}': {}",
19+
policy_arn,
20+
role_name,
21+
source
22+
))]
23+
AttachRolePolicy {
24+
role_name: String,
25+
policy_arn: String,
26+
source: SdkError<AttachRolePolicyError>,
27+
},
28+
1529
#[snafu(display("Failed to decode base64 blob: {}", source))]
1630
Base64Decode { source: base64::DecodeError },
1731

18-
#[snafu(display("Failed to setup environment variables: {}", what))]
19-
EnvSetup { what: String },
20-
2132
#[snafu(display("Could not convert '{}' secret to string: {}", what, source))]
2233
Conversion { what: String, source: FromUtf8Error },
2334

35+
#[snafu(display("Failed to send create SSM command: {}", source))]
36+
CreateSsmActivation {
37+
source: SdkError<CreateActivationError>,
38+
},
39+
40+
#[snafu(display(
41+
"Unable to create role '{}' with policy '{}': {}",
42+
role_name,
43+
role_policy,
44+
source
45+
))]
46+
CreateRole {
47+
role_name: String,
48+
role_policy: String,
49+
source: SdkError<CreateRoleError>,
50+
},
51+
2452
#[snafu(display("Credentials were missing for assumed role '{}'", role_arn))]
2553
CredentialsMissing { role_arn: String },
2654

55+
#[snafu(display("Failed to setup environment variables: {}", what))]
56+
EnvSetup { what: String },
57+
58+
#[snafu(display("Unable to get managed instance information: {}", source))]
59+
GetManagedInstanceInfo {
60+
source: SdkError<DescribeInstanceInformationError>,
61+
},
62+
63+
#[snafu(display("Unable to get SSM role '{}': {}", role_name, source))]
64+
GetSSMRole {
65+
role_name: String,
66+
source: SdkError<GetRoleError>,
67+
},
68+
69+
#[snafu(display("{} was missing from {}", what, from))]
70+
Missing { what: String, from: String },
71+
2772
#[snafu(display("Secret was missing: {}", source))]
2873
SecretMissing {
2974
source: agent_common::secrets::Error,
@@ -35,3 +80,5 @@ pub enum Error {
3580
source: std::io::Error,
3681
},
3782
}
83+
84+
pub type Result<T> = std::result::Result<T, Error>;

agent/utils/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::{env, fs};
1919
pub mod aws;
2020
pub mod constants;
2121
mod error;
22+
pub mod ssm;
2223

2324
/// Decode base64 blob and write to a file at the specified path
2425
pub async fn base64_decode_write_file(

0 commit comments

Comments
 (0)