blob: 294ae0a55e643463d0f3b1bd6a25a1bbf921e3aa [file] [log] [blame]
Guillaume Lambert85b14922021-03-12 13:53:18 +01001#!/bin/sh -e
Guillaume Lambert134188d2021-03-11 13:42:23 +01002
Lucjan Bryndzae604acd2020-02-06 15:20:24 +01003# 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] ...
guillaume.lambert7bf306e2021-09-08 12:03:22 +020027 [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
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
Guillaume Lambert85b14922021-03-12 13:53:18 +010036target_machine_notice_info()
37{
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010038cat << ==infodeploy
39Extra DNS server already deployed:
401. You can add the DNS server to the target machine using following commands:
guillaume.lambert7bf306e2021-09-08 12:03:22 +020041 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
Lucjan Bryndzae604acd2020-02-06 15:20:24 +0100452. Update /etc/resolv.conf file with nameserver 192.168.211.211 entry on your target machine
46==infodeploy
47}
48
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +020049
50list_node_with_external_addrs()
51{
guillaume.lambertf657a812021-12-07 20:21:17 +010052 local WORKER_NODES
53 WORKER_NODES=$(kubectl get no -l node-role.kubernetes.io/worker=true -o jsonpath='{.items..metadata.name}')
guillaume.lambert7bf306e2021-09-08 12:03:22 +020054 for worker in $WORKER_NODES; do
guillaume.lambertf657a812021-12-07 20:21:17 +010055 local external_ip
56 external_ip=$(kubectl get no $worker -o jsonpath='{.metadata.annotations.rke\.cattle\.io/external-ip }')
57 local internal_ip
58 internal_ip=$(kubectl get no $worker -o jsonpath='{.metadata.annotations.rke\.cattle\.io/internal-ip }')
guillaume.lambert7bf306e2021-09-08 12:03:22 +020059 if [ $internal_ip != $external_ip ]; then
60 echo $external_ip
61 break
62 fi
63 done
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +020064}
65
66ingress_controller_ip() {
guillaume.lambertf657a812021-12-07 20:21:17 +010067 local metal_ns
68 metal_ns=$(kubectl get ns --no-headers --output=custom-columns=NAME:metadata.name |grep metallb-system)
guillaume.lambert7bf306e2021-09-08 12:03:22 +020069 if [ -z $metal_ns ]; then
70 echo $CLUSTER_IP
71 else
72 list_node_with_external_addrs
73 fi
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +020074}
75
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010076deploy() {
guillaume.lambertf657a812021-12-07 20:21:17 +010077 local ingress_ip
78 ingress_ip=$(ingress_controller_ip)
guillaume.lambert7bf306e2021-09-08 12:03:22 +020079 initdir = $(pwd)
80 cd $SPATH/bind9dns
81 if [ $# -eq 0 ]; then
guillaume.lambertf657a812021-12-07 20:21:17 +010082 local cl_domain
83 cl_domain="simpledemo.onap.org"
guillaume.lambert7bf306e2021-09-08 12:03:22 +020084 else
guillaume.lambertf657a812021-12-07 20:21:17 +010085 local cl_domain
86 cl_domain=$1
guillaume.lambert7bf306e2021-09-08 12:03:22 +020087 shift
88 fi
89 if [ $# -ne 0 ]; then
90 ingress_ip=$1
91 shift
92 fi
93 helm install . --set dnsconf.wildcard="$cl_domain=$ingress_ip" $@
94 cd $initdir
95 target_machine_notice_info
Lucjan Bryndzae604acd2020-02-06 15:20:24 +010096}
97
Guillaume Lambert7abd8c32021-04-26 21:48:38 +020098if [ $# -eq 1 ] && [ "$1" = "-h" ]; then
guillaume.lambert7bf306e2021-09-08 12:03:22 +020099 usage
guillaume.lambertbd1b9ab2021-08-28 09:40:08 +0200100elif [ $# -eq 1 ] && [ "$1" = "--help" ]; then
guillaume.lambert7bf306e2021-09-08 12:03:22 +0200101 usage
Guillaume Lambert7abd8c32021-04-26 21:48:38 +0200102elif [ $# -eq 1 ] && [ "$1" = "--info" ]; then
Lucjan Bryndza76bf24c2020-04-01 15:10:14 +0200103 target_machine_notice_info
Lucjan Bryndzae604acd2020-02-06 15:20:24 +0100104else
guillaume.lambert7bf306e2021-09-08 12:03:22 +0200105 deploy $@
Lucjan Bryndzae604acd2020-02-06 15:20:24 +0100106fi