-
Notifications
You must be signed in to change notification settings - Fork 12
/
adjust-single-node-4.16.sh
executable file
Β·667 lines (611 loc) Β· 22.5 KB
/
adjust-single-node-4.16.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
#!/bin/bash
# -*- coding: UTF-8 -*-
# aws cli v2 - https://github.com/aws/aws-cli/issues/4992
export AWS_PAGER=""
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[38;5;214m'
NC='\033[0m' # No Color
# env vars
DRYRUN=${DRYRUN:-}
BASE_DOMAIN=${BASE_DOMAIN:-}
CLUSTER_NAME=${CLUSTER_NAME:-}
# prog vars
region=
instance_id=
vpc_id=
master_sg=
eip=
eip_alloc=
public_route_table_id=
private_route_table_id=
public_hosted_zone=
private_hosted_zone=
private_instance_ip=
nat_gateways=
network_load_balancers=
router_load_balancer=
zones=
find_region() {
if [ ! -z "$AWS_DEFAULT_REGION" ]; then
region="$AWS_DEFAULT_REGION"
else
region=$(aws configure get region)
fi
if [ -z "$region" ]; then
echo -e "π±${RED}Failed - could not find aws region ?${NC}"
exit 1
else
echo "π΄ Region set to $region"
fi
}
find_instance_id() {
local tag_value="$1"
instance_id=$(aws ec2 describe-instances \
--region=${region} \
--query "Reservations[].Instances[].InstanceId" \
--filters "Name=tag-value,Values=$tag_value" "Name=instance-state-name,Values=running" \
--output text)
if [ -z "$instance_id" ]; then
echo -e "π±${RED}Failed - could not find instance id associated with tag: $tag_value ?${NC}"
exit 1
else
echo "π΄ InstanceId set to $instance_id"
fi
}
find_vpc_id() {
local tag_value="$1"
vpc_id=$(aws ec2 describe-vpcs --region=${region} \
--query "Vpcs[].VpcId" \
--filters "Name=tag-value,Values=$tag_value" \
--output text)
if [ -z "$vpc_id" ]; then
echo -e "π±${RED}Failed - could not find vpc id associated with tag: $tag_value ?${NC}"
exit 1
else
echo "π΄ VpcId set to $vpc_id"
fi
}
find_master_sg() {
tag_value="$CLUSTER_NAME-*-master"
master_sg=$(aws ec2 describe-security-groups \
--region=${region} \
--query "SecurityGroups[].GroupId" \
--filters "Name=vpc-id,Values=${vpc_id}" \
--filters "Name=tag-value,Values=$tag_value" \
--output text)
if [ -z $master_sg ]; then
tag_value="$CLUSTER_NAME-*-node"
master_sg=$(aws ec2 describe-security-groups \
--region=${region} \
--query "SecurityGroups[].GroupId" \
--filters "Name=vpc-id,Values=${vpc_id}" \
--filters "Name=tag-value,Values=$tag_value" \
--output text)
fi
if [ -z $master_sg ]; then
echo -e "π±${RED}Failed - could not find master/node security group associated with vpc: $vpc_id and tag: $tag_value ?${NC}"
exit 1
else
echo "π΄ MasterSecurityGroup set to $master_sg"
fi
}
update_master_sg() {
set -o pipefail
# update master security group: allow 6443 (tcp)
aws ec2 authorize-security-group-ingress \
--region=${region} \
${DRYRUN:---dry-run} \
--group-id ${master_sg} \
--ip-permissions '[{"IpProtocol": "tcp", "FromPort": 6443, "ToPort":6443, "IpRanges": [{"CidrIp": "0.0.0.0/0","Description": "sno-100"}]}]' \
--tag-specifications "ResourceType=security-group-rule,Tags=[{Key=sno-100,Value=sno-100}]" 2>&1 | tee /tmp/aws-error-file
if [ "$?" != 0 ]; then
if egrep -q "InvalidPermission.Duplicate|DryRunOperation" /tmp/aws-error-file; then
echo -e "${GREEN}Ignoring - master security group rule already exists or dry-run set ?${NC}"
else
echo -e "π±${RED}Failed - problem authorizing master securty group setting ?${NC}"
exit 1
fi
fi
# update master security group: allow 30000 to 32767 (tcp & udp) from 0.0.0.0/0 for nodeport services
aws ec2 authorize-security-group-ingress \
--region=${region} \
${DRYRUN:---dry-run} \
--group-id ${master_sg} \
--ip-permissions '[{"IpProtocol": "tcp", "FromPort": 30000, "ToPort":32767, "IpRanges": [{"CidrIp": "0.0.0.0/0","Description": "sno-100"}]},{"IpProtocol": "udp", "FromPort": 30000, "ToPort":32767, "IpRanges": [{"CidrIp": "0.0.0.0/0","Description": "sno-100"}]}]' \
--tag-specifications "ResourceType=security-group-rule,Tags=[{Key=sno-100,Value=sno-100}]" 2>&1 | tee /tmp/aws-error-file
if [ "$?" != 0 ]; then
if egrep -q "InvalidPermission.Duplicate|DryRunOperation" /tmp/aws-error-file; then
echo -e "${GREEN}Ignoring - master security group rule already exists or dry-run set ?${NC}"
else
echo -e "π±${RED}Failed - problem authorizing master securty group setting ?${NC}"
exit 1
fi
fi
# update master security group - add rules that were attached to elb to master from 0.0.0.0/0 to 443, 80, echo
aws ec2 authorize-security-group-ingress \
--region=${region} \
${DRYRUN:---dry-run} \
--group-id ${master_sg} \
--ip-permissions '[{"IpProtocol": "tcp", "FromPort": 443, "ToPort":443, "IpRanges": [{"CidrIp": "0.0.0.0/0","Description": "sno-100"}]},{"IpProtocol": "tcp", "FromPort": 80, "ToPort":80, "IpRanges": [{"CidrIp": "0.0.0.0/0","Description": "sno-100"}]},{"IpProtocol": "icmp", "FromPort": 8, "ToPort": -1,"IpRanges": [{"CidrIp": "0.0.0.0/0","Description": "sno-100"}]}]' \
--tag-specifications "ResourceType=security-group-rule,Tags=[{Key=sno-100,Value=sno-100}]" 2>&1 | tee /tmp/aws-error-file
if [ "$?" != 0 ]; then
if egrep -q "InvalidPermission.Duplicate|DryRunOperation" /tmp/aws-error-file; then
echo -e "${GREEN}Ignoring - master security group rule already exists or dry-run set ?${NC}"
else
echo -e "π±${RED}Failed - problem authorizing master securty group setting ?${NC}"
exit 1
fi
fi
echo -e "${GREEN} -> update_master_sg OK${NC}"
set +o pipefail
}
tag_eip() {
IFS=$'\n' read -d '' -r -a lines < <(aws ec2 describe-tags --filters "Name=resource-id,Values=$instance_id" --output text)
if [ ! -z "$lines" ]; then
set -o pipefail
for line in "${lines[@]}"; do
read -r type key resourceid resourcetype value <<< "$line"
aws ec2 create-tags --region=${region} --resources ${eip_alloc} --tags Key="$key",Value="$value"
done
echo -e "${GREEN} -> tag_eip [ $eip, $eip_alloc ] OK${NC}"
set +o pipefail
else
echo -e "π${ORANGE}Warning - tag_eip - could not find any tags for new eip ?${NC}"
fi
}
find_or_allocate_eip() {
set -o pipefail
# check if we have sno-100 eip already
read -r eip eip_alloc < <(aws ec2 describe-addresses \
--region=${region} \
--query "Addresses[].[PublicIp, AllocationId]" \
--filters "Name=tag-value,Values=sno-100" \
--output text)
if [ -z "$eip" ]; then
# allocate a new elastic ip address
aws ec2 allocate-address \
--domain vpc \
${DRYRUN:---dry-run} \
--region=${region} \
--tag-specifications "ResourceType=elastic-ip,Tags=[{Key=sno-100,Value=sno-100}]" 2>&1 | tee /tmp/aws-error-file
if [ "$?" != 0 ]; then
if egrep -q "DryRunOperation" /tmp/aws-error-file; then
echo -e "${GREEN}Ignoring - allocate_eip - dry run set ${NC}"
else
echo -e "π±${RED}Failed - problem allocating elastic ip ?${NC}"
exit 1
fi
else
read -r eip eip_alloc < <(aws ec2 describe-addresses \
--region=${region} \
--query "Addresses[].[PublicIp, AllocationId]" \
--filters "Name=tag-value,Values=sno-100" \
--output text)
if [ -z "$eip" ]; then
echo -e "π±${RED}Failed - problem finding allocated elastic ip ?${NC}"
exit 1
fi
tag_eip
echo -e "${GREEN} -> allocate_eip [ $eip, $eip_alloc ] OK${NC}"
fi
else
echo -e "${GREEN} -> found existing eip [ $eip, $eip_alloc ] OK${NC}"
fi
set +o pipefail
}
associate_eip() {
set -o pipefail
aws ec2 associate-address \
--region=${region} \
${DRYRUN:---dry-run} \
--allocation-id ${eip_alloc:-a1000} \
--instance-id $instance_id 2>&1 | tee /tmp/aws-error-file
if [ "$?" != 0 ]; then
if egrep -q "DryRunOperation" /tmp/aws-error-file; then
echo -e "${GREEN}Ignoring - associate_eip - dry run set ${NC}"
else
echo -e "π±${RED}Failed - could not associate eip $eip with instance $instance_id ?${NC}"
exit 1
fi
else
echo -e "${GREEN} -> associate_eip [ $eip, $eip_alloc, $instance_id ] OK${NC}"
fi
set +o pipefail
}
find_public_route_table() {
local tag_value="$1"
public_route_table_id=$(aws ec2 describe-route-tables --region=${region} \
--query "RouteTables[].RouteTableId" \
--filters "Name=tag-value,Values=$tag_value" "Name=vpc-id,Values=${vpc_id}" \
--output text)
if [ -z "$public_route_table_id" ]; then
echo -e "π±${RED}Failed - could not find public route table id tag: $tag_value ?${NC}"
exit 1
else
echo "π΄ PublicRouteTableId set to $public_route_table_id"
fi
}
find_private_route_table() {
local tag_value="$1"
private_route_table_id=$(aws ec2 describe-route-tables --region=${region} \
--query "RouteTables[].Associations[].RouteTableAssociationId" \
--filters "Name=tag-value,Values=$tag_value" "Name=vpc-id,Values=${vpc_id}" \
--output text)
if [ -z "$private_route_table_id" ]; then
echo -e "π${ORANGE}Warning - could not find private route table assoc id for tag: $tag_value - continuing, they may have been deleted already ?${NC}"
else
echo "π΄ PrivateRouteTableId set to $private_route_table_id"
fi
}
update_private_route() {
set -o pipefail
if [ ! -z "$private_route_table_id" ]; then
aws ec2 replace-route-table-association \
${DRYRUN:---dry-run} \
--association-id $private_route_table_id \
--route-table-id $public_route_table_id \
--region=${region} 2>&1 | tee /tmp/aws-error-file
if [ "$?" != 0 ]; then
if egrep -q "DryRunOperation" /tmp/aws-error-file; then
echo -e "${GREEN}Ignoring - update_private_route - dry run set${NC}"
else
echo -e "π±${RED}Failed - could not associate private $private_route_table_id with public route table $public_route_table_id ?${NC}"
exit 1
fi
else
echo -e "${GREEN} -> update_private_route [ $private_route_table_id, $public_route_table_id ] OK${NC}"
fi
fi
set +o pipefail
}
update_all_private_routes() {
echo $zones | jq '.[]' | while read -r zone; do
zn=$(echo $zone | tr -d '"')
find_public_route_table "$CLUSTER_NAME-*-public-$zn"
find_private_route_table "$CLUSTER_NAME-*-private-$zn"
update_private_route
done
}
find_public_route53_hostedzone() {
local dns_name="$1"
public_hosted_zone=$(aws route53 list-hosted-zones-by-name \
--dns-name "$dns_name" \
--max-items 1 \
--query "HostedZones[].[Id]" \
--output text)
if [ -z "$public_hosted_zone" ]; then
echo -e "π±${RED}Failed - could not find public route53 hostedzone for: $dns_name ?${NC}"
exit 1
else
echo "π΄ PublicHostedZone set to $public_hosted_zone"
fi
}
update_route53_public() {
if [ -z "$DRYRUN" ]; then
echo -e "${GREEN}Ignoring - update_route53_public - dry run set${NC}"
return
fi
local dns_name="$1"
for x in "api"; do
cat << EOF > /tmp/route53_policy
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "$x.$dns_name",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
"Value": "$eip"
}
]
}
}
]
}
EOF
aws route53 change-resource-record-sets \
--region=${region} \
--hosted-zone-id $(echo ${public_hosted_zone} | sed 's/\/hostedzone\///g') \
--change-batch file:///tmp/route53_policy
if [ "$?" != 0 ]; then
echo -e "π±${RED}Failed - could not update route53 public record for $x.$dns_name, $eip ?${NC}"
exit 1
else
echo -e "${GREEN} -> update_route53_public[ $x.$dns_name, $eip ] OK${NC}"
fi
done
}
find_private_route53_hostedzone() {
local dns_name="$1"
private_hosted_zone=$(aws route53 list-hosted-zones-by-name \
--dns-name "$dns_name" \
--max-items 1 \
--query "HostedZones[].[Id]" \
--output text)
if [ -z "$private_hosted_zone" ]; then
echo -e "π±${RED}Failed - could not find private route53 hostedzone for: $dns_name ?${NC}"
exit 1
else
echo "π΄ PrivateHostedZone set to $private_hosted_zone"
fi
}
find_instance_private_ip_address() {
private_instance_ip=$(aws ec2 describe-instances \
--region=${region} \
--filters "Name=instance-id,Values=$instance_id" \
--query 'Reservations[*].Instances[*].[PrivateIpAddress]' \
--output text)
if [ -z "$private_instance_ip" ]; then
echo -e "π±${RED}Failed - could not find private instance ip address for $instance_id ?${NC}"
exit 1
else
echo "π΄ PrivateInstanceIp set to $private_instance_ip"
fi
}
update_route53_private() {
local dns_name="$1"
if [ -z "$DRYRUN" ]; then
echo -e "${GREEN}Ignoring - update_route53_private - dry run set${NC}"
return
fi
for x in "api-int" "api"; do
cat << EOF > /tmp/route53_policy
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "$x.$dns_name",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
"Value": "$private_instance_ip"
}
]
}
}
]
}
EOF
aws route53 change-resource-record-sets \
--region=${region} \
--hosted-zone-id $(echo ${private_hosted_zone} | sed 's/\/hostedzone\///g') \
--change-batch file:///tmp/route53_policy
if [ "$?" != 0 ]; then
echo -e "π±${RED}Failed - could not associate eip $eip with instance $instance_id ?${NC}"
exit 1
else
echo -e "${GREEN} -> associate_eip [ $eip, $eip_alloc, $instance_id ] OK${NC}"
fi
done
}
find_nat_gateways() {
local tag_value="$1"
nat_gateways=$(aws ec2 describe-nat-gateways --region=${region} \
--query="NatGateways[].NatGatewayId" \
--filter "Name=tag-value,Values=$tag_value" "Name=vpc-id,Values=${vpc_id}" \
--output text)
if [ -z "$nat_gateways" ]; then
echo -e "π${ORANGE}Warning - could not find nat gateways for tag: $tag_value in vpc $vpcid - continuing, they may have been deleted already ?${NC}"
else
echo "π΄ NatGateways set to $nat_gateways"
fi
}
delete_nat_gateways() {
set -o pipefail
if [ ! -z "$nat_gateways" ]; then
for x in $nat_gateways; do
aws ec2 delete-nat-gateway \
${DRYRUN:---dry-run} \
--nat-gateway-id $x \
--region=${region} 2>&1 | tee /tmp/aws-error-file
if [ "$?" != 0 ]; then
if egrep -q "DryRunOperation" /tmp/aws-error-file; then
echo -e "${GREEN}Ignoring - delete_nat_gateways - dry run set${NC}"
else
echo -e "π±${RED}Failed - could not delete nat gateway $x ?${NC}"
exit 1
fi
else
echo -e "${GREEN} -> delete_nat_gateways [ $x ] OK${NC}"
fi
done
fi
set +o pipefail
}
wait_for_nat_gateway_delete() {
set -o pipefail
if [ ! -z "$nat_gateways" ]; then
aws ec2 wait nat-gateway-deleted \
${DRYRUN:---dry-run} \
--nat-gateway-id $x \
--region=${region} 2>&1 | tee /tmp/aws-error-file
if [ "$?" != 0 ]; then
if egrep -q "DryRunOperation" /tmp/aws-error-file; then
echo -e "${GREEN}Ignoring - wait_for_nat_gateway_delete - dry run set${NC}"
else
echo -e "π±${RED}Failed - waiting for nat gateways to delete failed - $nat_gateways ?${NC}"
exit 1
fi
else
echo -e "${GREEN} -> wait_for_nat_gateway_delete [ $nat_gateways ] OK${NC}"
fi
fi
if [ ! -z "$DRYRUN" ]; then
sleep 30 # try to avoid auth failure when we release eip next
fi
set +o pipefail
}
release_eips() {
local tag_value="$1"
IFS=$'\n' read -d '' -r -a lines < <(aws ec2 describe-addresses \
--region=${region} \
--query "Addresses[].[PublicIp,AllocationId]" \
--filters "Name=tag-value,Values=$tag_value" \
--output text)
if [ ! -z "$lines" ]; then
set -o pipefail
for line in "${lines[@]}"; do
read -r ip alloc_id <<< "$line"
aws ec2 release-address \
${DRYRUN:---dry-run} \
--region=${region} \
--allocation-id $alloc_id 2>&1 | tee /tmp/aws-error-file
if [ "$?" != 0 ]; then
if egrep -q "DryRunOperation" /tmp/aws-error-file; then
echo -e "${GREEN}Ignoring - release_eips - dry run set${NC}"
else
echo -e "π±${RED}Failed - could not release eip $ip $alloc_id ?${NC}"
exit 1
fi
else
echo -e "${GREEN} -> release_eips [ $ip, $alloc_id ] OK${NC}"
fi
done
set +o pipefail
else
echo -e "π${ORANGE}Warning - could not find any eips to release - continuing, they may have been deleted already ?${NC}"
fi
}
find_network_load_balancers() {
query='LoadBalancers[?VpcId==`'${vpc_id}'`]|[].LoadBalancerArn'
network_load_balancers=$(aws elbv2 describe-load-balancers --region=${region} \
--query $query \
--output text)
if [ -z "$network_load_balancers" ]; then
echo -e "π${ORANGE}Warning - could not find load balancers - continuing, they may have been deleted already ?${NC}"
else
echo "π΄ NetworkLoadBalancers set to $network_load_balancers"
fi
}
delete_network_load_balancers() {
if [ -z "$DRYRUN" ]; then
echo -e "${GREEN}Ignoring - delete_load_balancers - dry run set${NC}"
return
fi
if [ ! -z "$network_load_balancers" ]; then
for x in $network_load_balancers; do
aws elbv2 delete-load-balancer \
--region=${region} \
--load-balancer-arn $x
if [ "$?" != 0 ]; then
echo -e "π±${RED}Failed - could not delete load balancer $x ?${NC}"
exit 1
else
echo -e "${GREEN} -> delete_load_balancers [ $x ] OK${NC}"
fi
done
fi
}
delete_target_groups() {
if [ -z "$DRYRUN" ]; then
echo -e "${GREEN}Ignoring - delete_target_groups - dry run set${NC}"
return
fi
query='TargetGroups|[].TargetGroupArn'
target_groups=$(aws elbv2 describe-target-groups --query $query)
if [ ! -z "$target_groups" ]; then
echo $target_groups | jq '.[]' | while read -r tg; do aws elbv2 delete-target-group --target-group-arn $(echo $tg | tr -d '"'); done
if [ "$?" != 0 ]; then
echo -e "π±${RED}Failed - could not delete target groups $target_groups ?${NC}"
exit 1
else
echo -e "${GREEN} -> delete_target_groups [ $target_groups ] OK${NC}"
fi
fi
}
find_zones() {
if [ -z "$DRYRUN" ]; then
echo -e "${GREEN}Ignoring - find_zones - dry run set${NC}"
return
fi
query='AvailabilityZones[].ZoneName'
zones=$(aws ec2 describe-availability-zones --query $query)
if [ -z "$zones" ]; then
echo -e "π±${RED}Failed - could not find zones ?${NC}"
exit 1
fi
echo -e "${GREEN} -> find_zones [ $zones ] OK${NC}"
}
# do it all
all() {
echo "π΄ BASE_DOMAIN set to $BASE_DOMAIN"
echo "π΄ CLUSTER_NAME set to $CLUSTER_NAME"
# find ids
find_region
find_zones
find_instance_id "$CLUSTER_NAME-*-master-0"
find_vpc_id "$CLUSTER_NAME-*-vpc"
find_master_sg
# updates
update_master_sg
find_or_allocate_eip
associate_eip
update_all_private_routes
find_public_route53_hostedzone "$BASE_DOMAIN"
update_route53_public "$CLUSTER_NAME.$BASE_DOMAIN"
find_instance_private_ip_address
find_private_route53_hostedzone "$CLUSTER_NAME.$BASE_DOMAIN"
update_route53_private "$CLUSTER_NAME.$BASE_DOMAIN"
find_nat_gateways "$CLUSTER_NAME-*-nat"
delete_nat_gateways
wait_for_nat_gateway_delete
release_eips "$CLUSTER_NAME-*-eip-*"
find_network_load_balancers
delete_network_load_balancers
delete_target_groups
}
usage() {
cat <<EOF 2>&1
usage: $0 [ -d -b <BASE_DOMAIN> -c <CLUSTER_NAME> ]
Adjust SNO instance networking. By default dry-run is ON ! You must set -d to doItβ’οΈ
-d do it ! no dry run - else we print out whats going to happen and any non desructive lookups
Optional arguments if not set in environment:
-b BASE_DOMAIN - openshift base domain (or export BASE_DOMAIN env var)
-c CLUSTER_NAME - openshift cluster name (or export CLUSTER_NAME env var)
This script is rerunnable.
Environment Variables:
Export these in your environment.
AWS_PROFILE use a pre-configured aws profile (~/.aws/config and ~/.aws/credentials)
OR export these in your environment:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
Optionally if not set on command line:
BASE_DOMAIN
CLUSTER_NAME
EOF
exit 1
}
while getopts b:c:d opt; do
case $opt in
b)
BASE_DOMAIN=$OPTARG
;;
c)
CLUSTER_NAME=$OPTARG
;;
d)
DRYRUN="--no-dry-run"
;;
*)
usage
;;
esac
done
shift `expr $OPTIND - 1`
# Check for EnvVars
[ ! -z "$AWS_PROFILE" ] && echo "π΄ Using AWS_PROFILE: $AWS_PROFILE"
[ -z "$BASE_DOMAIN" ] && echo "π± Error: must supply BASE_DOMAIN in env or cli" && exit 1
[ -z "$CLUSTER_NAME" ] && echo "π± Error: must supply CLUSTER_NAME in env or cli" && exit 1
[ -z "$AWS_PROFILE" ] && [ -z "$AWS_ACCESS_KEY_ID" ] && echo "π± Error: AWS_ACCESS_KEY_ID not set in env" && exit 1
[ -z "$AWS_PROFILE" ] && [ -z "$AWS_SECRET_ACCESS_KEY" ] && echo "π± Error: AWS_SECRET_ACCESS_KEY not set in env" && exit 1
[ -z "$AWS_PROFILE" ] && [ -z "$AWS_DEFAULT_REGION" ] && echo "π± Error: AWS_DEFAULT_REGION not set in env" && exit 1
all
echo -e "\nπ»${GREEN}AWS SNO Reconfigured OK.${NC}π»\n"
exit 0