mirror of https://github.com/easzlab/kubeasz.git
修改easzctl list显示内容
parent
fd22fb6db2
commit
bf4d5976fb
|
@ -181,13 +181,13 @@ function save_context() {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "[INFO] save $CLUSTER ansible hosts"
|
|
||||||
if [ -f "$BASEPATH/hosts" ];then
|
if [ -f "$BASEPATH/hosts" ];then
|
||||||
|
echo "[INFO] save $CLUSTER ansible hosts"
|
||||||
cp -fp $BASEPATH/hosts $BASEPATH/.cluster/$CLUSTER/
|
cp -fp $BASEPATH/hosts $BASEPATH/.cluster/$CLUSTER/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[INFO] save $CLUSTER kubeconfig"
|
|
||||||
if [ -f /root/.kube/config ];then
|
if [ -f /root/.kube/config ];then
|
||||||
|
echo "[INFO] save $CLUSTER kubeconfig"
|
||||||
cp -fp /root/.kube/config $BASEPATH/.cluster/$CLUSTER/
|
cp -fp /root/.kube/config $BASEPATH/.cluster/$CLUSTER/
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -202,13 +202,13 @@ function install_context() {
|
||||||
cp -fp $BASEPATH/.cluster/$CLUSTER/roles/$ROLE/defaults/* $BASEPATH/roles/$ROLE/defaults/
|
cp -fp $BASEPATH/.cluster/$CLUSTER/roles/$ROLE/defaults/* $BASEPATH/roles/$ROLE/defaults/
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "[INFO] install $CLUSTER ansible hosts"
|
|
||||||
if [ -f "$BASEPATH/.cluster/$CLUSTER/hosts" ];then
|
if [ -f "$BASEPATH/.cluster/$CLUSTER/hosts" ];then
|
||||||
|
echo "[INFO] install $CLUSTER ansible hosts"
|
||||||
cp -fp $BASEPATH/.cluster/$CLUSTER/hosts $BASEPATH/
|
cp -fp $BASEPATH/.cluster/$CLUSTER/hosts $BASEPATH/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[INFO] install $CLUSTER kubeconfig"
|
|
||||||
if [ -f "$BASEPATH/.cluster/$CLUSTER/config" ];then
|
if [ -f "$BASEPATH/.cluster/$CLUSTER/config" ];then
|
||||||
|
echo "[INFO] install $CLUSTER kubeconfig"
|
||||||
cp -fp $BASEPATH/.cluster/$CLUSTER/config /root/.kube/
|
cp -fp $BASEPATH/.cluster/$CLUSTER/config /root/.kube/
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -249,32 +249,37 @@ function setup() {
|
||||||
echo -e "[INFO] setup begin in 5s, press 'Enter' to abort\n:"
|
echo -e "[INFO] setup begin in 5s, press 'Enter' to abort\n:"
|
||||||
! (read -t 5 ANS) || { echo "[WARN] setup aborted"; return 1; }
|
! (read -t 5 ANS) || { echo "[WARN] setup aborted"; return 1; }
|
||||||
ansible-playbook $BASEPATH/90.setup.yml
|
ansible-playbook $BASEPATH/90.setup.yml
|
||||||
|
save_context
|
||||||
}
|
}
|
||||||
|
|
||||||
function list() {
|
function list() {
|
||||||
[ -d "$BASEPATH/.cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
[ -d "$BASEPATH/.cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
||||||
CLUSTER=$(cat $BASEPATH/.cluster/current_cluster)
|
CLUSTER=$(cat $BASEPATH/.cluster/current_cluster)
|
||||||
#save_context $CLUSTER
|
echo -e "\nlist of managed contexts (current: $CLUSTER)"
|
||||||
i=1
|
i=1; for Cluster in $(ls $BASEPATH/.cluster/ |grep -v current_cluster);
|
||||||
for Cluster in $(ls $BASEPATH/.cluster/ |grep -v current_cluster);
|
do
|
||||||
|
echo -e "==> context $i:\t$Cluster"
|
||||||
|
let "i++"
|
||||||
|
done
|
||||||
|
echo -e "\nlist of installed clusters (current: $CLUSTER)"
|
||||||
|
i=1; for Cluster in $(ls $BASEPATH/.cluster/ |grep -v current_cluster);
|
||||||
do
|
do
|
||||||
KUBECONF=$BASEPATH/.cluster/$Cluster/config
|
KUBECONF=$BASEPATH/.cluster/$Cluster/config
|
||||||
if [ -f "$KUBECONF" ]; then
|
if [ -f "$KUBECONF" ]; then
|
||||||
echo -e "\ncluster $i: $Cluster"
|
echo -e "==> cluster $i:\t$Cluster"
|
||||||
$BASEPATH/bin/kubectl --kubeconfig=$KUBECONF get node
|
$BASEPATH/bin/kubectl --kubeconfig=$KUBECONF get node
|
||||||
fi
|
fi
|
||||||
let "i++"
|
let "i++"
|
||||||
done
|
done
|
||||||
echo -e "\nCurrent cluster context is: $CLUSTER"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function destroy() {
|
function destroy() {
|
||||||
[ -d "$BASEPATH/.cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
[ -d "$BASEPATH/.cluster" ] || { echo "[ERROR] invalid context, run 'easzctl checkout <cluster_name>' first"; return 1; }
|
||||||
CLUSTER=$(cat $BASEPATH/.cluster/current_cluster)
|
CLUSTER=$(cat $BASEPATH/.cluster/current_cluster)
|
||||||
echo -e "[WARN] DELETE cluster: $CLUSTER, Continue? y/n:\n"
|
echo -n "[WARN] DELETE cluster: $CLUSTER, Continue? (y/n): "
|
||||||
read -t 15 ANS || { echo "[WARN] timeout, destroy aborted"; return 1; }
|
read -t10 -n1 ANS || { echo -e "\n[WARN] timeout, destroy aborted"; return 1; }
|
||||||
if [[ -n $ANS && $ANS == y ]];then
|
if [[ -n $ANS && $ANS == y ]];then
|
||||||
echo "[INFO] clean all nodes of cluster"
|
echo -e "\n[INFO] clean all nodes of cluster in 5s"
|
||||||
sleep 5
|
sleep 5
|
||||||
ansible-playbook $BASEPATH/99.clean.yml
|
ansible-playbook $BASEPATH/99.clean.yml
|
||||||
rm -f $BASEPATH/.cluster/$CLUSTER/config
|
rm -f $BASEPATH/.cluster/$CLUSTER/config
|
||||||
|
@ -288,7 +293,7 @@ function destroy() {
|
||||||
install_context
|
install_context
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "[WARN] destroy aborted"; return 1;
|
echo -e "\n[WARN] destroy aborted"; return 1;
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
### Main Lines ##################################################
|
### Main Lines ##################################################
|
||||||
|
|
Loading…
Reference in New Issue