Skip to content

Commit bb01a0c

Browse files
Add ssh key to launch template for Nodegroups to help debug
1 parent b6aaee1 commit bb01a0c

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

tests/assets/eks_node_group_launch_template.json

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"ClusterName": {
1010
"Type": "String",
1111
"Description": "Name of the Cluster"
12+
},
13+
"SSHKeyName": {
14+
"Type": "String",
15+
"Description": "SSH Key Name for EC2 instances"
1216
}
1317
},
1418
"Resources": {
@@ -17,6 +21,7 @@
1721
"Properties": {
1822
"LaunchTemplateName": { "Ref": "LaunchTemplateName" },
1923
"LaunchTemplateData": {
24+
"KeyName": { "Ref": "SSHKeyName" },
2025
"BlockDeviceMappings": [
2126
{
2227
"DeviceName": "/dev/xvda",

tests/tasks/setup/eks/awscli-cfn-lt.yaml

+16-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,21 @@ spec:
4141
fi
4242
4343
curl -s $(params.ng-cfn-url) -o ./amazon-ng-cfn
44-
44+
45+
SSH_KEY_NAME=scaletest-$(params.region)-nodegroups-ssh-key
46+
KEY_EXISTS=$(aws ec2 --region $(params.region) describe-key-pairs --key-names $SSH_KEY_NAME --query 'KeyPairs[0].KeyName' --output text)
47+
48+
if [[ "$KEY_EXISTS" == "None" ]]; then
49+
echo "KeyPair not found"
50+
rm -f $HOME/.ssh/$SSH_KEY_NAME.pem
51+
# Create the key pair and store it
52+
aws ec2 create-key-pair --region $(params.region) --key-name $SSH_KEY_NAME --query 'KeyMaterial' --output text > $HOME/.ssh/$SSH_KEY_NAME.pem
53+
chmod 400 $HOME/.ssh/$SSH_KEY_NAME.pem
54+
ssh-add -k $HOME/.ssh/$SSH_KEY_NAME.pem
55+
else
56+
echo "KeyPair already exists"
57+
fi
58+
4559
launch_template_name=$(params.cluster-name)-launchTemplate
4660
STACK_NAME=$(params.stack-name)
4761
STACK_STATUS=$(aws cloudformation describe-stacks --query 'Stacks[?StackName==`'${STACK_NAME}'`].StackStatus' --output text --region $(params.region))
@@ -52,6 +66,7 @@ spec:
5266
--template-body file://$(pwd)/amazon-ng-cfn \
5367
--parameters ParameterKey=LaunchTemplateName,ParameterValue=$launch_template_name\
5468
ParameterKey=ClusterName,ParameterValue=$(params.cluster-name)\
69+
ParameterKey=SSHKeyName,ParameterValue=$SSH_KEY_NAME\
5570
--region $(params.region)
5671
5772
aws cloudformation wait stack-create-complete --stack-name $STACK_NAME --region $(params.region)

tests/tasks/setup/eks/awscli-mng.yaml

-12
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@ spec:
6969
asgs=$((nodes/max_nodes))
7070
echo "asgs: $asgs"
7171
node_group=$(params.nodegroup-prefix)$(params.cluster-name)-nodes
72-
SSH_KEY_NAME=scaletest-$(params.region)-nodegroups-ssh-key
73-
if [[ "$(aws ec2 --region $(params.region) describe-key-pairs --key-names $SSH_KEY_NAME --query 'KeyPairs[?KeyName==`'$SSH_KEY_NAME'`].KeyName' --output text)" -eq 0 ]];
74-
then
75-
echo "KeyPair not found";
76-
rm -f $HOME/.ssh/$SSH_KEY_NAME.pem
77-
aws ec2 create-key-pair --region $(params.region) --key-name $SSH_KEY_NAME --query 'KeyMaterial' --output text > $HOME/.ssh/$SSH_KEY_NAME.pem
78-
chmod 400 $HOME/.ssh/$SSH_KEY_NAME.pem
79-
ssh-add -k $HOME/.ssh/$SSH_KEY_NAME.pem
80-
else
81-
echo "KeyPair already exists";
82-
fi
8372
create_and_validate_dp_nodes()
8473
{
8574
node_group_name=$node_group-$1
@@ -96,7 +85,6 @@ spec:
9685
--region $(params.region) \
9786
--instance-types $EC2_INSTANCES \
9887
--scaling-config minSize=$(params.min-nodes),maxSize=$2,desiredSize=$2 \
99-
--remote-access ec2SshKey=$SSH_KEY_NAME \
10088
--subnets $NG_SUBNETS $TAINTS_FLAG
10189
fi
10290
echo "CREATED_NODEGROUP=$node_group_name"

0 commit comments

Comments
 (0)