Skip to content

Commit

Permalink
Add ssh key to launch template for Nodegroups to help debug
Browse files Browse the repository at this point in the history
  • Loading branch information
hakuna-matatah committed Dec 10, 2024
1 parent b6aaee1 commit 3400879
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
5 changes: 5 additions & 0 deletions tests/assets/eks_node_group_launch_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"ClusterName": {
"Type": "String",
"Description": "Name of the Cluster"
},
"SSHKeyName": {
"Type": "String",
"Description": "SSH Key Name for EC2 instances"
}
},
"Resources": {
Expand All @@ -17,6 +21,7 @@
"Properties": {
"LaunchTemplateName": { "Ref": "LaunchTemplateName" },
"LaunchTemplateData": {
"KeyName": { "Ref": "SSHKeyName" },
"BlockDeviceMappings": [
{
"DeviceName": "/dev/xvda",
Expand Down
15 changes: 14 additions & 1 deletion tests/tasks/setup/eks/awscli-cfn-lt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,19 @@ spec:
fi
curl -s $(params.ng-cfn-url) -o ./amazon-ng-cfn
SSH_KEY_NAME=scaletest-$(params.region)-nodegroups-ssh-key
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 ]];
then
echo "KeyPair not found";
rm -f $HOME/.ssh/$SSH_KEY_NAME.pem
aws ec2 create-key-pair --region $(params.region) --key-name $SSH_KEY_NAME --query 'KeyMaterial' --output text > $HOME/.ssh/$SSH_KEY_NAME.pem
chmod 400 $HOME/.ssh/$SSH_KEY_NAME.pem
ssh-add -k $HOME/.ssh/$SSH_KEY_NAME.pem
else
echo "KeyPair already exists";
fi
launch_template_name=$(params.cluster-name)-launchTemplate
STACK_NAME=$(params.stack-name)
STACK_STATUS=$(aws cloudformation describe-stacks --query 'Stacks[?StackName==`'${STACK_NAME}'`].StackStatus' --output text --region $(params.region))
Expand All @@ -52,6 +64,7 @@ spec:
--template-body file://$(pwd)/amazon-ng-cfn \
--parameters ParameterKey=LaunchTemplateName,ParameterValue=$launch_template_name\
ParameterKey=ClusterName,ParameterValue=$(params.cluster-name)\
ParameterKey=SSHKeyName,ParameterValue=$SSH_KEY_NAME\
--region $(params.region)
aws cloudformation wait stack-create-complete --stack-name $STACK_NAME --region $(params.region)
Expand Down
12 changes: 0 additions & 12 deletions tests/tasks/setup/eks/awscli-mng.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,6 @@ spec:
asgs=$((nodes/max_nodes))
echo "asgs: $asgs"
node_group=$(params.nodegroup-prefix)$(params.cluster-name)-nodes
SSH_KEY_NAME=scaletest-$(params.region)-nodegroups-ssh-key
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 ]];
then
echo "KeyPair not found";
rm -f $HOME/.ssh/$SSH_KEY_NAME.pem
aws ec2 create-key-pair --region $(params.region) --key-name $SSH_KEY_NAME --query 'KeyMaterial' --output text > $HOME/.ssh/$SSH_KEY_NAME.pem
chmod 400 $HOME/.ssh/$SSH_KEY_NAME.pem
ssh-add -k $HOME/.ssh/$SSH_KEY_NAME.pem
else
echo "KeyPair already exists";
fi
create_and_validate_dp_nodes()
{
node_group_name=$node_group-$1
Expand All @@ -96,7 +85,6 @@ spec:
--region $(params.region) \
--instance-types $EC2_INSTANCES \
--scaling-config minSize=$(params.min-nodes),maxSize=$2,desiredSize=$2 \
--remote-access ec2SshKey=$SSH_KEY_NAME \
--subnets $NG_SUBNETS $TAINTS_FLAG
fi
echo "CREATED_NODEGROUP=$node_group_name"
Expand Down

0 comments on commit 3400879

Please sign in to comment.