Skip to content

Commit d1f8cf1

Browse files
authored
Merge pull request #282 from jprovaznik/scaleup
Use new_nodes for scaleup
2 parents ca0a112 + 9a1233c commit d1f8cf1

3 files changed

Lines changed: 44 additions & 14 deletions

File tree

fragments/bastion-ansible.sh

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,28 @@ set -eu
55
set -x
66
set -o pipefail
77

8-
INVENTORY=/var/lib/ansible/inventory
9-
NODESFILE=/var/lib/ansible/node_list
8+
ANSDIR=/var/lib/ansible
9+
INVENTORY=$ANSDIR/inventory
10+
NODESFILE=$ANSDIR/node_list
11+
12+
function get_new_nodes() {
13+
# compare old and new list of nodes and return all newly added nodes
14+
# separated by comma instead of newline
15+
if [ -e ${ANSDIR}.deployed ]; then
16+
str=$(comm -13 <(sort ${ANSDIR}.deployed/node_list) <(sort ${ANSDIR}/node_list) | sed ':a;N;$!ba;s/\n/","/g')
17+
[ -z "$str" ] && echo '' || echo "\"$str\""
18+
else
19+
echo ''
20+
fi
21+
}
1022

1123
function create_metadata_json() {
1224
# $1 - metadata filename
1325
infra_arr=($all_infra_nodes)
1426
infra_count=${#infra_arr[@]}
1527
master_arr=($all_master_nodes)
1628
master_count=${#master_arr[@]}
29+
new_nodes=$(get_new_nodes)
1730
if [ -n "$os_username" ] && [ -n "$os_password" ] && \
1831
[ -n "$os_auth_url" ] && [ -n "$os_tenant_name" ]; then
1932
openstack_cloud_provider=true
@@ -40,6 +53,7 @@ function create_metadata_json() {
4053
"infra_nodes": ["$(echo "$all_infra_nodes" | sed 's/ /","/g')"],
4154
"infra_count": $infra_count,
4255
"nodes": ["$(sed ':a;N;$!ba;s/\n/","/g' $NODESFILE)"],
56+
"new_nodes": [$new_nodes],
4357
"deploy_router_or_registry": $deploy_router_or_registry,
4458
"domainname": "$domainname",
4559
"lb_hostname": "$lb_hostname",
@@ -64,7 +78,7 @@ function create_metadata_json() {
6478
"ldap_url": "$ldap_url",
6579
"ldap_preferred_username": "$ldap_preferred_username",
6680
"bastion_instance_id": "$bastion_instance_id",
67-
"ansible_first_run": $([ -e ${INVENTORY}.deployed ] && echo false || echo true),
81+
"ansible_first_run": $([ -e ${ANSDIR}.deployed ] && echo false || echo true),
6882
"router_vip": "$router_vip",
6983
"volume_quota": $volume_quota
7084
}
@@ -107,11 +121,15 @@ EOF
107121
}
108122

109123
function is_scaleup() {
110-
# check if there are only new openshift nodes added - then we can play the
111-
# scaleup playbook, otherwise we run the main playbook
112-
[ -e ${INVENTORY}.deployed ] || return 1
113-
(diff $INVENTORY ${INVENTORY}.deployed |
114-
grep '^[<>]' | grep -v '^< .*-node') && return 1 || return 0
124+
# check if there are only new openshift nodes added - then we can play the
125+
# scaleup playbook, otherwise we run the main playbook
126+
[ -e ${ANSDIR}.deployed ] || return 1
127+
# check if diff between old and new inventory file contains only
128+
# node changes (ignore 'new_nodes' changes because nodes
129+
# are removed from [new_nodes] on the next stack-update run
130+
(diff $ANSDIR/inventory ${ANSDIR}.deployed/inventory | grep '^[<>]' |
131+
grep -v new_nodes | grep -v '[<>] $' |
132+
grep -v '.*-node') && return 1 || return 0
115133
}
116134

117135
function update_etc_hosts() {
@@ -154,13 +172,14 @@ while pidof -x /bin/ansible-playbook /usr/bin/ansible-playbook; do
154172
sleep 10
155173
done
156174

157-
if [ -e ${INVENTORY}.deployed ] &&
158-
diff $INVENTORY ${INVENTORY}.deployed; then
175+
if [ -e ${ANSDIR}.deployed ] &&
176+
diff $ANSDIR/inventory ${ANSDIR}.deployed/inventory; then
159177
echo "inventory file has not changed since last ansible run, no need to re-run"
160178
exit 0
161179
fi
162180

163-
cp ${INVENTORY} ${INVENTORY}.started
181+
[ -e ${ANSDIR}.started ] && rm -rf ${ANSDIR}.started
182+
cp -a ${ANSDIR} ${ANSDIR}.started
164183

165184
# crond was stopped in cloud-init before yum update, make sure it's running
166185
systemctl status crond && systemctl restart crond
@@ -183,5 +202,6 @@ if ! $cmd > $logfile 2>&1; then
183202
echo "Failed to run '$cmd', full log is in $(hostname):$logfile" >&2
184203
exit 1
185204
else
186-
mv ${INVENTORY}.started ${INVENTORY}.deployed
205+
[ -e ${ANSDIR}.deployed ] && rm -rf ${ANSDIR}.deployed
206+
mv ${ANSDIR}.started ${ANSDIR}.deployed
187207
fi

templates/var/lib/ansible/inventory

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ bastion
66
masters
77
nodes
88
etcd
9+
{{^ansible_first_run}}
10+
new_nodes
11+
{{/ansible_first_run}}
912
{{#dedicated_lb}}
1013
lb
1114

@@ -44,6 +47,13 @@ localhost
4447
{{.}} openshift_node_labels="{'region': 'primary', 'zone': 'default'}"
4548
{{/nodes}}
4649

50+
{{^ansible_first_run}}
51+
[new_nodes]
52+
{{#new_nodes}}
53+
{{.}} openshift_node_labels="{'region': 'primary', 'zone': 'default'}"
54+
{{/new_nodes}}
55+
{{/ansible_first_run}}
56+
4757
[dns]
4858
localhost
4959
{{^no_lb}}

templates/var/lib/ansible/playbooks/scaleup.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ cat << 'EOF' > /var/lib/os-apply-config/templates/var/lib/ansible/playbooks/scal
99
vars:
1010
openshift_infra_nodes: "{{ groups.infra | default([]) }}"
1111

12-
- hosts: nodes
12+
- hosts: new_nodes
1313
sudo: yes
1414
tasks:
1515
- name: Allow docker traffic
1616
shell: iptables -A DOCKER -p tcp -j ACCEPT
1717
when: openshift_use_flannel
1818

19-
- hosts: nodes
19+
- hosts: new_nodes
2020
sudo: yes
2121
tasks:
2222
- name: Restart node service

0 commit comments

Comments
 (0)