Skip to content

Add 'kubectl rabbitmq version' sub command #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions bin/kubectl-rabbitmq
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,38 @@ USAGE:

Print this help
kubectl rabbitmq help

Print kubectl-rabbitmq plugin version
kubectl rabbitmq version
END
)
echo "$usage"
}

version() {
# Since we require to install this plugin via krew, we get the version from krew instead of hardcoding a version to this file.
failure_msg="version cannot be determined because plugin was not installed via krew"
if ! command -v kubectl-krew &> /dev/null
then
echo "$failure_msg"
exit 1
fi

# We can't use `krew info` because it provides versions about available - not installed - plugins.
# `krew list` provides versions of installed plugins.
# We can't redirect stdout of `krew list` because this will suppress the version number (see `kubectl krew list --help`)
# Therefore, we have to get the version number from the `krew list` logs.
version_line=$(kubectl krew -v 4 list 2>&1 | grep 'rabbitmq: version=' || true)
if [[ -z "$version_line" ]];
then
echo "$failure_msg"
exit 1
fi

version="${version_line##*rabbitmq: version=}"
echo "kubectl-rabbitmq $version"
}

get_instance_details() {
instance=${1}
username=$(kubectl get secret "${instance}-default-user" -o jsonpath="{.data.username}" | base64 --decode)
Expand Down Expand Up @@ -305,6 +332,9 @@ main() {
"-h")
usage
;;
"version")
version
;;
*)
usage
exit 1
Expand Down
14 changes: 14 additions & 0 deletions bin/kubectl-rabbitmq.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ eventually() {
return 1
}

@test "version outputs version" {
run kubectl rabbitmq version

if ! command -v kubectl-krew &> /dev/null
then
[ "$status" -eq 1 ]
[ "${lines[0]}" = "version cannot be determined because plugin was not installed via krew" ]
else
[ "$status" -eq 0 ]
version_regex='kubectl-rabbitmq v([0-9]+)\.([0-9]+)\.([0-9]+)$'
[[ "${lines[0]}" =~ $version_regex ]]
fi
}

@test "install-cluster-operator with too many args fails" {
run kubectl rabbitmq install-cluster-operator too-many-args

Expand Down