From 655b2f4987c5cb335761cadd6c40cb06dd5c9f5a Mon Sep 17 00:00:00 2001 From: gjmzj Date: Mon, 1 Feb 2021 22:05:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B8=A6=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E6=97=B6=E5=A2=9E=E5=8A=A0/=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=8A=82=E7=82=B9=E5=8F=AF=E8=83=BD=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ezctl | 15 +++++++++------ playbooks/31.deletcd.yml | 2 +- playbooks/32.delnode.yml | 2 +- playbooks/33.delmaster.yml | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ezctl b/ezctl index bf1aee1..a34ab4d 100755 --- a/ezctl +++ b/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; } # 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" - 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" 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; } # 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" - 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" 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; } # 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" - 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" ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/21.addetcd.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml" diff --git a/playbooks/31.deletcd.yml b/playbooks/31.deletcd.yml index 04eaf25..8b02883 100644 --- a/playbooks/31.deletcd.yml +++ b/playbooks/31.deletcd.yml @@ -73,7 +73,7 @@ # lineinfile is inadequate to delete lines between some specific line range - 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: warn: false when: "groups['etcd']|length > 1 and ETCD_TO_DEL in groups['etcd']" diff --git a/playbooks/32.delnode.yml b/playbooks/32.delnode.yml index a37ec98..caeddbd 100644 --- a/playbooks/32.delnode.yml +++ b/playbooks/32.delnode.yml @@ -26,6 +26,6 @@ # lineinfile is inadequate to delete lines between some specific line range - 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: warn: false diff --git a/playbooks/33.delmaster.yml b/playbooks/33.delmaster.yml index 4b01e03..8c2f8bb 100644 --- a/playbooks/33.delmaster.yml +++ b/playbooks/33.delmaster.yml @@ -27,6 +27,6 @@ # lineinfile is inadequate to delete lines between some specific line range - 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: warn: false