Skip to content

Commit

Permalink
wip: Enhance CLI functionalities #188
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Nouguier committed Oct 20, 2020
1 parent 5903c15 commit 2159456
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions scripts/display-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo $KARGO_VERSION
39 changes: 38 additions & 1 deletion scripts/update-labels.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
#!/bin/bash

echo $KARGO_VERSION
usage() {
echo "usage: update-labels <node> <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

0 comments on commit 2159456

Please sign in to comment.