[COMMON] Enforce checkbashisms tox profile
[oom.git] / kubernetes / contrib / dns-server-for-vhost-ingress-testing / deploy_dns.sh
1 #!/bin/sh -e
2
3 #   Copyright 2020 Samsung Electronics Co., Ltd.
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 #
17 DNS_PORT=31555
18 CLUSTER_CONTROL=$( kubectl get no -l node-role.kubernetes.io/controlplane=true -o jsonpath='{.items..metadata.name}')
19 CLUSTER_IP=$(kubectl get no $CLUSTER_CONTROL  -o jsonpath='{.metadata.annotations.rke\.cattle\.io/external-ip }')
20 SPATH="$( dirname "$( which "$0" )" )"
21
22
23
24 usage() {
25 cat << ==usage
26 $0 [cluster_domain] [lb_ip] [helm_chart_args] ...
27     [cluster_domain] Default value simpledemo.onap.org
28     [lb_ip] Default value LoadBalancer IP
29     [helm_chart_args] ... Optional arguments passed to helm install command
30 $0 --help This message
31 $0 --info Display howto configure target machine
32 ==usage
33 }
34
35
36 target_machine_notice_info()
37 {
38 cat << ==infodeploy
39 Extra DNS server already deployed:
40 1. You can add the DNS server to the target machine using following commands:
41     sudo iptables -t nat -A OUTPUT -p tcp -d 192.168.211.211 --dport 53 -j DNAT --to-destination $CLUSTER_IP:$DNS_PORT
42     sudo iptables -t nat -A OUTPUT -p udp -d 192.168.211.211 --dport 53 -j DNAT --to-destination $CLUSTER_IP:$DNS_PORT
43     sudo sysctl -w net.ipv4.conf.all.route_localnet=1
44     sudo sysctl -w net.ipv4.ip_forward=1
45 2. Update /etc/resolv.conf file with nameserver 192.168.211.211 entry on your target machine
46 ==infodeploy
47 }
48
49
50 list_node_with_external_addrs()
51 {
52     local WORKER_NODES=$(kubectl get no -l node-role.kubernetes.io/worker=true -o jsonpath='{.items..metadata.name}')
53     for worker in $WORKER_NODES; do
54         local external_ip=$(kubectl get no $worker  -o jsonpath='{.metadata.annotations.rke\.cattle\.io/external-ip }')
55         local internal_ip=$(kubectl get no $worker  -o jsonpath='{.metadata.annotations.rke\.cattle\.io/internal-ip }')
56         if [ $internal_ip != $external_ip ]; then
57             echo $external_ip
58             break
59         fi
60     done
61 }
62
63 ingress_controller_ip() {
64     local metal_ns=$(kubectl get ns --no-headers --output=custom-columns=NAME:metadata.name |grep metallb-system)
65     if [ -z $metal_ns ]; then
66         echo $CLUSTER_IP
67     else
68         list_node_with_external_addrs
69     fi
70 }
71
72 deploy() {
73     local ingress_ip=$(ingress_controller_ip)
74     initdir = $(pwd)
75     cd $SPATH/bind9dns
76     if [ $# -eq 0 ]; then
77         local cl_domain="simpledemo.onap.org"
78     else
79         local cl_domain=$1
80         shift
81     fi
82     if [ $# -ne 0 ]; then
83         ingress_ip=$1
84         shift
85     fi
86     helm install . --set dnsconf.wildcard="$cl_domain=$ingress_ip" $@
87     cd $initdir
88     target_machine_notice_info
89 }
90
91 if [ $# -eq 1 ] && [ "$1" = "-h" ]; then
92     usage
93 elif [ $# -eq 1 ] && [ "$1" = "--help" ]; then
94     usage
95 elif [ $# -eq 1 ] && [ "$1" = "--info" ]; then
96        target_machine_notice_info
97 else
98     deploy $@
99 fi