From 21594569d4a9680ee5c9d5f3df6cf36b65486ae6 Mon Sep 17 00:00:00 2001 From: Christophe Nouguier Date: Wed, 21 Oct 2020 00:45:46 +0200 Subject: [PATCH] wip: Enhance CLI functionalities #188 --- scripts/display-env.sh | 3 +++ scripts/update-labels.sh | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/scripts/display-env.sh b/scripts/display-env.sh index e69de29bb..b18336d7e 100644 --- a/scripts/display-env.sh +++ b/scripts/display-env.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo $KARGO_VERSION diff --git a/scripts/update-labels.sh b/scripts/update-labels.sh index 81828cbe2..0122daa1d 100755 --- a/scripts/update-labels.sh +++ b/scripts/update-labels.sh @@ -1,5 +1,42 @@ #!/bin/bash -echo $KARGO_VERSION +usage() { + echo "usage: update-labels " +} +help() { + echo "Update the labels of the specified node" + usage +} + +exec() { + local NODE=$1 + local LABELS=$2 + # Retrieve the existing labels + local EXISTING_LABELS=`docker node inspect -f '{{ range $k, $v := .Spec.Labels }}{{ $k }}={{ $v }} {{end}}' $NODE` + # Keep the existing labels if needed + for EXISTING_LABEL in $EXISTING_LABELS; do + if [[ ! $NEW_LABELS =~ $EXISTING_LABEL ]]; then + EXISTING_LABEL_KEY=${EXISTING_LABEL%=*} + docker node update --label-rm $EXISTING_LABEL_KEY $NODE > /dev/null + fi + done + # Add the label of needed + for LABEL in $LABELS; do + if [[ ! $EXISTING_LABELS =~ $LABEL ]]; then + docker node update --label-add $LABEL $NODE > /dev/null + fi + done +} + +if [ "$#" -ne 2 ]; then + echo error: illegal number of arguments + usage + exit 1 +fi + +case $1 in + -h|--help) help;; + *) exec "$1" "$2" +esac