From 34008798efde5634cdaf1970e36f50def11a2194 Mon Sep 17 00:00:00 2001 From: hakuna-matatah Date: Mon, 9 Dec 2024 21:02:29 -0800 Subject: [PATCH] Add ssh key to launch template for Nodegroups to help debug --- tests/assets/eks_node_group_launch_template.json | 5 +++++ tests/tasks/setup/eks/awscli-cfn-lt.yaml | 15 ++++++++++++++- tests/tasks/setup/eks/awscli-mng.yaml | 12 ------------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/tests/assets/eks_node_group_launch_template.json b/tests/assets/eks_node_group_launch_template.json index 1ed63b43..8f15b0d1 100644 --- a/tests/assets/eks_node_group_launch_template.json +++ b/tests/assets/eks_node_group_launch_template.json @@ -9,6 +9,10 @@ "ClusterName": { "Type": "String", "Description": "Name of the Cluster" + }, + "SSHKeyName": { + "Type": "String", + "Description": "SSH Key Name for EC2 instances" } }, "Resources": { @@ -17,6 +21,7 @@ "Properties": { "LaunchTemplateName": { "Ref": "LaunchTemplateName" }, "LaunchTemplateData": { + "KeyName": { "Ref": "SSHKeyName" }, "BlockDeviceMappings": [ { "DeviceName": "/dev/xvda", diff --git a/tests/tasks/setup/eks/awscli-cfn-lt.yaml b/tests/tasks/setup/eks/awscli-cfn-lt.yaml index dcb512b0..7f427f12 100644 --- a/tests/tasks/setup/eks/awscli-cfn-lt.yaml +++ b/tests/tasks/setup/eks/awscli-cfn-lt.yaml @@ -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)) @@ -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) diff --git a/tests/tasks/setup/eks/awscli-mng.yaml b/tests/tasks/setup/eks/awscli-mng.yaml index 13c40eea..be38065d 100644 --- a/tests/tasks/setup/eks/awscli-mng.yaml +++ b/tests/tasks/setup/eks/awscli-mng.yaml @@ -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 @@ -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"