Skip to content

Commit 0160628

Browse files
committed
Changes for operator+ipa
Refactoring: rhel_provisioning and ipa server setup are moved from rhosp to common level partial-jira-bug: CEM-26529 Signed-off-by: Gleb Galkin <[email protected]> Change-Id: Ic7df960c3d6b1bad56deba9bf6410861771701b9
1 parent b5c18c6 commit 0160628

17 files changed

+320
-86
lines changed

common/common.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ export PHYS_INT=`ip route get 1 | grep -o 'dev.*' | awk '{print($2)}'`
2323
export NODE_IP=`ip addr show dev $PHYS_INT | grep 'inet ' | awk '{print $2}' | head -n 1 | cut -d '/' -f 1`
2424
export NODE_CIDR=`ip r | grep -E "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]+ dev $PHYS_INT " | awk '{print $1}'`
2525
export SSH_USER=${SSH_USER:-${IMAGE_SSH_USER:-$(whoami)}}
26+
27+
if [[ "$DISTRO" == "rhel" ]]; then
28+
declare -A _default_rhel_version=( ['7.9']='rhel7.9' ['8.2']='rhel8.2' ['8.4']='rhel8.4' )
29+
export RHEL_VERSION=${_default_rhel_version[$DISTRO_VERSION_ID]}
30+
export RHEL_MAJOR_VERSION=$(echo $RHEL_VERSION | cut -d '.' -f1)
31+
fi
32+
2633
# defaults
2734

2835
# run build tf
@@ -43,6 +50,7 @@ export CONTROLLER_NODES="$(echo $CONTROLLER_NODES | tr ',' ' ')"
4350
export CONTROL_NODES="$(echo $CONTROL_NODES | tr ',' ' ')"
4451
AGENT_NODES="${AGENT_NODES:-$NODE_IP}"
4552
export AGENT_NODES="$(echo $AGENT_NODES | tr ',' ' ')"
53+
export IPA_NODES="$(echo $IPA_NODES | tr ',' ' ')"
4654

4755
export TF_LOG_DIR=${TF_LOG_DIR:-${TF_CONFIG_DIR}/logs}
4856
export SSL_ENABLE=${SSL_ENABLE:-false}

common/deploy_kubespray.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ LOOKUP_NODE_HOSTNAMES=${LOOKUP_NODE_HOSTNAMES:-true}
4848
CRYPTOGRAPHY_ALLOW_OPENSSL_102=true
4949

5050
# set locale to prevent errors from pip install and similar
51+
if [[ "$DISTRO" == "rhel" ]]; then
52+
sudo dnf install -y glibc-langpack-en
53+
fi
5154
sudo localectl set-locale LANG=en_US.UTF-8
5255
. /etc/locale.conf
5356
export LC_ALL=en_US.UTF-8
@@ -252,13 +255,18 @@ if [[ -z "$CONTAINER_RUNTIME" || "$CONTAINER_RUNTIME" == 'docker' ]]; then
252255
fi
253256

254257
extra_vars=""
255-
[[ "$ENABLE_RHEL_REGISTRATION" == 'true' ]] || extra_vars="$extra_vars -e {\"rhel_enable_repos\":False}"
258+
[[ "$ENABLE_RHEL_REGISTRATION" == 'true' ]] || echo '{"rhel_enable_repos": False}' >/tmp/extravars.json
256259
[[ -z "$REGISTRY_PROXY" ]] || extra_vars="$extra_vars -e docker_image_repo=$REGISTRY_PROXY"
257260
[[ -z "$REGISTRY_PROXY" ]] || extra_vars="$extra_vars -e docker_image_repo=$REGISTRY_PROXY"
258261
[[ -z $K8S_POD_SUBNET ]] || extra_vars="$extra_vars -e kube_pods_subnet=$K8S_POD_SUBNET"
259262
[[ -z $K8S_SERVICE_SUBNET ]] || extra_vars="$extra_vars -e kube_service_addresses=$K8S_SERVICE_SUBNET"
260263
[[ -z $K8S_VERSION ]] || extra_vars="$extra_vars -e kube_version=$K8S_VERSION"
261-
ansible-playbook -i inventory/mycluster/hosts.yml --become --become-user=root cluster.yml $extra_vars "$@"
264+
265+
echo i"INFO: Cleanup /etc/hosts before kubespay"
266+
cp $my_dir/deploy_kubespray_cleanup_hosts.yaml .
267+
ansible-playbook -i inventory/mycluster/hosts.yml deploy_kubespray_cleanup_hosts.yaml
268+
echo "INFO: Running kubespray playbook"
269+
ansible-playbook -i inventory/mycluster/hosts.yml --become --become-user=root cluster.yml --extra-vars "@/tmp/extravars.json" $extra_vars "$@"
262270

