mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Properly get return value (considering errexit). Quote variables.
This commit is contained in:
parent
d4d02a9028
commit
eb220f05a6
@ -354,7 +354,7 @@ function ensure-iam-profiles {
|
|||||||
function wait-for-instance-running {
|
function wait-for-instance-running {
|
||||||
instance_id=$1
|
instance_id=$1
|
||||||
while true; do
|
while true; do
|
||||||
instance_state=$($AWS_CMD describe-instances --instance-ids $instance_id | expect_instance_states running)
|
instance_state=$($AWS_CMD describe-instances --instance-ids ${instance_id} | expect_instance_states running)
|
||||||
if [[ "$instance_state" == "" ]]; then
|
if [[ "$instance_state" == "" ]]; then
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
@ -365,6 +365,8 @@ function wait-for-instance-running {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Allocates new Elastic IP from Amazon
|
||||||
|
# Output: allocated IP address
|
||||||
function allocate-elastic-ip {
|
function allocate-elastic-ip {
|
||||||
$AWS_CMD allocate-address --domain vpc --output text | cut -f3
|
$AWS_CMD allocate-address --domain vpc --output text | cut -f3
|
||||||
}
|
}
|
||||||
@ -372,23 +374,29 @@ function allocate-elastic-ip {
|
|||||||
function assign-ip-to-instance {
|
function assign-ip-to-instance {
|
||||||
local ip_address=$1
|
local ip_address=$1
|
||||||
local instance_id=$2
|
local instance_id=$2
|
||||||
local elastic_ip_allocation_id=$($AWS_CMD describe-addresses --public-ips $ip_address --output text | cut -f2)
|
local fallback_ip=$3
|
||||||
$AWS_CMD associate-address --instance-id $master_instance_id --allocation-id $elastic_ip_allocation_id > /dev/null
|
|
||||||
local association_result=$?
|
|
||||||
|
|
||||||
if [[ $association_result -eq 0 ]]; then
|
local elastic_ip_allocation_id=$($AWS_CMD describe-addresses --public-ips $ip_address --output text | cut -f2)
|
||||||
echo $ip_address
|
local association_result=$($AWS_CMD associate-address --instance-id ${master_instance_id} --allocation-id ${elastic_ip_allocation_id} > /dev/null && echo "success" || echo "failure")
|
||||||
|
|
||||||
|
if [[ $association_result = "success" ]]; then
|
||||||
|
echo "${ip_address}"
|
||||||
|
else
|
||||||
|
echo "${fallback_ip}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Assigns elastic ip to a Amazon EC2 instance. If assigned public IP is empty,
|
||||||
|
# then will request new one.
|
||||||
|
# Output: assigned IP address
|
||||||
function assign-elastic-ip {
|
function assign-elastic-ip {
|
||||||
local assigned_public_ip=$1
|
local assigned_public_ip=$1
|
||||||
local master_instance_id=$2
|
local master_instance_id=$2
|
||||||
|
|
||||||
if [[ -n $MASTER_RESERVED_IP ]]; then
|
if [[ -n "${MASTER_RESERVED_IP}" ]]; then
|
||||||
assign-ip-to-instance $MASTER_RESERVED_IP $master_instance_id
|
assign-ip-to-instance "${MASTER_RESERVED_IP}" "${master_instance_id}" "${assigned_public_ip}"
|
||||||
else
|
else
|
||||||
assign-ip-to-instance $(allocate-elastic-ip) $master_instance_id
|
assign-ip-to-instance $(allocate-elastic-ip) "${master_instance_id}" "${assigned_public_ip}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user