bin: shellscript housekeeping (#13469)

- Use single quotes for static strings, not double
- Use sh and not bash for _os.sh that has no bash-specific content
- Remove superfluous double quotes on variable assignments
- Only use bash-specific [[ ]] if statements for bash-specific content
- Consistently use style with if; then on same line

Change-Id: I1575971262773149db32021efbf2d7f1d4df9771

Signed-off-by: Joakim Roubert <joakimr@axis.com>
This commit is contained in:
Joakim Roubert 2024-12-12 16:28:14 +01:00 committed by GitHub
parent 0d9c86c866
commit 2b92b07b19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 62 additions and 67 deletions

View File

@ -65,17 +65,17 @@ docker_build() {
shift shift
rootdir=${ROOTDIR:-$( cd "$bindir"/.. && pwd )} rootdir=${ROOTDIR:-$( cd "$bindir"/.. && pwd )}
cache_params="" cache_params=''
if [ "$ACTIONS_CACHE_URL" ]; then if [ "$ACTIONS_CACHE_URL" ]; then
cache_params="--cache-from type=gha,scope=$name-$DOCKER_TARGET --cache-to type=gha,scope=$name-$DOCKER_TARGET,mode=max" cache_params="--cache-from type=gha,scope=$name-$DOCKER_TARGET --cache-to type=gha,scope=$name-$DOCKER_TARGET,mode=max"
fi fi
output_params="--load" output_params='--load'
if [ "$DOCKER_TARGET" = 'multi-arch' ]; then if [ "$DOCKER_TARGET" = 'multi-arch' ]; then
output_params="--platform $SUPPORTED_ARCHS" output_params="--platform $SUPPORTED_ARCHS"
if [ "$DOCKER_PUSH" ]; then if [ "$DOCKER_PUSH" ]; then
output_params+=" --push" output_params+=' --push'
else else
echo 'Error: env DOCKER_PUSH=1 is missing echo 'Error: env DOCKER_PUSH=1 is missing
When building the multi-arch images it is required to push the images to the registry When building the multi-arch images it is required to push the images to the registry

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env sh
set -eu set -eu
export OS_ARCH_ALL="linux-amd64 linux-arm64 linux-arm darwin darwin-arm64 windows" export OS_ARCH_ALL='linux-amd64 linux-arm64 linux-arm darwin darwin-arm64 windows'
architecture() { architecture() {
arch=$(uname -m) arch=$(uname -m)
@ -32,7 +32,7 @@ architecture() {
os() { os() {
os=$(uname -s) os=$(uname -s)
arch="" arch=''
case $os in case $os in
CYGWIN* | MINGW64*) CYGWIN* | MINGW64*)
os=windows os=windows

View File

@ -11,7 +11,7 @@ clean_head() {
} }
named_tag() { named_tag() {
tag="$(git name-rev --tags --name-only "$(git_sha_head)")" tag=$(git name-rev --tags --name-only "$(git_sha_head)")
tag=${tag%"^0"} tag=${tag%"^0"}
echo "${tag}" echo "${tag}"
} }

View File

@ -8,7 +8,7 @@ k8s_version_min='+v1.22'
k8s_version_max='docker.io/rancher/k3s:v1.29.6-k3s2' k8s_version_max='docker.io/rancher/k3s:v1.29.6-k3s2'
bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd ) bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
testdir="$bindir"/../test/integration testdir=$bindir/../test/integration
##### Test setup helpers ##### ##### Test setup helpers #####
@ -20,7 +20,7 @@ export all_test_names=(cluster-domain cni-calico-deep multicluster "${default_te
images_load_default=(proxy controller policy-controller web metrics-api tap) images_load_default=(proxy controller policy-controller web metrics-api tap)
tests_usage() { tests_usage() {
progname="${0##*/}" progname=${0##*/}
echo "Run Linkerd integration tests. echo "Run Linkerd integration tests.
Optionally specify a test with the --name flag: [${all_test_names[*]}] Optionally specify a test with the --name flag: [${all_test_names[*]}]
@ -56,7 +56,7 @@ Available Commands:
} }
cleanup_usage() { cleanup_usage() {
progname="${0##*/}" progname=${0##*/}
echo "Cleanup Linkerd integration tests. echo "Cleanup Linkerd integration tests.
Usage: Usage:
@ -76,7 +76,7 @@ handle_tests_input() {
export skip_cluster_create='' export skip_cluster_create=''
export skip_cluster_delete='' export skip_cluster_delete=''
export cleanup_docker='' export cleanup_docker=''
export linkerd_path="" export linkerd_path=''
while [ $# -ne 0 ]; do while [ $# -ne 0 ]; do
case $1 in case $1 in
@ -227,7 +227,7 @@ cleanup_cluster() {
setup_min_cluster() { setup_min_cluster() {
local name=$1 local name=$1
export helm_path="$bindir"/helm export helm_path=$bindir/helm
check_linkerd_binary check_linkerd_binary
if [ -z "$skip_cluster_create" ]; then if [ -z "$skip_cluster_create" ]; then
@ -239,7 +239,7 @@ setup_min_cluster() {
setup_cluster() { setup_cluster() {
local name=$1 local name=$1
export helm_path="$bindir"/helm export helm_path=$bindir/helm
check_linkerd_binary check_linkerd_binary
if [ -z "$skip_cluster_create" ]; then if [ -z "$skip_cluster_create" ]; then
@ -428,7 +428,7 @@ run_helm-upgrade_test() {
fi fi
setup_helm setup_helm
helm_viz_chart="$( cd "$bindir"/.. && pwd )"/viz/charts/linkerd-viz helm_viz_chart=$( cd "$bindir"/.. && pwd )/viz/charts/linkerd-viz
run_test "$testdir/install/install_test.go" --helm-path="$helm_path" --helm-charts="$helm_charts" \ run_test "$testdir/install/install_test.go" --helm-path="$helm_path" --helm-charts="$helm_charts" \
--viz-helm-chart="$helm_viz_chart" --viz-helm-stable-chart="linkerd/linkerd-viz" --helm-release="$helm_release_name" --upgrade-helm-from-version="$edge_version" --viz-helm-chart="$helm_viz_chart" --viz-helm-stable-chart="linkerd/linkerd-viz" --helm-release="$helm_release_name" --upgrade-helm-from-version="$edge_version"
helm_cleanup helm_cleanup

View File

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
#
set -eu set -eu
# Creates the root and issuer (intermediary) self-signed certificates for the control plane using openssl. # Creates the root and issuer (intermediary) self-signed certificates for the control plane using openssl.

View File

@ -9,12 +9,11 @@ targetbin=$( cd "$bindir"/.. && pwd )/target/bin
dockerbin=$targetbin/.docker-$dockerversion dockerbin=$targetbin/.docker-$dockerversion
if [ ! -f "$dockerbin" ]; then if [ ! -f "$dockerbin" ]; then
filename=docker-$dockerversion.tgz
if [ "$(uname -s)" = Darwin ]; then if [ "$(uname -s)" = Darwin ]; then
os=mac os=mac
filename=docker-$dockerversion.tgz
else else
os=linux os=linux
filename=docker-$dockerversion.tgz
fi fi
url=https://download.docker.com/$os/static/stable/x86_64/$filename url=https://download.docker.com/$os/static/stable/x86_64/$filename

View File

@ -3,7 +3,7 @@
set -eu set -eu
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
tag="${1:-}" tag=${1:-}
else else
echo "usage: ${0##*/} tag" >&2 echo "usage: ${0##*/} tag" >&2
exit 64 exit 64

View File

@ -9,16 +9,16 @@ set -eu
bindir=$( cd "${0%/*}" && pwd ) bindir=$( cd "${0%/*}" && pwd )
rootdir=$( cd "$bindir"/.. && pwd ) rootdir=$( cd "$bindir"/.. && pwd )
builddir="$rootdir/target/proxy" builddir=$rootdir/target/proxy
proxy_repo="${LINKERD2_PROXY_REPO:-}" proxy_repo=${LINKERD2_PROXY_REPO:-}
if [ -z "$proxy_repo" ]; then if [ -z "$proxy_repo" ]; then
proxy_repo=linkerd/linkerd2-proxy proxy_repo=linkerd/linkerd2-proxy
fi fi
releases_url=https://api.github.com/repos/"$proxy_repo"/releases releases_url=https://api.github.com/repos/"$proxy_repo"/releases
github_token="${GITHUB_TOKEN:-}" github_token=${GITHUB_TOKEN:-}
if [ -z "$github_token" ] && [ -n "${GITHUB_TOKEN_FILE:-}" ] && [ -f "$GITHUB_TOKEN_FILE" ]; then if [ -z "$github_token" ] && [ -n "${GITHUB_TOKEN_FILE:-}" ] && [ -f "$GITHUB_TOKEN_FILE" ]; then
github_token=$(cat "$GITHUB_TOKEN_FILE") github_token=$(cat "$GITHUB_TOKEN_FILE")
fi fi
@ -42,16 +42,16 @@ if ! ghcurl "$releases_url" | jq '.[] | select(.name == "'"$version"'")' > relea
exit 1 exit 1
fi fi
pkgname="linkerd2-proxy-${version}-${arch}" pkgname=linkerd2-proxy-${version}-${arch}
pkgfile="${pkgname}.tar.gz" pkgfile=${pkgname}.tar.gz
pkgurl=$(jq -r '.assets[] | select(.name == "'"$pkgfile"'") | .url' release.json) pkgurl=$(jq -r '.assets[] | select(.name == "'"$pkgfile"'") | .url' release.json)
if ! ghcurl -H 'Accept: application/octet-stream' -o "$pkgfile" "$pkgurl" ; then if ! ghcurl -H 'Accept: application/octet-stream' -o "$pkgfile" "$pkgurl" ; then
echo "Failed to fetch $pkgurl" >&2 echo "Failed to fetch $pkgurl" >&2
exit 1 exit 1
fi fi
shafile="${pkgname}.txt" shafile=${pkgname}.txt
shaurl=$(jq -r '.assets[] | select(.name == "'"$shafile"'") | .url' release.json) shaurl=$(jq -r '.assets[] | select(.name == "'"$shafile"'") | .url' release.json)
if ! ghcurl -H 'Accept: application/octet-stream' -o "$shafile" "$shaurl" ; then if ! ghcurl -H 'Accept: application/octet-stream' -o "$shafile" "$shaurl" ; then
echo "Failed to fetch $shaurl" >&2 echo "Failed to fetch $shaurl" >&2

View File

@ -8,7 +8,7 @@ if [ $# -gt 1 ]; then
echo "Usage: $0 [root]" >&2 echo "Usage: $0 [root]" >&2
exit 64 exit 64
fi fi
declare -r MODULE="${1:-github.com/linkerd/linkerd2}" declare -r MODULE=${1:-github.com/linkerd/linkerd2}
GRAPH=$(go mod graph) GRAPH=$(go mod graph)
declare -r GRAPH declare -r GRAPH

View File

@ -8,7 +8,7 @@ if [ $# -ne 1 ]; then
echo "Usage: $0 <module>" >&2 echo "Usage: $0 <module>" >&2
exit 64 exit 64
fi fi
declare -r MODULE="$1" declare -r MODULE=$1
if [[ "$MODULE" == *@* ]]; then if [[ "$MODULE" == *@* ]]; then
echo 'The dependency must not specify an exact version.' >&2 echo 'The dependency must not specify an exact version.' >&2

View File

@ -8,7 +8,7 @@ if [ $# -ne 1 ]; then
echo "Usage: $0 <module>" >&2 echo "Usage: $0 <module>" >&2
exit 64 exit 64
fi fi
declare -r MODULE="$1" declare -r MODULE=$1
GRAPH=$(go mod graph) GRAPH=$(go mod graph)
declare -r GRAPH declare -r GRAPH

View File

@ -22,7 +22,7 @@ if [ ! -f "$helmbin" ]; then
arm) dpkg --print-architecture | grep -q arm64 && arch=arm64 || arch=arm ;; arm) dpkg --print-architecture | grep -q arm64 && arch=arm64 || arch=arm ;;
esac esac
fi fi
helmcurl="https://get.helm.sh/helm-$helmversion-$os-$arch.tar.gz" helmcurl=https://get.helm.sh/helm-$helmversion-$os-$arch.tar.gz
targetdir=$os-$arch targetdir=$os-$arch
tmp=$(mktemp -d -t helm.XXX) tmp=$(mktemp -d -t helm.XXX)
mkdir -p "$targetbin" mkdir -p "$targetbin"

View File

@ -11,7 +11,7 @@ bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
. "$bindir"/_tag.sh . "$bindir"/_tag.sh
tag=$(named_tag) tag=$(named_tag)
edge_tag_regex="edge-([0-9][0-9])\.([0-9]|[0-9][0-9])\.([0-9]+)" edge_tag_regex='edge-([0-9][0-9])\.([0-9]|[0-9][0-9])\.([0-9]+)'
# Get the current edge version. # Get the current edge version.
url=https://run.linkerd.io/install-edge url=https://run.linkerd.io/install-edge
@ -24,7 +24,7 @@ yyyy=$(date +"%Y")
new_mm=$(date +"%-m") new_mm=$(date +"%-m")
# If this is a new month, `new_xx` should be 1; otherwise increment it. # If this is a new month, `new_xx` should be 1; otherwise increment it.
if [[ "$new_mm" != "$current_mm" ]]; then if [ "$new_mm" != "$current_mm" ]; then
new_xx=1 new_xx=1
else else
new_xx=$((current_xx+1)) new_xx=$((current_xx+1))
@ -32,7 +32,7 @@ fi
expected_tag="edge-$yy.$new_mm.$new_xx" expected_tag="edge-$yy.$new_mm.$new_xx"
if [[ "$tag" != "$expected_tag" ]]; then if [ "$tag" != "$expected_tag" ]; then
echo "Tag ($tag) doesn't match computed edge version ($expected_tag)" echo "Tag ($tag) doesn't match computed edge version ($expected_tag)"
exit 1 exit 1
fi fi

View File

@ -10,8 +10,8 @@ helmdocsv=1.12.0
bindir=$( cd "${0%/*}" && pwd ) # Change to script dir and set bin dir to this bindir=$( cd "${0%/*}" && pwd ) # Change to script dir and set bin dir to this
targetbin=$( cd "$bindir"/.. && pwd )/target/bin targetbin=$( cd "$bindir"/.. && pwd )/target/bin
helmdocsbin=$targetbin/helm-docs-$helmdocsv helmdocsbin=$targetbin/helm-docs-$helmdocsv
os="" os=''
arch="" arch=''
if [ ! -f "$helmdocsbin" ]; then if [ ! -f "$helmdocsbin" ]; then
case $(uname | tr '[:upper:]' '[:lower:]') in case $(uname | tr '[:upper:]' '[:lower:]') in

View File

@ -91,11 +91,11 @@ if [ "$k3d" ]; then
if [ -z "$cluster" ]; then if [ -z "$cluster" ]; then
cluster=k3s-default cluster=k3s-default
fi fi
bin="$bindir"/k3d bin=$bindir/k3d
image_sub_cmd=(image import -c "$cluster") image_sub_cmd=(image import -c "$cluster")
else else
kind=1 kind=1
bin="$bindir"/kind bin=$bindir/kind
if [ -z "$cluster" ]; then if [ -z "$cluster" ]; then
cluster=kind cluster=kind
fi fi
@ -106,8 +106,7 @@ else
fi fi
fi fi
if [ -z "$archive" ] if [ -z "$archive" ]; then
then
# shellcheck source=_tag.sh # shellcheck source=_tag.sh
. "$bindir"/_tag.sh . "$bindir"/_tag.sh
# shellcheck source=_docker.sh # shellcheck source=_docker.sh
@ -122,9 +121,9 @@ fi
rm -f load_fail rm -f load_fail
for i in "${!images[@]}"; do for i in "${!images[@]}"; do
if [ $archive ]; then if [ $archive ]; then
param="image-archives/${images[$i]}.tar" param=image-archives/${images[$i]}.tar
else else
param="$DOCKER_REGISTRY/${images[$i]}:$TAG" param=$DOCKER_REGISTRY/${images[$i]}:$TAG
if [ $preload ]; then if [ $preload ]; then
docker pull -q "$param" || (echo "Error pulling image $param"; touch load_fail) & docker pull -q "$param" || (echo "Error pulling image $param"; touch load_fail) &
fi fi

View File

@ -60,16 +60,14 @@ done
pr=$1 pr=$1
if [ -z "$pr" ] if [ -z "$pr" ]; then
then
echo "Error: ${0##*/} accepts 1 argument echo "Error: ${0##*/} accepts 1 argument
Usage: Usage:
${0##*/} ####" >&2 ${0##*/} ####" >&2
exit 1 exit 1
fi fi
if [ -z "$GITHUB_TOKEN" ] if [ -z "$GITHUB_TOKEN" ]; then
then
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo 'Error: Generate a personal access token at https://github.com/settings/tokens and set it in the $GITHUB_TOKEN env var' echo 'Error: Generate a personal access token at https://github.com/settings/tokens and set it in the $GITHUB_TOKEN env var'
exit 1 exit 1
@ -108,18 +106,16 @@ do
docker load -i "image-archives/$image.tar" docker load -i "image-archives/$image.tar"
done done
if [ "$is_kind" = true ] || [ "$is_k3d" = true ] if [ "$is_kind" = true ] || [ "$is_k3d" = true ]; then
then
# When importing into k3d or kind, the images must be renamed to use the # When importing into k3d or kind, the images must be renamed to use the
# proper registry so that users don't have to change the default install # proper registry so that users don't have to change the default install
# output. # output.
docker_rename_registry "$tag" 'ghcr.io/linkerd' 'cr.l5d.io/linkerd' docker_rename_registry "$tag" 'ghcr.io/linkerd' 'cr.l5d.io/linkerd'
distro=k3d distro=k3d
if [ "$is_kind" = true ] if [ "$is_kind" = true ]; then
then
distro=kind distro=kind
fi fi
export TAG="$tag" export TAG=$tag
"$bindir"/image-load --"$distro" --cluster "$cluster" "$bindir"/image-load --"$distro" --cluster "$cluster"
else else
# The images were built with the ghcr.io registry so when pushing to a # The images were built with the ghcr.io registry so when pushing to a

View File

@ -10,7 +10,7 @@ bindir=$( cd "${0%/*}" && pwd )
. "$bindir"/_os.sh . "$bindir"/_os.sh
targetbin=$( cd "$bindir"/.. && pwd )/target/bin targetbin=$( cd "$bindir"/.. && pwd )/target/bin
k3dbin="$targetbin/k3d-${K3D_VERSION}" k3dbin=$targetbin/k3d-${K3D_VERSION}
if [ ! -f "$k3dbin" ]; then if [ ! -f "$k3dbin" ]; then
arch=$(architecture) arch=$(architecture)

View File

@ -15,10 +15,10 @@ if [[ $toolchain =~ $version_regex ]]; then
fi fi
# Otherwise, no matching line was found, so print an error. # Otherwise, no matching line was found, so print an error.
if [[ "${GITHUB_ACTIONS:-false}" == "true" ]]; then if [ "${GITHUB_ACTIONS:-false}" = 'true' ]; then
echo "::error file=rust-toolchain.toml::failed to parse rust-toolchain.toml" echo '::error file=rust-toolchain.toml::failed to parse rust-toolchain.toml'
else else
echo "failed to parse rust-toolchain.toml" echo 'failed to parse rust-toolchain.toml'
fi fi
exit 1 exit 1

View File

@ -98,13 +98,13 @@ done
BOOKS_APP=$("$bindir"/scurl https://raw.githubusercontent.com/BuoyantIO/booksapp/main/k8s/mysql-app.yml) BOOKS_APP=$("$bindir"/scurl https://raw.githubusercontent.com/BuoyantIO/booksapp/main/k8s/mysql-app.yml)
# add "-sleep=10ms" param to the traffic app (~100rps) # add "-sleep=10ms" param to the traffic app (~100rps)
traffic_param=" - \"webapp:7000\"" traffic_param=' - "webapp:7000"'
sleep_param=$(cat <<-END sleep_param=$(cat <<-END
- "-sleep=10ms" - "-sleep=10ms"
- "webapp:7000" - "webapp:7000"
END END
) )
BOOKS_APP="${BOOKS_APP/$traffic_param/$sleep_param}" BOOKS_APP=${BOOKS_APP/$traffic_param/$sleep_param}
# inject # inject
BOOKS_APP=$(echo "$BOOKS_APP" | "$linkerd_path" -l "$linkerd_namespace" inject -) BOOKS_APP=$(echo "$BOOKS_APP" | "$linkerd_path" -l "$linkerd_namespace" inject -)
@ -128,10 +128,10 @@ EMOJIVOTO=$("$bindir"/scurl https://run.linkerd.io/emojivoto.yml)
# delete namespace # delete namespace
EMOJIVOTO=$(echo "$EMOJIVOTO" | tail -n +6) EMOJIVOTO=$(echo "$EMOJIVOTO" | tail -n +6)
emojins='namespace: emojivoto' emojins='namespace: emojivoto'
EMOJIVOTO="${EMOJIVOTO//$emojins/}" EMOJIVOTO=${EMOJIVOTO//$emojins/}
emojins=.emojivoto: emojins=.emojivoto:
newns=: newns=:
EMOJIVOTO="${EMOJIVOTO//$emojins/$newns}" EMOJIVOTO=${EMOJIVOTO//$emojins/$newns}
# inject # inject
EMOJIVOTO=$(echo "$EMOJIVOTO" | "$linkerd_path" -l "$linkerd_namespace" inject -) EMOJIVOTO=$(echo "$EMOJIVOTO" | "$linkerd_path" -l "$linkerd_namespace" inject -)

View File

@ -4,8 +4,8 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
SCRIPT_ROOT="$(dirname "${SCRIPT_DIR}")" SCRIPT_ROOT=$(dirname "${SCRIPT_DIR}")
GEN_VER=$( awk '/k8s.io\/code-generator/ { print $2 }' "${SCRIPT_ROOT}/go.mod" ) GEN_VER=$( awk '/k8s.io\/code-generator/ { print $2 }' "${SCRIPT_ROOT}/go.mod" )
KUBE_OPEN_API_VER=$( awk '/k8s.io\/kube-openapi/ { print $2 }' "${SCRIPT_ROOT}/go.mod" ) KUBE_OPEN_API_VER=$( awk '/k8s.io\/kube-openapi/ { print $2 }' "${SCRIPT_ROOT}/go.mod" )
CODEGEN_PKG=$(mktemp -d -t "code-generator-${GEN_VER}.XXX")/code-generator CODEGEN_PKG=$(mktemp -d -t "code-generator-${GEN_VER}.XXX")/code-generator
@ -38,10 +38,10 @@ kube::codegen::gen_helpers \
--boilerplate "${SCRIPT_ROOT}/controller/gen/boilerplate.go.txt" \ --boilerplate "${SCRIPT_ROOT}/controller/gen/boilerplate.go.txt" \
github.com/linkerd/linkerd2/controller/gen/apis github.com/linkerd/linkerd2/controller/gen/apis
if [[ -n "${API_KNOWN_VIOLATIONS_DIR:-}" ]]; then if [ -n "${API_KNOWN_VIOLATIONS_DIR:-}" ]; then
report_filename="${API_KNOWN_VIOLATIONS_DIR}/codegen_violation_exceptions.list" report_filename=${API_KNOWN_VIOLATIONS_DIR}/codegen_violation_exceptions.list
if [[ "${UPDATE_API_KNOWN_VIOLATIONS:-}" == "true" ]]; then if [ "${UPDATE_API_KNOWN_VIOLATIONS:-}" = 'true' ]; then
update_report="--update-report" update_report='--update-report'
fi fi
fi fi

11
bin/web
View File

@ -27,7 +27,7 @@ USAGE
check-for-linkerd-and-viz() { check-for-linkerd-and-viz() {
metrics_api_pod=$(get-pod linkerd-viz metrics-api) metrics_api_pod=$(get-pod linkerd-viz metrics-api)
if [[ -z "${metrics_api_pod// }" ]]; then if [ -z "${metrics_api_pod// }" ]; then
err 'Metrics-api is not running. Have you installed Linkerd-Viz?' err 'Metrics-api is not running. Have you installed Linkerd-Viz?'
exit 1 exit 1
fi fi
@ -57,7 +57,7 @@ get-pod() {
fi fi
selector="linkerd.io/control-plane-component=$2" selector=linkerd.io/control-plane-component=$2
if [ "$1" = 'linkerd-viz' ]; then if [ "$1" = 'linkerd-viz' ]; then
selector="component=$2" selector="component=$2"
fi fi
@ -123,7 +123,8 @@ msg() { out "$*" >&2 ;}
err() { local x=$? ; msg "$*" ; return $(( x == 0 ? 1 : x )) ;} err() { local x=$? ; msg "$*" ; return $(( x == 0 ? 1 : x )) ;}
out() { printf '%s\n' "$*" ;} out() { printf '%s\n' "$*" ;}
if [[ ${1:-} ]] && declare -F | cut -d' ' -f3 | grep -Fqx -- "${1:-}" if [ ${1:-} ] && declare -F | cut -d' ' -f3 | grep -Fqx -- "${1:-}"; then
then "$@" "$@"
else main "$@" else
main "$@"
fi fi