diff --git a/tools/k8s/mkllb-url b/tools/k8s/mkllb-url index f76900128..3e73753d7 100755 --- a/tools/k8s/mkllb-url +++ b/tools/k8s/mkllb-url @@ -1,11 +1,11 @@ #!/bin/bash usage() { - echo "Usage: $0 -a -z -t " - echo " $0 -a -z -t -x" + echo "Usage: $0 -a -z -t -c " + echo " $0 -a -z -t -c -x" } -if [[ $# -gt 7 ]] || [[ $# -lt 6 ]]; then +if [[ $# -gt 9 ]] || [[ $# -lt 6 ]]; then usage exit fi @@ -18,23 +18,36 @@ if [[ ! -f /usr/local/sbin/kubectl ]]; then fi addr="" +cloud="bm" zone="llb" utype="default" cmd="apply" -while getopts a:z:t:x opt +while getopts a:z:t:c:x opt do case "${opt}" in a) addr=${OPTARG};; z) zone=${OPTARG};; t) utype=${OPTARG};; x) cmd="delete";; + c) cloud=${OPTARG};; ?) usage;exit;; esac done url="http://${addr}:11111" +laddr=${addr} +if [[ ${cloud} == "aws" ]]; then + if [[ ! -f /usr/local/bin/aws ]]; then + apt install -y unzip + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" + unzip awscliv2.zip && ./aws/install + fi + token=`curl -m 10 -X PUT http://169.254.169.254/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && \ + addr=`curl -m 10 -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/meta-data/public-ipv4` +fi + if [[ ${utype} == "hostcidr" ]]; then url=${addr} fi @@ -42,6 +55,7 @@ fi echo "============" echo "Applying CRD" echo "============" +echo name llb-${laddr} echo url $url echo zone $zone echo utype $utype @@ -52,7 +66,7 @@ cat <