Skip to content

Commit c639998

Browse files
committed
Set AWS environment variables to access AWS resources
Signed-off-by: Wenqi Qiu <[email protected]>
1 parent 61f55bb commit c639998

File tree

2 files changed

+29
-48
lines changed

2 files changed

+29
-48
lines changed

ci/test-conformance-eks.sh

+15-29
Original file line numberDiff line numberDiff line change
@@ -187,35 +187,21 @@ function setup_eks() {
187187
aws --version
188188

189189
set +e
190-
if [[ "$AWS_SERVICE_USER_ROLE_ARN" != "" ]] && [[ "$AWS_SERVICE_USER_NAME" != "" ]]; then
191-
mkdir -p ~/.aws
192-
cat > ~/.aws/config <<EOF
193-
[default]
194-
region = $REGION
195-
role_arn = $AWS_SERVICE_USER_ROLE_ARN
196-
source_profile = $AWS_SERVICE_USER_NAME
197-
output = json
198-
EOF
199-
cat > ~/.aws/credentials <<EOF
200-
[$AWS_SERVICE_USER_NAME]
201-
aws_access_key_id = $AWS_ACCESS_KEY
202-
aws_secret_access_key = $AWS_SECRET_KEY
203-
EOF
204-
elif [[ "$AWS_SERVICE_USER_ROLE_ARN" = "" ]] && [[ "$AWS_SERVICE_USER_NAME" = "" ]]; then
205-
mkdir -p ~/.aws
206-
cat > ~/.aws/config <<EOF
207-
[default]
208-
region = $REGION
209-
output = json
210-
EOF
211-
cat > ~/.aws/credentials <<EOF
212-
[default]
213-
aws_access_key_id = $AWS_ACCESS_KEY
214-
aws_secret_access_key = $AWS_SECRET_KEY
215-
EOF
216-
else
217-
echo "Invalid input either specify both aws-service-user-role-arn and aws-service-user or none."
218-
exit 1
190+
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY
191+
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_KEY
192+
193+
export AWS_DEFAULT_OUTPUT=json
194+
export AWS_DEFAULT_REGION=$REGION
195+
if [[ "$AWS_SERVICE_USER_ROLE_ARN" != "" ]]; then
196+
TEMP_CRED=$(aws sts assume-role \
197+
--role-arn "$AWS_SERVICE_USER_ROLE_ARN" \
198+
--role-session-name "cli-session" \
199+
--query "Credentials" \
200+
--output json)
201+
202+
export AWS_ACCESS_KEY_ID=$(echo "$TEMP_CRED" | jq -r .AccessKeyId)
203+
export AWS_SECRET_ACCESS_KEY=$(echo "$TEMP_CRED" | jq -r .SecretAccessKey)
204+
export AWS_SESSION_TOKEN=$(echo "$TEMP_CRED" | jq -r .SessionToken)
219205
fi
220206

221207
if [[ "$INSTALL_EKSCTL" == true ]]; then

ci/test-sriov-secondary-network-aws.sh

+14-19
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ SUBNET_CIDR_RES_ID="${SUBNET_CIDR_RES_ID:-}"
3535
_usage="Usage: $0 [--aws-access-key <AccessKey>] [--aws-secret-key <SecretKey>] \
3636
[--aws-security-group-id <SecurityGroupID>] [--aws-subnet-id <SubnetID>] \
3737
[--aws-ec2-ssh-key-name <SSHKeyName>]
38-
[--aws-service-user-role-arn <ServiceUserRoleARN>] [--aws-service-user <ServiceUserName>] \
38+
[--aws-service-user-role-arn <ServiceUserRoleARN>] \
3939
[--aws-region <Region>] [--k8s-version <ClusterVersion>]
4040
4141
Setup a Kubernetes cluster and test SR-IOV secondary network in AWS.
@@ -46,7 +46,6 @@ Setup a Kubernetes cluster and test SR-IOV secondary network in AWS.
4646
--aws-subnet-id The subnet in which the ec2 instance network interface is located.
4747
--aws-ec2-ssh-key-name The key name to be used for ssh access to ec2 instances.
4848
--aws-service-user-role-arn AWS Service User Role ARN for logging in to awscli.
49-
--aws-service-user AWS Service User Name for logging in to awscli.
5049
--aws-region The AWS region where the cluster will be initiated. Defaults to $REGION.
5150
--setup-only Only perform setting up the cluster and run test.
5251
--cleanup-only Only perform cleaning up the cluster.
@@ -89,10 +88,6 @@ case $key in
8988
AWS_SERVICE_USER_ROLE_ARN="$2"
9089
shift 2
9190
;;
92-
--aws-service-user)
93-
AWS_SERVICE_USER_NAME="$2"
94-
shift 2
95-
;;
9691
--aws-region)
9792
REGION="$2"
9893
shift 2
@@ -122,19 +117,19 @@ case $key in
122117
esac
123118
done
124119

125-
mkdir -p ~/.aws
126-
cat > ~/.aws/config <<EOF
127-
[default]
128-
region = $REGION
129-
role_arn = $AWS_SERVICE_USER_ROLE_ARN
130-
source_profile = $AWS_SERVICE_USER_NAME
131-
output = json
132-
EOF
133-
cat > ~/.aws/credentials <<EOF
134-
[$AWS_SERVICE_USER_NAME]
135-
aws_access_key_id = $AWS_ACCESS_KEY
136-
aws_secret_access_key = $AWS_SECRET_KEY
137-
EOF
120+
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY
121+
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_KEY
122+
export AWS_DEFAULT_REGION=$REGION
123+
124+
TEMP_CRED=$(aws sts assume-role \
125+
--role-arn "$AWS_SERVICE_USER_ROLE_ARN" \
126+
--role-session-name "cli-session" \
127+
--query "Credentials" \
128+
--output json)
129+
130+
export AWS_ACCESS_KEY_ID=$(echo "$TEMP_CRED" | jq -r .AccessKeyId)
131+
export AWS_SECRET_ACCESS_KEY=$(echo "$TEMP_CRED" | jq -r .SecretAccessKey)
132+
export AWS_SESSION_TOKEN=$(echo "$TEMP_CRED" | jq -r .SessionToken)
138133

139134
THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
140135
ANTREA_CHART="$THIS_DIR/../build/charts/antrea"

0 commit comments

Comments
 (0)