-
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
5903c15
commit 2159456
Showing
2 changed files
with
41 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo $KARGO_VERSION |
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,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 | ||
|