blob: 1a75bd7a85f839061c2936672330bd7f6ba8d4ee [file] [log] [blame]
Lucjan Bryndzae604acd2020-02-06 15:20:24 +01001#!/bin/bash -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#
17DNS_PORT=31555
18CLUSTER_CONTROL=$( kubectl get no -l node-role.kubernetes.io/controlplane=true -o jsonpath='{.items..metadata.name}')
19CLUSTER_IP=$(kubectl get no $CLUSTER_CONTROL -o jsonpath='{.metadata.annotations.rke\.cattle\.io/external-ip }')
20SPATH="$( dirname "$( which "$0" )" )"
21
22
23
24usage() {
25cat << ==usage
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +020026$0 [cluster_domain] [lb_ip] [helm_chart_args] ...
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010027 [cluster_domain] Default value simpledemo.onap.org
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +020028 [lb_ip] Default value LoadBalancer IP
29 [helm_chart_args] ... Optional arguments passed to helm install command
Lucjan Bryndzaf2208122020-03-12 10:02:56 +010030$0 --help This message
31$0 --info Display howto configure target machine
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010032==usage
33}
34
35
36target_machine_notice_info() {
37cat << ==infodeploy
38Extra DNS server already deployed:
391. You can add the DNS server to the target machine using following commands:
40 sudo iptables -t nat -A OUTPUT -p tcp -d 192.168.211.211 --dport 53 -j DNAT --to-destination $CLUSTER_IP:$DNS_PORT
41 sudo iptables -t nat -A OUTPUT -p udp -d 192.168.211.211 --dport 53 -j DNAT --to-destination $CLUSTER_IP:$DNS_PORT
42 sudo sysctl -w net.ipv4.conf.all.route_localnet=1
43 sudo sysctl -w net.ipv4.ip_forward=1
442. Update /etc/resolv.conf file with nameserver 192.168.211.211 entry on your target machine
45==infodeploy
46}
47
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +020048
49list_node_with_external_addrs()
50{
51 local WORKER_NODES=$(kubectl get no -l node-role.kubernetes.io/worker=true -o jsonpath='{.items..metadata.name}')
52 for worker in $WORKER_NODES; do
53 local external_ip=$(kubectl get no $worker -o jsonpath='{.metadata.annotations.rke\.cattle\.io/external-ip }')
54 local internal_ip=$(kubectl get no $worker -o jsonpath='{.metadata.annotations.rke\.cattle\.io/internal-ip }')
55 if [ $internal_ip != $external_ip ]; then
56 echo $external_ip
57 break
58 fi
59 done
60}
61
62ingress_controller_ip() {
63 local metal_ns=$(kubectl get ns --no-headers --output=custom-columns=NAME:metadata.name |grep metallb-system)
64 if [ -z $metal_ns ]; then
65 echo $CLUSTER_IP
66 else
67 list_node_with_external_addrs
68 fi
69}
70
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010071deploy() {
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +020072 local ingress_ip=$(ingress_controller_ip)
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010073 pushd "$SPATH/bind9dns" > /dev/null
74 if [ $# -eq 0 ]; then
75 local cl_domain="simpledemo.onap.org"
76 else
77 local cl_domain=$1
78 shift
79 fi
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +020080 if [ $# -ne 0 ]; then
81 ingress_ip=$1
82 shift
83 fi
84 helm install . --set dnsconf.wildcard="$cl_domain=$ingress_ip" $@
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010085 popd > /dev/null
86 target_machine_notice_info
87}
88
Guillaume Lambert5f4af052021-03-09 21:52:32 +010089if [[ $# -eq 1 ]] && [[ $1 = "-h" || $1 = "--help" ]]; then
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010090 usage
Guillaume Lambert5f4af052021-03-09 21:52:32 +010091elif [[ $# -eq 1 ]] && [[ $1 = "--info" ]]; then
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +020092 target_machine_notice_info
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010093else
94 deploy $@
95fi