-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_endpoint.sh
executable file
·135 lines (117 loc) · 4.15 KB
/
config_endpoint.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
#!/bin/bash -x
if [ $# -gt 1 ]
then
echo "Invalid input, only one argument expected"
exit
fi
COMPONENT=$1
check_for_loadBalancer()
{
## Wait for $EXTERNAL_IP_CHECK_DELAY till K8s assins a load Balancer IP to oes-gate
iter=0
lapsedTime=0
while [ $iter -lt 36 ]
do
ENDPOINT_IP=$(kubectl get svc $1 -o jsonpath="{.status.loadBalancer.ingress[].ip}")
if [ ! -z "$ENDPOINT_IP" ];
then
echo "Found LoadBalancer IP for" $1
break
fi
sleep 5
lapsedTime=`expr $lapsedTime + 5`
if [ $lapsedTime -eq $EXTERNAL_IP_CHECK_DELAY ];
then
echo "Time Lapsed" $lapsedTime
echo "Timeout! Fetching nodeport IP alternatively"
break
fi
echo "Time Lapsed" $lapsedTime
iter=`expr $iter + 1`
done
}
check_for_spinnakerGate_loadBalancer()
{
## Wait for $EXTERNAL_IP_CHECK_DELAY till K8s assins a load Balancer IP to oes-gate
iter=0
lapsedTime=0
while [ $iter -lt 36 ]
do
# Check if loadBalancer is directly assinged to spin-deck or spin-deck-ui service
ENDPOINT_IP=$(kubectl get svc spin-deck -o jsonpath="{.status.loadBalancer.ingress[].ip}")
if [ -z "$ENDPOINT_IP" ];
then
ENDPOINT_IP=$(kubectl get svc spin-deck-ui -o jsonpath="{.status.loadBalancer.ingress[].ip}")
fi
if [ ! -z "$ENDPOINT_IP" ];
then
echo "Found LoadBalancer IP for" $1
break
fi
sleep 5
lapsedTime=`expr $lapsedTime + 5`
if [ $lapsedTime -eq $2 ];
then
echo "Time Lapsed" $lapsedTime
echo "Timeout! Fetching nodeport IP alternatively"
break
fi
echo "Time Lapsed" $lapsedTime
iter=`expr $iter + 1`
done
}
case "$COMPONENT" in
oes-ui)
cp /config/* /var/www/html/assets/config/
ENDPOINT_IP=""
## Wait for $EXTERNAL_IP_CHECK_DELAY till K8s assins a load Balancer IP to oes-gate
check_for_loadBalancer oes-gate
## If external IP is not available
if [ -z "$ENDPOINT_IP" ]; then
## Fetch the IP of the host & nodeport and replace in app-config.js
ENDPOINT_IP=$(kubectl get ep kubernetes -n default -o jsonpath="{.subsets[].addresses[].ip}")
PORT=$(kubectl get svc oes-gate-svc -o jsonpath="{.spec.ports[].nodePort}")
sed -i "s/OES_GATE_IP/$ENDPOINT_IP/g" /var/www/html/assets/config/app-config.json
sed -i "s/8084/$PORT/g" /var/www/html/assets/config/app-config.json
else
## Substitute oes-gate external IP in app-config.js
sed -i "s/OES_GATE_IP/$ENDPOINT_IP/g" /var/www/html/assets/config/app-config.json
fi
;;
oes-gate)
cp /config/* /opt/spinnaker/config/
ENDPOINT_IP=""
## Wait for $EXTERNAL_IP_CHECK_DELAY till K8s assins a load Balancer IP to oes-gate
check_for_loadBalancer oes-ui
## If external IP is not available
if [ -z "$ENDPOINT_IP" ]; then
## Fetch the IP of the host and replace in gate.yml
ENDPOINT_IP=$(kubectl get ep kubernetes -n default -o jsonpath="{.subsets[].addresses[].ip}")
sed -i "s/OES_UI_LOADBALANCER_IP/$ENDPOINT_IP/g" /opt/spinnaker/config/gate.yml
else
## Substitute oes-ui external IP in gate.yml
sed -i "s/OES_UI_LOADBALANCER_IP/$ENDPOINT_IP/g" /opt/spinnaker/config/gate.yml
fi
;;
sapor)
cp /config/* /opt/opsmx/
ENDPOINT_IP=""
## Wait for $EXTERNAL_IP_CHECK_DELAY till K8s assins a load Balancer IP to oes-gate
check_for_spinnakerGate_loadBalancer spin-deck $SPINNAKER_SETUP_DELAY
PORT=9000
## If external IP is not available
if [ -z "$ENDPOINT_IP" ]; then
## Fetch the IP of the host and replace in spinnaker.yaml
ENDPOINT_IP=$(kubectl get ep kubernetes -n default -o jsonpath="{.subsets[].addresses[].ip}")
PORT=$(kubectl get svc spin-gate -o jsonpath="{.spec.ports[].nodePort}")
sed -i "s/SPIN_GATE_LOADBALANCER_IP_PORT/$ENDPOINT_IP:$PORT/g" /opt/opsmx/spinnaker.yaml
#sed -i "s/spin-gate:8084/$ENDPOINT_IP:$PORT/g" /opt/opsmx/spinnaker.yaml
else
## Substitute oes-ui external IP in spinnaker.yaml
sed -i "s/SPIN_GATE_LOADBALANCER_IP_PORT/$ENDPOINT_IP:$PORT/g" /opt/opsmx/spinnaker.yaml
fi
;;
*)
echo "Invalid input"
;;
esac