mirror of https://github.com/easzlab/kubeasz.git
fix: 带自定义变量时增加/删除节点可能失败
parent
56813cb01b
commit
655b2f4987
15
ezctl
15
ezctl
|
@ -294,10 +294,11 @@ function add-node() {
|
||||||
[[ $2 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { logger error "Invalid ip add:$2"; return 1; }
|
[[ $2 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { logger error "Invalid ip add:$2"; return 1; }
|
||||||
|
|
||||||
# check if the new node already exsited
|
# check if the new node already exsited
|
||||||
sed -n '/^\[kube_master/,/^\[harbor/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]*$" && { logger error "node $2 already existed in $BASE/clusters/$1/hosts"; return 2; }
|
sed -n '/^\[kube_master/,/^\[harbor/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]" && { logger error "node $2 already existed in $BASE/clusters/$1/hosts"; return 2; }
|
||||||
|
|
||||||
logger info "add $2 into 'kube_node' group"
|
logger info "add $2 into 'kube_node' group"
|
||||||
sed -i "/\[kube_node/a $2 NEW_NODE=yes ${@:3}" "$BASE/clusters/$1/hosts"
|
NODE_INFO="${@:2}"
|
||||||
|
sed -i "/\[kube_node/a $NODE_INFO" "$BASE/clusters/$1/hosts"
|
||||||
|
|
||||||
logger info "start to add a work node:$2 into cluster:$1"
|
logger info "start to add a work node:$2 into cluster:$1"
|
||||||
ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/22.addnode.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml"
|
ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/22.addnode.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml"
|
||||||
|
@ -308,10 +309,11 @@ function add-master() {
|
||||||
[[ $2 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { logger error "Invalid ip add:$2"; return 1; }
|
[[ $2 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { logger error "Invalid ip add:$2"; return 1; }
|
||||||
|
|
||||||
# check if the new master already exsited
|
# check if the new master already exsited
|
||||||
sed -n '/^\[kube_master/,/^\[kube_node/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]*$" && { logger error "master $2 already existed!"; return 2; }
|
sed -n '/^\[kube_master/,/^\[kube_node/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]" && { logger error "master $2 already existed!"; return 2; }
|
||||||
|
|
||||||
logger info "add $2 into 'kube_master' group"
|
logger info "add $2 into 'kube_master' group"
|
||||||
sed -i "/\[kube_master/a $2 NEW_MASTER=yes ${@:3}" "$BASE/clusters/$1/hosts"
|
MASTER_INFO="${@:2}"
|
||||||
|
sed -i "/\[kube_master/a $MASTER_INFO" "$BASE/clusters/$1/hosts"
|
||||||
|
|
||||||
logger info "start to add a master node:$2 into cluster:$1"
|
logger info "start to add a master node:$2 into cluster:$1"
|
||||||
ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/23.addmaster.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml"
|
ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/23.addmaster.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml"
|
||||||
|
@ -325,10 +327,11 @@ function add-etcd() {
|
||||||
[[ $2 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { logger error "Invalid ip add:$2"; return 1; }
|
[[ $2 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { logger error "Invalid ip add:$2"; return 1; }
|
||||||
|
|
||||||
# check if the new node already exsited
|
# check if the new node already exsited
|
||||||
sed -n '/^\[etcd/,/^\[kube_master/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]*$" && { logger error "etcd $2 already existed!"; return 2; }
|
sed -n '/^\[etcd/,/^\[kube_master/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]" && { logger error "etcd $2 already existed!"; return 2; }
|
||||||
|
|
||||||
logger info "add $2 into 'etcd' group"
|
logger info "add $2 into 'etcd' group"
|
||||||
sed -i "/\[etcd/a $2 NEW_ETCD=yes ${@:3}" "$BASE/clusters/$1/hosts"
|
ETCD_INFO="${@:2}"
|
||||||
|
sed -i "/\[etcd/a $ETCD_INFO" "$BASE/clusters/$1/hosts"
|
||||||
|
|
||||||
logger info "start to add a etcd node:$2 into cluster:$1"
|
logger info "start to add a etcd node:$2 into cluster:$1"
|
||||||
ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/21.addetcd.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml"
|
ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/21.addetcd.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml"
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
# lineinfile is inadequate to delete lines between some specific line range
|
# lineinfile is inadequate to delete lines between some specific line range
|
||||||
- name: remove the etcd's node entry in hosts
|
- name: remove the etcd's node entry in hosts
|
||||||
shell: 'sed -i "/^\[etcd/,/^\[kube_master/ {/^{{ ETCD_TO_DEL }}[^0-9]*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts'
|
shell: 'sed -i "/^\[etcd/,/^\[kube_master/ {/^{{ ETCD_TO_DEL }}[^0-9].*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts'
|
||||||
args:
|
args:
|
||||||
warn: false
|
warn: false
|
||||||
when: "groups['etcd']|length > 1 and ETCD_TO_DEL in groups['etcd']"
|
when: "groups['etcd']|length > 1 and ETCD_TO_DEL in groups['etcd']"
|
||||||
|
|
|
@ -26,6 +26,6 @@
|
||||||
|
|
||||||
# lineinfile is inadequate to delete lines between some specific line range
|
# lineinfile is inadequate to delete lines between some specific line range
|
||||||
- name: remove the node's entry in hosts
|
- name: remove the node's entry in hosts
|
||||||
shell: 'sed -i "/^\[kube_node/,/^\[harbor/ {/^{{ NODE_TO_DEL }}[^0-9]*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts'
|
shell: 'sed -i "/^\[kube_node/,/^\[harbor/ {/^{{ NODE_TO_DEL }}[^0-9].*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts'
|
||||||
args:
|
args:
|
||||||
warn: false
|
warn: false
|
||||||
|
|
|
@ -27,6 +27,6 @@
|
||||||
|
|
||||||
# lineinfile is inadequate to delete lines between some specific line range
|
# lineinfile is inadequate to delete lines between some specific line range
|
||||||
- name: remove the master's entry in hosts
|
- name: remove the master's entry in hosts
|
||||||
shell: 'sed -i "/^\[kube_master/,/^\[harbor/ {/^{{ NODE_TO_DEL }}[^0-9]*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts'
|
shell: 'sed -i "/^\[kube_master/,/^\[harbor/ {/^{{ NODE_TO_DEL }}[^0-9].*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts'
|
||||||
args:
|
args:
|
||||||
warn: false
|
warn: false
|
||||||
|
|
Loading…
Reference in New Issue