263271
mkdir -p ~/.kube
264272
sudo cp /root/.kube/config ~/.kube/config
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
#Kubespray manages /etc/hosts and this playbook clean ansible inventory ip from /etc/hosts
3+
#It should be run with kubespray inventory file
4+
- name: Clear /etc/hosts from ansible inventory hosts
5+
hosts: all
6+
become: yes
7+
tasks:
8+
9+
- set_fact:
10+
cluster_hosts: "{{ cluster_hosts|default([]) + [ hostvars[item]['ansible_host'] ] }}"
11+
loop: "{{ groups['all'] }}"
12+
run_once: true
13+
14+
- name: Delete ip addresses from /etc/hosts
15+
lineinfile: dest=/etc/hosts
16+
state=absent
17+
regexp='^{{ item }}'
18+
with_items: "{{ cluster_hosts }}"
19+

common/functions.sh

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function check_tf_services() {
219219
# get contrail-status from $machine node
220220
# TODO: set timeout 15 sec (-t 15) - there is bug in agent - it does internally
221221
# 2 dns queries with 5 sec timeout that always fails in 10 sec,
222-
# so tool always fails with default 10 sec timeout.
222+
# so tool always fails with default 10 sec timeout.
223223
local contrail_status=$(ssh $SSH_OPTIONS $addr "sudo contrail-status -t 15" 2>/dev/null)
224224
# keep first part of contrail-status with rows and columns
225225
# of pods and services in /tmp/_tmp_contrail_status file
@@ -258,7 +258,7 @@ function check_tf_active() {
258258
fi
259259
# TODO: set timeout 15 sec (-t 15) - there is bug in agent - it does internally
260260
# 2 dns queries with 5 sec timeout that always fails in 10 sec,
261-
# so tool always fails with default 10 sec timeout.
261+
# so tool always fails with default 10 sec timeout.
262262
for line in $(ssh $SSH_OPTIONS $addr "sudo contrail-status -t 15" 2>/dev/null | egrep ": " | grep -v "WARNING" | awk '{print $2}'); do
263263
if [ "$line" != "active" ] && [ "$line" != "backup" ] ; then
264264
return 1
@@ -318,3 +318,66 @@ function get_vrouter_gateway() {
318318
local gw=$(ip route get "$cidr" | grep -o 'via .*' | awk '{print($2)}' |head -n1)
319319
[ -z "$gw" ] || echo $gw
320320
}
321+
322+
#Find full hostname by ip based on /etc/hosts
323+
function get_hostname_by_ip() {
324+
local ip_addr=$1
325+
[ -n "$ip_addr" ] || return
326+
local str
327+
str=$(getent hosts $ip_addr | awk '{print $2}')
328+
echo $str
329+
}
330+
331+
#Convert list of IP addresses into list of full hostnames
332+
function convert_ips_to_hostnames() {
333+
local line=$1
334+
local converted_line=''
335+
local host_name
336+
local ip_addr
337+
for ip_addr in $(echo $line | tr ',' ' '); do
338+
host_name=$(get_hostname_by_ip $ip_addr)
339+
converted_line+="$host_name,"
340+
done
341+
echo $converted_line
342+
}
343+
344+
function ensure_fqdn() {
345+
local domain=${1}
346+
if [ -z "$domain" ] ; then
347+
echo "ERROR: domain must be set"
348+
exit 1
349+
fi
350+
local cur_fqdn="$(hostname -f)"
351+
local exp_fqdn="$(hostname -s).${domain}"
352+
echo "INFO: cur_fqdn=$cur_fqdn exp_fqdn=$exp_fqdn"
353+
if [[ "$cur_fqdn" != "$exp_fqdn" ]] ; then
354+
echo "INFO: cur fqdn doesnt match to expected: $cur_fqdn != $exp_fqdn"
355+
sudo hostnamectl set-hostname $exp_fqdn
356+
echo "INFO: Changing /etc/resolv.conf on $(hostname -f)"
357+
echo "#generated by tf-devstack" > /tmp/resolv.conf
358+
echo "search $domain" >> /tmp/resolv.conf
359+
echo "nameserver 8.8.8.8" >> /tmp/resolv.conf
360+
sudo cp /tmp/resolv.conf /etc/resolv.conf
361+
fi
362+
echo "INFO: fqdn: $(hostname -f) host domain: $(hostname -d)"
363+
}
364+
365+
function ensure_nameserver() {
366+
local nameserver_ip=${1:-'8.8.8.8'}
367+
if ! grep -q "nameserver $nameserver_ip" /etc/resolv.conf; then
368+
echo "INFO: change_nameserver: nameserver $nameserver_ip is set in /etc/resolv.conf"
369+
sudo sed -i '/nameserver/d' /etc/resolv.conf
370+
echo "nameserver $nameserver_ip" | sudo tee -a /etc/resolv.conf
371+
fi
372+
}
373+
374+
function ensure_record_in_etc_hosts() {
375+
local ip_addr=$1
376+
local fqdn=$2
377+
local shortname=$(echo $fqdn | cut -d '.' -f1)
378+
if ! grep -qE "$ip_addr\s+$fqdn" /etc/hosts; then
379+
echo "INFO: Adding new record \"$ip_addr $fqdn\" to /etc/hosts"
380+
sudo sed -i "/$ip_addr/d" /etc/hosts
381+
echo "$ip_addr $fqdn $shortname" | sudo tee -a /etc/hosts
382+
fi
383+
}

rhosp/providers/common/rhel8_provisioning.sh renamed to common/rhel8_provisioning.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ sudo dnf distro-sync -y
3131

3232
sudo dnf update -y
3333

34-
packages="chrony wget yum-utils vim iproute jq curl bind-utils network-scripts net-tools tmux createrepo bind-utils sshpass python36 podman"
34+
packages="chrony wget yum-utils vim iproute jq curl bind-utils network-scripts net-tools tmux createrepo sshpass python36 podman"
3535
[[ "$ENABLE_TLS" != 'ipa' ]] || packages+=" ipa-client python3-novajoin openssl-perl ca-certificates"
3636

3737
sudo dnf install -y --allowerasing $packages
3838

3939
sudo systemctl start chronyd
4040

4141
sudo alternatives --set python /usr/bin/python3
42+
43+
#service network is not enabled by default in RHEL8.4
44+
sudo systemctl enable network || true
45+
sudo systemctl start network || true

rhosp/providers/common/rhel_provisioning.sh renamed to common/rhel_provisioning.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ my_file="$(readlink -e "$0")"
44
my_dir="$(dirname $my_file)"
55

66
cd
7-
source rhosp-environment.sh
8-
source $my_dir/../../../common/common.sh
9-
source $my_dir/../../../common/functions.sh
7+
8+
#For rhosp compatibility
9+
if [[ -n "$domain" ]]; then
10+
export DOMAIN=$domain
11+
fi
12+
1013
source $my_dir/common.sh
1114
source $my_dir/functions.sh
1215

13-
ensure_fqdn ${domain}
16+
ensure_fqdn ${DOMAIN}
1417

1518
attach_opts='--auto'
1619
if [[ -n "$RHEL_POOL_ID" ]] ; then

contrib/ipa/enroll.sh

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash -e
1+
#!/bin/bash -ex
22

33
IPA_IP=$1
44
IPA_PRINCIPAL=$2
@@ -7,9 +7,20 @@ HOST_IP=$4
77
CA_DIR=/etc/contrail/ssl/ca-certs
88
CERTS_DIR=/etc/contrail/ssl/certs
99

10+
export DISTRO=$(cat /etc/*release | egrep '^ID=' | awk -F= '{print $2}' | tr -d \")
11+
export DISTRO_VERSION_ID=$(cat /etc/*release | egrep '^VERSION_ID=' | awk -F= '{print $2}' | tr -d \")
12+
1013
sudo mkdir -p $CA_DIR
1114
sudo mkdir -p $CERTS_DIR
1215

16+
#Managing SeLinux policies for directories
17+
sudo semanage fcontext -a -t cert_t "$CERTS_DIR(/.*)?"
18+
sudo restorecon -rv "$CERTS_DIR"
19+
sudo semanage fcontext -a -t cert_t "$CA_DIR(/.*)?"
20+
sudo restorecon -rv "$CA_DIR"
21+
ls -laZ $CA_DIR $CERTS_DIR
22+
23+
sudo yum install -y bind-utils
1324
sudo sed -i.bak "s/\(nameserver\) .*/\1 $IPA_IP/" /etc/resolv.conf
1425

1526
IPA_FQDN=$(nslookup "$IPA_IP" | grep name | awk '{print $4}' | rev | cut -c 2- | rev)
@@ -21,7 +32,16 @@ if [[ "$(hostname -f)" != "$HOST_FQDN" ]] ; then
2132
sudo hostnamectl set-hostname "$HOST_FQDN"
2233
fi
2334

24-
sudo yum install ipa-client -y
35+
if [[ "$DISTRO" == "rhel" && "$DISTRO_VERSION_ID" =~ ^8\. ]]; then
36+
sudo yum module install -y idm
37+
#sudo yum module enable idm:DL1
38+
sudo yum distro-sync -y
39+
#sudo yum module install -y idm:DL1/client
40+
#sudo ipa-client-install --enable-dns-updates --mkhomedir
41+
else
42+
sudo yum install ipa-client -y
43+
fi
44+
2545
sudo ipa-client-install --verbose -U --server "$IPA_FQDN" -p "$IPA_PRINCIPAL" -w "$IPA_PASSWORD" --domain "$IPA_DOMAIN" --hostname "$HOST_FQDN"
2646

2747
sudo cp /etc/ipa/ca.crt $CA_DIR/ca-bundle.crt
@@ -34,18 +54,47 @@ sudo ipa dnsrecord-find --name="$Hostname" "$IPA_DOMAIN" || sudo ipa dnsrecord-a
3454

3555
HOST_PRINCIPAL=contrail/"$HOST_FQDN"@"${IPA_DOMAIN^^}"
3656

37-
if ! ipa service-find "$HOST_PRINCIPAL" ; then
57+
if ! sudo ipa service-find "$HOST_PRINCIPAL" ; then
3858
sudo ipa service-add "$HOST_PRINCIPAL" || true
3959
sudo ipa service-add-host --hosts "$HOST_FQDN" "$HOST_PRINCIPAL" || true
4060
fi
61+
62+
res=1
4163
if [ ! -e $CERTS_DIR/client-"$HOST_IP".crt ] ; then
4264
sudo ipa-getcert request -f $CERTS_DIR/client-"$HOST_IP".crt -k $CERTS_DIR/client-key-"$HOST_IP".pem -D "$HOST_FQDN" -K contrail/"$HOST_FQDN"@"${IPA_DOMAIN^^}"
43-
while [ ! -e $CERTS_DIR/client-"$HOST_IP".crt ] ; do sleep 1; done
65+
for i in {1..30} ; do
66+
echo "INFO: waiting for $CERTS_DIR/client-"$HOST_IP".crt to appear. Try $i from 30"
67+
if [ -e $CERTS_DIR/client-"$HOST_IP".crt ] ; then
68+
echo "INFO: $CERTS_DIR/client-"$HOST_IP".crt found"
69+
res=0
70+
break
71+
fi
72+
sleep 2
73+
done
4474
fi
4575

76+
if [[ $res == 1 ]]; then
77+
echo "INFO: sudo ipa-getcert request $CERTS_DIR/client-"$HOST_IP".crt failed. Exit"
78+
exit 1
79+
fi
80+
81+
res=1
4682
if [ ! -e $CERTS_DIR/server-"$HOST_IP".crt ] ; then
4783
sudo ipa-getcert request -f $CERTS_DIR/server-"$HOST_IP".crt -k $CERTS_DIR/server-key-"$HOST_IP".pem -D "$HOST_FQDN" -K contrail/"$HOST_FQDN"@"${IPA_DOMAIN^^}"
48-
while [ ! -e $CERTS_DIR/server-"$HOST_IP".crt ] ; do sleep 1; done
84+
for i in {1..30} ; do
85+
echo "INFO: waiting for $CERTS_DIR/server-"$HOST_IP".crt to appear. Try $i from 30"
86+
if [ -e $CERTS_DIR/server-"$HOST_IP".crt ] ; then
87+
echo "INFO: $CERTS_DIR/server-"$HOST_IP".crt found"
88+
res=0
89+
break
90+
fi
91+
sleep 2
92+
done
93+
fi
94+
95+
if [[ $res == 1 ]]; then
96+
echo "INFO: sudo ipa-getcert request failed $CERTS_DIR/server-"$HOST_IP".crt. Exit"
97+
exit 1
4998
fi
5099

51100
sudo chmod -R a+rX $CA_DIR

rhosp/ipa/freeipa_setup_root.sh renamed to contrib/ipa/freeipa_setup_root.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ source /etc/os-release
2525

2626
fqdn=$(hostname -f)
2727
domain=$(hostname -d)
28+
host_name=$(hostname -s)
2829
export Hostname=${Hostname:-"${fqdn}"}
2930
export DirectoryManagerPassword=${DirectoryManagerPassword:-"$AdminPassword"}
3031
export FreeIPAExtraArgs=${FreeIPAExtraArgs:-""}
3132
export CLOUD_DOMAIN_NAME=${CLOUD_DOMAIN_NAME:-"${domain}"}
32-
export FreeIPAIPSubnet=${FreeIPAIPSubnet:-'24'}
33-
export IPA_IFACE=${IPA_IFACE-'eth1'}
33+
export FreeIPAIPSubnet=$(ip addr show | grep -o "inet ${FreeIPAIP}/[0-9]* "| cut -d '/' -f2)
34+
export IPA_IFACE=$(ip addr show | grep "inet ${FreeIPAIP}" | awk '{print $(NF)}')
35+
export DEFAULT_IFACE=$(ip route list | grep default | cut -d ' ' -f5)
3436
export IPA_DNS1=${IPA_DNS1-'8.8.8.8'}
3537
export IPA_DNS2=${IPA_DNS2-'8.8.4.4'}
3638

@@ -47,8 +49,10 @@ IPADDR=$FreeIPAIP
4749
PREFIX=$FreeIPAIPSubnet
4850
EOM
4951
modprobe ipv6 || true
50-
ifdown $IPA_IFACE || true
51-
ifup $IPA_IFACE || true
52+
if [[ "$DEFAULT_IFACE" != "$IPA_IFACE" ]]; then
53+
ifdown $IPA_IFACE || true
54+
ifup $IPA_IFACE || true
55+
fi
5256
fi
5357

5458
if [[ -n "$IPA_DNS1" || -n "$IPA_DNS2" ]] ; then
@@ -155,6 +159,9 @@ function install_ipa_server() {
155159
return $res
156160
}
157161

162+
#Adding ipaserver fqdn to the /etc/hosts
163+
sed -i /etc/hosts -e "s/^${FreeIPAIP}.*$/${FreeIPAIP} ${fqdn} ${host_name}/"
164+
158165
for i in {1..5} ; do
159166
if install_ipa_server ; then
160167
break

contrib/ipa/server_install.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

openshift/functions.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,14 @@ function monitor_csr() {
153153
sleep 5
154154
done
155155
}
156+
157+
function wait_vhost0_up() {
158+
local node
159+
for node in $(echo ${CONTROLLER_NODES} ${AGENT_NODES} | tr ',' ' ') ; do
160+
scp $SSH_OPTIONS ${fmy_dir}/functions.sh ${node}:/tmp/functions.sh
161+
if ! ssh $SSH_OPTIONS ${node} "export PATH=\$PATH:/usr/sbin ; source /tmp/functions.sh ; wait_nic_up vhost0" ; then
162+
return 1
163+
fi
164+
done
165+
}
166+

0 commit comments

Comments
 (0)