-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Enhance CLI functionalities #188
- Loading branch information
Christophe Nouguier
committed
Oct 20, 2020
1 parent
3880f09
commit 5903c15
Showing
3 changed files
with
34 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,5 @@ | ||
#!/bin/bash | ||
|
||
usage() { | ||
echo "usage: update-labels <node> <labels>" | ||
} | ||
echo $KARGO_VERSION | ||
|
||
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 | ||
|