Fix whitespace path handling in non-docker (build) scripts (#3650)

* Fix whitespace path handling in non-docker (build) scripts

Handling of whitespace paths was not fully implemented; this patch adds
the missing pieces. Also, only use bash where bash-specific
functionality is used/needed.

Signed-off-by: Joakim Roubert <joakimr@axis.com>
This commit is contained in:
Joakim Roubert 2019-11-26 15:48:41 +01:00 committed by Alejandro Pedraza
parent 65d5778b93
commit e1b3fdb029
22 changed files with 249 additions and 241 deletions

View File

@ -6,15 +6,15 @@
# init_test_run parses input params, initializes global vars, and checks for
# linkerd and kubectl. Call this prior to calling any of the
# *_integration_tests() functions.
function init_test_run() {
init_test_run() {
linkerd_path=$1
if [ -z "$linkerd_path" ]; then
echo "usage: $(basename "$0") /path/to/linkerd [namespace] [k8s-context]" >&2
echo "usage: ${0##*/} /path/to/linkerd [namespace] [k8s-context]" >&2
exit 64
fi
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
test_directory="$bindir/../test"
bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
test_directory=$bindir/../test
linkerd_version=$($linkerd_path version --client --short)
linkerd_namespace=${2:-l5d-integration}
k8s_context=${3:-""}
@ -30,7 +30,7 @@ function init_test_run() {
# 2. helm_integration_tests
# 3. deep_integration_tests
function upgrade_integration_tests() {
upgrade_integration_tests() {
# run upgrade test:
# 1. install latest stable
# 2. upgrade to HEAD
@ -42,41 +42,41 @@ function upgrade_integration_tests() {
cleanup
}
function helm_integration_tests() {
helm_integration_tests() {
helm_path=$bindir/helm
helm_chart="$( cd $bindir/.. && pwd )"/charts/linkerd2
helm_chart="$( cd "$bindir"/.. && pwd )"/charts/linkerd2
helm_release_name=$linkerd_namespace-test
tiller_namespace=$linkerd_namespace-tiller
run_helm_test
exit_on_err "error testing Helm"
exit_on_err 'error testing Helm'
helm_cleanup
exit_on_err "error cleaning up Helm"
exit_on_err 'error cleaning up Helm'
# clean the data plane test resources
cleanup
}
function deep_integration_tests() {
deep_integration_tests() {
run_test "$test_directory/install_test.go" --linkerd-namespace=$linkerd_namespace
exit_on_err "error during install"
exit_on_err 'error during install'
run_test "$(go list $test_directory/.../...)" --linkerd-namespace=$linkerd_namespace
exit_on_err "error during deep tests"
exit_on_err 'error during deep tests'
cleanup
}
function custom_domain_integration_tests() {
run_test "$test_directory/install_test.go" --linkerd-namespace=$linkerd_namespace --cluster-domain="custom.domain"
exit_on_err "error during install"
exit_on_err 'error during install'
cleanup
}
function external_issuer_integration_tests() {
run_test "$test_directory/install_test.go" --linkerd-namespace=$linkerd_namespace-external-issuer --external-issuer=true
exit_on_err "error during install with --external-issuer=true"
exit_on_err 'error during install with --external-issuer=true'
run_test "$test_directory/externalissuer/external_issuer_test.go" --linkerd-namespace=$linkerd_namespace-external-issuer --external-issuer=true
exit_on_err "error during external issuer tests"
exit_on_err 'error during external issuer tests'
cleanup
}
@ -84,66 +84,66 @@ function external_issuer_integration_tests() {
# Helper functions.
#
function check_linkerd_binary(){
printf "Checking the linkerd binary..."
check_linkerd_binary(){
printf 'Checking the linkerd binary...'
if [[ "$linkerd_path" != /* ]]; then
printf "\\n[%s] is not an absolute path\\n" "$linkerd_path"
printf '\n[%s] is not an absolute path\n' "$linkerd_path"
exit 1
fi
if [ ! -x "$linkerd_path" ]; then
printf "\\n[%s] does not exist or is not executable\\n" "$linkerd_path"
printf '\n[%s] does not exist or is not executable\n' "$linkerd_path"
exit 1
fi
exit_code=0
"$linkerd_path" version --client > /dev/null 2>&1
exit_on_err "error running linkerd version command"
printf "[ok]\\n"
exit_on_err 'error running linkerd version command'
printf '[ok]\n'
}
function check_if_k8s_reachable(){
printf "Checking if there is a Kubernetes cluster available..."
check_if_k8s_reachable(){
printf 'Checking if there is a Kubernetes cluster available...'
exit_code=0
kubectl --context=$k8s_context --request-timeout=5s get ns > /dev/null 2>&1
exit_on_err "error connecting to Kubernetes cluster"
printf "[ok]\\n"
exit_on_err 'error connecting to Kubernetes cluster'
printf '[ok]\n'
}
function remove_l5d_if_exists() {
remove_l5d_if_exists() {
resources=$(kubectl --context=$k8s_context get all,clusterrole,clusterrolebinding,mutatingwebhookconfigurations,validatingwebhookconfigurations,psp,crd -l linkerd.io/control-plane-ns --all-namespaces -oname)
if [ ! -z "$resources" ]; then
printf "Removing existing l5d installation..."
printf 'Removing existing l5d installation...'
cleanup
printf "[ok]\\n"
printf '[ok]\n'
fi
# Cleanup Helm, in case it's there (if not, we ignore the error)
helm_cleanup &> /dev/null || true
}
function cleanup() {
$bindir/test-cleanup $k8s_context > /dev/null 2>&1
exit_on_err "error removing existing Linkerd resources"
cleanup() {
"$bindir"/test-cleanup $k8s_context > /dev/null 2>&1
exit_on_err 'error removing existing Linkerd resources'
}
function run_test(){
filename="$1"
run_test(){
filename=$1
shift
printf "Test script: [%s] Params: [%s]\n" "$(basename $filename 2>/dev/null || echo $filename )" "$*"
printf 'Test script: [%s] Params: [%s]\n' "$(basename $filename 2>/dev/null || echo $filename )" "$*"
GO111MODULE=on go test --failfast --mod=readonly $filename --linkerd="$linkerd_path" --k8s-context="$k8s_context" --integration-tests "$@"
}
# Install the latest stable release.
# $1 - namespace to use for the stable release
function install_stable() {
install_stable() {
tmp=$(mktemp -d -t l5dbin.XXX)
trap "rm -rf $tmp" RETURN
curl -s https://run.linkerd.io/install | HOME=$tmp sh > /dev/null 2>&1
local linkerd_path=$tmp/.linkerd2/bin/linkerd
local stable_namespace="$1"
local test_app_namespace="$stable_namespace"-upgrade-test
local stable_namespace=$1
local test_app_namespace=$stable_namespace-upgrade-test
$linkerd_path install --linkerd-namespace="$stable_namespace" | kubectl --context=$k8s_context apply -f - > /dev/null 2>&1
$linkerd_path check --linkerd-namespace="$stable_namespace" > /dev/null 2>&1
@ -156,51 +156,51 @@ function install_stable() {
# Run the upgrade test by upgrading the most-recent stable release to the HEAD of
# this branch.
# $1 - namespace to use for the stable release
function run_upgrade_test() {
local stable_namespace="$1"
run_upgrade_test() {
local stable_namespace=$1
local stable_version=$(curl -s https://versioncheck.linkerd.io/version.json | grep -o "stable-[0-9]*.[0-9]*.[0-9]*")
install_stable $stable_namespace
run_test "$test_directory/install_test.go" --upgrade-from-version=$stable_version --linkerd-namespace=$stable_namespace
}
function run_helm_test() {
run_helm_test() {
(
set -e
kubectl --context=$k8s_context create ns $tiller_namespace
kubectl --context=$k8s_context label ns $tiller_namespace linkerd.io/is-test-helm=true
kubectl --context=$k8s_context create clusterrolebinding ${tiller_namespace}:tiller-cluster-admin --clusterrole=cluster-admin --serviceaccount=${tiller_namespace}:default
kubectl --context=$k8s_context label clusterrolebinding ${tiller_namespace}:tiller-cluster-admin linkerd.io/is-test-helm=true
$helm_path --kube-context=$k8s_context --tiller-namespace=$tiller_namespace init --wait
$helm_path --kube-context=$k8s_context --tiller-namespace=$tiller_namespace dependency update $helm_chart
"$helm_path" --kube-context=$k8s_context --tiller-namespace=$tiller_namespace init --wait
"$helm_path" --kube-context=$k8s_context --tiller-namespace=$tiller_namespace dependency update "$helm_chart"
)
exit_on_err "error setting up Helm"
exit_on_err 'error setting up Helm'
run_test "$test_directory/install_test.go" --linkerd-namespace=$linkerd_namespace-helm \
--helm-path=$helm_path --helm-chart=$helm_chart --helm-release=$helm_release_name --tiller-ns=$tiller_namespace
--helm-path="$helm_path" --helm-chart="$helm_chart" --helm-release=$helm_release_name --tiller-ns=$tiller_namespace
}
function helm_cleanup() {
helm_cleanup() {
(
set -e
# `helm delete` deletes $linkerd_namespace-helm
$helm_path --kube-context=$k8s_context --tiller-namespace=$tiller_namespace delete --purge $helm_release_name
"$helm_path" --kube-context=$k8s_context --tiller-namespace=$tiller_namespace delete --purge $helm_release_name
# `helm delete` doesn't wait for resources to be deleted, so we wait explicitly.
# We wait for the namespace to be gone so the following call to `cleanup` doesn't fail when it attempts to delete
# the same namespace that is already being deleted here (error thrown by the NamespaceLifecycle controller).
# We don't have that problem with global resources, so no need to wait for them to be gone.
kubectl wait --for=delete ns/$linkerd_namespace-helm --timeout=40s
# `helm reset` deletes the tiller pod in $tiller_namespace
$helm_path --kube-context=$k8s_context --tiller-namespace=$tiller_namespace reset
"$helm_path" --kube-context=$k8s_context --tiller-namespace=$tiller_namespace reset
kubectl --context=$k8s_context delete clusterrolebinding ${tiller_namespace}:tiller-cluster-admin
echo $tiller_namespace
kubectl --context=$k8s_context delete ns $tiller_namespace
)
}
function exit_on_err() {
exit_on_err() {
exit_code=$?
if [ $exit_code -ne 0 ]; then
printf "\\n=== FAIL: %s\\n" "$@"
printf '\n=== FAIL: %s\n' "$@"
exit $exit_code
fi
}

View File

@ -25,7 +25,7 @@ esac
(
cd "$rootdir"
cd "$(pwd -P)"
target="target/cli/${host_platform}/linkerd"
target=target/cli/$host_platform/linkerd
GO111MODULE=on go generate -mod=readonly ./pkg/charts/static # TODO: `go generate` does not honor -mod=readonly
root_tag=$("$bindir"/root-tag)
GO111MODULE=on CGO_ENABLED=0 go build -o $target -tags prod -mod=readonly -ldflags "-s -w -X github.com/linkerd/linkerd2/pkg/version.Version=$root_tag" ./cli

View File

@ -1,19 +1,19 @@
#!/bin/bash
#!/bin/sh
set -eu
if [ $# -ne 1 ]; then
echo "usage: $(basename $0) v2.N.P" >&2
echo "usage: ${0##*/} v2.N.P" >&2
exit 64
fi
new_proxy_version="$1"
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"
bindir=$( cd "${0%/*}" && pwd )
rootdir=$( cd "$bindir"/.. && pwd )
old_proxy_version="$(tr -d '\n' <"$rootdir/.proxy-version")"
if [ -z "$old_proxy_version" ]; then
echo "Missing .proxy-version" >&2
echo 'Missing .proxy-version' >&2
exit 1
fi

View File

@ -1,16 +1,17 @@
#!/bin/bash
#!/bin/sh
set -eu
cd "$(pwd -P)"
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bindir=$( cd "${0%/*}" && pwd )
if [ "$#" -eq 0 ]; then
echo "Usage: bin/go-run path/to/main [args]" >&2
if [ $# -eq 0 ]; then
echo "Usage: bin/${0##*/} path/to/main [args]" >&2
exit 1
fi
ldflags="-X github.com/linkerd/linkerd2/pkg/version.Version=$($bindir/root-tag)"
version=$("$bindir"/root-tag)
ldflags="-X github.com/linkerd/linkerd2/pkg/version.Version=$version"
GO111MODULE=on go build -v -mod=readonly -race -o .gorun -ldflags "$ldflags" "./$1"
shift
exec ./.gorun "$@"

View File

@ -1,19 +1,19 @@
#!/bin/bash
#!/bin/sh
set -eu
cd "$(pwd -P)"
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd "$bindir/.." && pwd )"
targetbin="${rootdir}"/target/bin
version="$( grep golang.org/x/tools go.mod | awk '{ print $2}' )"
goimportsbin="${targetbin}/goimports-${version}"
bindir=$( cd "${0%/*}" && pwd )
rootdir=$( cd "$bindir/.." && pwd )
targetbin=$rootdir/target/bin
version=$( grep golang.org/x/tools go.mod | awk '{ print $2}' )
goimportsbin=$targetbin/goimports-$version
# install goimports if it does not exist
if [ ! -f "$goimportsbin" ]; then
GOBIN=$targetbin go install -mod=readonly golang.org/x/tools/cmd/goimports
mv "${targetbin}/goimports" "$goimportsbin"
mv "$targetbin/goimports" "$goimportsbin"
fi
exec "$goimportsbin" "$@"

View File

@ -1,25 +1,25 @@
#!/bin/bash
#!/bin/sh
set -eu
helmversion=v2.14.3
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
targetbin="$( cd $bindir/.. && pwd )"/target/bin
bindir=$( cd "${0%/*}" && pwd )
targetbin=$( cd "$bindir"/.. && pwd )/target/bin
helmbin=$targetbin/helm-$helmversion
if [ ! -f $helmbin ]; then
if [ "$(uname -s)" = "Darwin" ]; then
if [ ! -f "$helmbin" ]; then
if [ "$(uname -s)" = Darwin ]; then
os=darwin
arch=amd64
else
os=linux
case $(uname -m) in
x86_64) arch="amd64" ;;
arm) dpkg --print-architecture | grep -q "arm64" && arch="arm64" || arch="arm" ;;
x86_64) arch=amd64 ;;
arm) dpkg --print-architecture | grep -q arm64 && arch=arm64 || arch=arm ;;
esac
fi
helmcurl="https://get.helm.sh/helm-${helmversion}-${os}-${arch}.tar.gz"
targetdir="${os}-${arch}"
helmcurl="https://get.helm.sh/helm-$helmversion-$os-$arch.tar.gz"
targetdir=$os-$arch
tmp=$(mktemp -d -t helm.XXX)
mkdir -p "$targetbin"
(
@ -32,4 +32,4 @@ if [ ! -f $helmbin ]; then
rm -rf "$tmp"
fi
$helmbin "$@"
"$helmbin" "$@"

View File

@ -5,29 +5,29 @@ set -e
# trap the last failed command
trap 'printf "Error on exit:\n Exit code: $?\n Failed command: \"$BASH_COMMAND\"\n"' ERR
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"
bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
rootdir=$( cd "$bindir"/.. && pwd )
$bindir/helm lint $rootdir/charts/partials
$bindir/helm init --client-only
$bindir/helm dep up $rootdir/charts/linkerd2
$bindir/helm dep up $rootdir/charts/patch
$bindir/helm lint --set Identity.TrustAnchorsPEM="fake-trust" --set Identity.Issuer.TLS.CrtPEM="fake-cert" --set Identity.Issuer.TLS.KeyPEM="fake-key" --set Identity.Issuer.CrtExpiry="fake-expiry-date" $rootdir/charts/linkerd2
"$bindir"/helm lint "$rootdir"/charts/partials
"$bindir"/helm init --client-only
"$bindir"/helm dep up "$rootdir"/charts/linkerd2
"$bindir"/helm dep up "$rootdir"/charts/patch
"$bindir"/helm lint --set Identity.TrustAnchorsPEM="fake-trust" --set Identity.Issuer.TLS.CrtPEM="fake-cert" --set Identity.Issuer.TLS.KeyPEM="fake-key" --set Identity.Issuer.CrtExpiry="fake-expiry-date" "$rootdir"/charts/linkerd2
# `bin/helm-build package` assumes the presence of $rootdir/target/helm/index-pre.yaml which is downloaded in the chart_deploy CI job
if [ "$1" == "package" ]; then
. $bindir/_tag.sh
# `bin/helm-build package` assumes the presence of "$rootdir"/target/helm/index-pre.yaml which is downloaded in the chart_deploy CI job
if [ "$1" = package ]; then
. "$bindir"/_tag.sh
tag=$(named_tag)
clean_head || { echo "There are uncommitted changes"; exit 1; }
clean_head || { echo 'There are uncommitted changes'; exit 1; }
regex='(edge|stable)-([0-9]+\.[0-9]+\.[0-9]+)'
if [[ ! "$tag" =~ $regex ]]; then
echo "Version tag is malformed"
echo 'Version tag is malformed'
exit 1
fi;
fi
repo=${BASH_REMATCH[1]}
version=${BASH_REMATCH[2]}
$bindir/helm --version $version --app-version $tag -d $rootdir/target/helm package $rootdir/charts/linkerd2
mv $rootdir/target/helm/index-pre.yaml $rootdir/target/helm/index-pre-$version.yaml
$bindir/helm repo index --url "https://helm.linkerd.io/$repo/" --merge $rootdir/target/helm/index-pre-$version.yaml $rootdir/target/helm
fi;
"$bindir"/helm --version $version --app-version $tag -d "$rootdir"/target/helm package "$rootdir"/charts/linkerd2
mv "$rootdir"/target/helm/index-pre.yaml "$rootdir"/target/helm/index-pre-$version.yaml
"$bindir"/helm repo index --url "https://helm.linkerd.io/$repo/" --merge "$rootdir"/target/helm/index-pre-$version.yaml "$rootdir"/target/helm
fi

View File

@ -1,25 +1,25 @@
#!/bin/bash
#!/bin/sh
set -eu
kindversion=v0.5.1
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
targetbin="$( cd $bindir/.. && pwd )"/target/bin
kindbin="${targetbin}/.kind-${kindversion}"
bindir=$( cd "${0%/*}" && pwd )
targetbin=$( cd "$bindir"/.. && pwd )/target/bin
kindbin=$targetbin/.kind-$kindversion
if [ ! -f "$kindbin" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
if [ "$(uname -s)" = Darwin ]; then
os=darwin
arch=amd64
elif [ "$(uname -o)" = "Msys" ]; then
elif [ "$(uname -o)" = Msys ]; then
os=windows
arch=amd64
else
os=linux
case $(uname -m) in
x86_64) arch="amd64" ;;
arm) arch="arm64" ;;
x86_64) arch=amd64 ;;
arm) arch=arm64 ;;
esac
fi
@ -28,4 +28,4 @@ if [ ! -f "$kindbin" ]; then
chmod +x "$kindbin"
fi
$kindbin "$@"
"$kindbin" "$@"

View File

@ -1,17 +1,17 @@
#!/bin/bash
#!/bin/sh
set -eu
# If cluster name is unset or null, default to $USER.
cluster="${1:-$USER}"
cluster=${1:-$USER}
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bindir=$( cd "${0%/*}" && pwd )
. $bindir/_tag.sh
. "$bindir"/_tag.sh
tag="$(head_root_tag)"
org_repo="gcr.io/linkerd-io"
tag=$(head_root_tag)
org_repo=gcr.io/linkerd-io
for img in proxy controller web grafana ; do
$bindir/kind load docker-image $org_repo/$img:$tag --name $cluster
"$bindir"/kind load docker-image "$org_repo/$img:$tag" --name $cluster
done

View File

@ -1,27 +1,27 @@
#!/bin/bash
#!/bin/sh
set -eu
kubectlversion=v1.15.3
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
targetbin="$( cd $bindir/.. && pwd )"/target/bin
kubectlbin="${targetbin}/.kubectl-${kubectlversion}"
bindir=$( cd "${0%/*}" && pwd )
targetbin=$( cd "$bindir"/.. && pwd )/target/bin
kubectlbin=$targetbin/.kubectl-$kubectlversion
if [ ! -f "$kubectlbin" ]; then
exe=
if [ "$(uname -s)" = "Darwin" ]; then
if [ "$(uname -s)" = Darwin ]; then
os=darwin
arch=amd64
elif [ "$(uname -o)" = "Msys" ]; then
elif [ "$(uname -o)" = Msys ]; then
os=windows
arch=amd64
exe=.exe
else
os=linux
case $(uname -m) in
x86_64) arch="amd64" ;;
arm) dpkg --print-architecture | grep -q "arm64" && arch="arm64" || arch="arm" ;;
x86_64) arch=amd64 ;;
arm) dpkg --print-architecture | grep -q arm64 && arch=arm64 || arch=arm ;;
esac
fi
@ -30,4 +30,4 @@ if [ ! -f "$kubectlbin" ]; then
chmod +x "$kubectlbin"
fi
$kubectlbin "$@"
"$kubectlbin" "$@"

View File

@ -1,15 +1,15 @@
#!/bin/bash
#!/bin/sh
set -eu
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"
bindir=$( cd "${0%/*}" && pwd )
rootdir=$( cd "$bindir"/.. && pwd )
system=$(uname -s)
if [ "$system" = "Darwin" ]; then
if [ "$system" = Darwin ]; then
bin=$rootdir/target/cli/darwin/linkerd
elif [ "$system" = "Linux" ]; then
elif [ "$system" = Linux ]; then
bin=$rootdir/target/cli/linux/linkerd
else
echo "unknown system: $system" >&2
@ -17,8 +17,8 @@ else
fi
# build linkerd executable if it does not exist
if [ ! -f $bin ]; then
$bindir/build-cli-bin >/dev/null
if [ ! -f "$bin" ]; then
"$bindir"/build-cli-bin >/dev/null
fi
exec $bin "$@"
exec "$bin" "$@"

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
set -eu
@ -6,27 +6,27 @@ lintversion=1.19.1
cd "$(pwd -P)"
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"
targetbin="${rootdir}"/target/bin
bindir=$( cd "${0%/*}" && pwd )
rootdir=$( cd "$bindir"/.. && pwd )
targetbin=$rootdir/target/bin
cd "$rootdir"
os=linux
exe=
if [ "$(uname -s)" = "Darwin" ]; then
if [ "$(uname -s)" = Darwin ]; then
os=darwin
elif [ "$(uname -o)" = "Msys" ]; then
elif [ "$(uname -o)" = Msys ]; then
os=windows
exe=.exe
fi
lintbin="${targetbin}/.golangci-lint-${lintversion}${exe}"
lintbin=$targetbin/.golangci-lint-$lintversion$exe
if [ ! -f "$lintbin" ]; then
mkdir -p "$targetbin"
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/v$lintversion/install.sh | sh -s -- -b . v$lintversion
mv ./golangci-lint${exe} $lintbin
mv ./golangci-lint$exe "$lintbin"
fi
$lintbin run "$@"
"$lintbin" run "$@"

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# A wrapper for interacting with minikube.
#
@ -8,8 +8,7 @@
# If we're running under WSL then we have to use the Windows native Minikube
# as the Linux version doesn't work in WSL. Assume WSL is Microsoft's only
# Linux distro.
uname -r | grep "Microsoft" > /dev/null
if [ $? -ne 0 ]; then
if ! uname -r | grep Microsoft > /dev/null; then
MINIKUBE_EXE=minikube
else
# This is where minikube-installer.exe puts it.

View File

@ -1,19 +1,19 @@
#!/bin/bash
#!/bin/sh
set -eu
if [ "$(uname -s)" = "Darwin" ]; then
if [ "$(uname -s)" = Darwin ]; then
os=osx
else
os=linux
fi
arch=$(uname -m)
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
targetbin="$( cd $bindir/.. && pwd )"/target/bin
bindir=$( cd "${0%/*}" && pwd )
targetbin=$( cd "$bindir"/.. && pwd )/target/bin
protocversion=3.6.0
protocbin=${targetbin}/protoc-${protocversion}
protocurl="https://github.com/google/protobuf/releases/download/v${protocversion}/protoc-${protocversion}-${os}-${arch}.zip"
protocbin=$targetbin/protoc-$protocversion
protocurl=https://github.com/google/protobuf/releases/download/v$protocversion/protoc-$protocversion-$os-$arch.zip
if [ ! -f "$protocbin" ]; then
tmp=$(mktemp -d -t protoc.XXX)
@ -28,4 +28,4 @@ if [ ! -f "$protocbin" ]; then
rm -rf "$tmp"
fi
$protocbin "$@"
"$protocbin" "$@"

View File

@ -7,49 +7,49 @@ k8s_context=${1:-""}
echo "cleaning up control-plane namespaces in k8s-context [${k8s_context}]"
if [ -z "${namespaces_controlplane=$(kubectl --context=$k8s_context get ns -oname -l linkerd.io/is-control-plane)}" ]; then
echo "no control-plane namespaces found" >&2
echo 'no control-plane namespaces found' >&2
fi
if [ -z "${namespaces_helm=$(kubectl --context=$k8s_context get ns -oname -l linkerd.io/is-test-helm)}" ]; then
echo "no helm namespaces found" >&2
echo 'no helm namespaces found' >&2
fi
echo "cleaning up data-plane namespaces in k8s-context [${k8s_context}]"
if [ -z "${namespaces_dataplane=$(kubectl --context=$k8s_context get ns -oname -l linkerd.io/is-test-data-plane)}" ]; then
echo "no data-plane namespaces found" >&2
echo 'no data-plane namespaces found' >&2
fi
if [ -z "${clusterrolebindings=$(kubectl --context=$k8s_context get clusterrolebindings -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no clusterrolebindings found" >&2
echo 'no clusterrolebindings found' >&2
fi
if [ -z "${clusterrolebindings_helm=$(kubectl --context=$k8s_context get clusterrolebindings -oname -l linkerd.io/is-test-helm)}" ]; then
echo "no helm clusterrolebindings found" >&2
echo 'no helm clusterrolebindings found' >&2
fi
if [ -z "${clusterroles=$(kubectl --context=$k8s_context get clusterroles -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no clusterroles found" >&2
echo 'no clusterroles found' >&2
fi
if [ -z "${webhookconfigs=$(kubectl --context=$k8s_context get mutatingwebhookconfigurations -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no mutatingwebhookconfigurations found" >&2
echo 'no mutatingwebhookconfigurations found' >&2
fi
if [ -z "${validatingconfigs=$(kubectl --context=$k8s_context get validatingwebhookconfigurations -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no validatingwebhookconfigurations found" >&2
echo 'no validatingwebhookconfigurations found' >&2
fi
if [ -z "${podsecuritypolicies=$(kubectl --context=$k8s_context get podsecuritypolicies -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no podsecuritypolicies found" >&2
echo 'no podsecuritypolicies found' >&2
fi
if [ -z "${customresourcedefinitions=$(kubectl --context=$k8s_context get customresourcedefinitions -l linkerd.io/control-plane-ns -oname)}" ]; then
echo "no customresourcedefinitions found" >&2
echo 'no customresourcedefinitions found' >&2
fi
if [ -z "${apiservices=$(kubectl --context=$k8s_context get apiservices -l linkerd.io/control-plane-ns -oname)}" ]; then
echo "no apiservices found" >&2
echo 'no apiservices found' >&2
fi
if [[ $namespaces_controlplane || $namespaces_helm || $namespaces_dataplane || $clusterrolebindings || $clusterrolebindings_helm || $clusterroles || $webhookconfigs || $validatingconfigs || $podsecuritypolicies || $customresourcedefinitions || $apiservices ]]; then
@ -58,7 +58,7 @@ fi
echo "cleaning up rolebindings in kube-system namespace in k8s-context [${k8s_context}]"
if ! rolebindings=$(kubectl --context=$k8s_context -n kube-system get rolebindings -l linkerd.io/control-plane-ns -oname); then
echo "no rolebindings found in the kube-system namespace" >&2
echo 'no rolebindings found in the kube-system namespace' >&2
fi
if [[ $rolebindings ]]; then
kubectl --context=$k8s_context delete $rolebindings -n kube-system

View File

@ -23,27 +23,31 @@
set -e
# TODO: share this with test-run
function check_linkerd_binary(){
printf "Checking the linkerd binary..."
if [[ "$linkerd_path" != /* ]]; then
printf "\\n[%s] is not an absolute path\\n" "$linkerd_path"
exit 1
fi
check_linkerd_binary() {
printf 'Checking the linkerd binary...'
case "$linkerd_path" in
/*)
;;
*)
printf '\n[%s] is not an absolute path\n' "$linkerd_path"
exit 1
;;
esac
if [ ! -x "$linkerd_path" ]; then
printf "\\n[%s] does not exist or is not executable\\n" "$linkerd_path"
printf '\n[%s] does not exist or is not executable\n' "$linkerd_path"
exit 1
fi
exit_code=0
"$linkerd_path" version --client > /dev/null 2>&1 || exit_code=$?
if [ $exit_code -ne 0 ]; then
printf "\\nFailed to run linkerd version command\\n"
printf '\nFailed to run linkerd version command\n'
exit $exit_code
fi
printf "[ok]\\n"
printf '[ok]\n'
}
if [ "$#" -ne 1 ]; then
echo "usage: $(basename "$0") /path/to/linkerd" >&2
echo "usage: ${0##*/} /path/to/linkerd" >&2
exit 64
fi
@ -57,7 +61,7 @@ done
linkerd_path=$1
check_linkerd_binary
printf "\nKicking off tests for:\n- $AKS\n- $DO\n- $EKS\n- $GKE\n\n"
printf '\nKicking off tests for:\n- %s\n- %s\n- %s\n- %s\n\n' "$AKS" "$DO" "$EKS" "$GKE"
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
for CLUSTER in $AKS $DO $EKS $GKE; do

View File

@ -22,6 +22,6 @@ done
for CLUSTER in $AKS $DO $EKS $GKE
do
printf "\n$CLUSTER\n"
printf '\n%s\n' "$CLUSTER"
bin/test-cleanup $CLUSTER
done

View File

@ -6,14 +6,14 @@
# 3. deep_integration_tests
# 4. external_issuer_integration_tests
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
. $bindir/_test-run.sh
. "$bindir"/_test-run.sh
init_test_run "$@"
printf "==================RUNNING ALL TESTS==================\\n"
printf "Testing Linkerd version [%s] namespace [%s] k8s-context [%s]\\n" "$linkerd_version" "$linkerd_namespace" "$k8s_context"
printf '==================RUNNING ALL TESTS==================\n'
printf 'Testing Linkerd version [%s] namespace [%s] k8s-context [%s]\n' "$linkerd_version" "$linkerd_namespace" "$k8s_context"
upgrade_integration_tests
helm_integration_tests
@ -25,11 +25,11 @@ deep_integration_tests
# external_issuer_integration_tests
if [ $exit_code -eq 0 ]; then
printf "\\n=== PASS: all tests passed\\n"
printf '\n=== PASS: all tests passed\n'
cleanup
else
# `cleanup` is not called so that there is a chance to debug the problem
printf "\\n=== FAIL: at least one test failed\\n"
printf '\n=== FAIL: at least one test failed\n'
fi
exit $exit_code

View File

@ -17,56 +17,60 @@ REPLICAS=5
# TODO: share these functions with test-run
function check_linkerd_binary(){
printf "Checking the linkerd binary..."
if [[ "$linkerd_path" != /* ]]; then
printf "\\n[%s] is not an absolute path\\n" "$linkerd_path"
exit 1
fi
check_linkerd_binary(){
printf 'Checking the linkerd binary...'
case "$linkerd_path" in
/*)
;;
*)
printf '\n[%s] is not an absolute path\n' "$linkerd_path"
exit 1
;;
esac
if [ ! -x "$linkerd_path" ]; then
printf "\\n[%s] does not exist or is not executable\\n" "$linkerd_path"
printf '\n[%s] does not exist or is not executable\n' "$linkerd_path"
exit 1
fi
exit_code=0
"$linkerd_path" version --client > /dev/null 2>&1 || exit_code=$?
if [ $exit_code -ne 0 ]; then
printf "\\nFailed to run linkerd version command\\n"
printf '\nFailed to run linkerd version command\n'
exit $exit_code
fi
printf "[ok]\\n"
printf '[ok]\n'
}
function check_if_k8s_reachable(){
printf "Checking if there is a Kubernetes cluster available..."
check_if_k8s_reachable(){
printf 'Checking if there is a Kubernetes cluster available...'
exit_code=0
kubectl --request-timeout=5s get ns > /dev/null 2>&1 || exit_code=$?
if [ $exit_code -ne 0 ]; then
printf "\\nFailed to connect to Kubernetes cluster\\n"
printf '\nFailed to connect to Kubernetes cluster\n'
exit $exit_code
fi
printf "[ok]\\n"
printf '[ok]\n'
}
linkerd_path=$1
if [ -z "$linkerd_path" ]; then
echo "usage: $(basename "$0") /path/to/linkerd [namespace]" >&2
echo "usage: ${0##*/} /path/to/linkerd [namespace]" >&2
exit 64
fi
check_linkerd_binary
check_if_k8s_reachable
linkerd_version=$($linkerd_path version --client --short)
linkerd_version=$("$linkerd_path" version --client --short)
linkerd_namespace=${2:-l5d-scale}
#
# Deploy Linkerd
#
$linkerd_path -l $linkerd_namespace install | kubectl apply -f -
$linkerd_path -l $linkerd_namespace check --expected-version=$linkerd_version
$linkerd_path -l $linkerd_namespace install-sp | kubectl apply -f -
"$linkerd_path" -l $linkerd_namespace install | kubectl apply -f -
"$linkerd_path" -l $linkerd_namespace check --expected-version=$linkerd_version
"$linkerd_path" -l $linkerd_namespace install-sp | kubectl apply -f -
#
# Deploy Books
@ -101,7 +105,7 @@ END
BOOKS_APP=$(echo "${BOOKS_APP/$traffic_param/$sleep_param}")
# inject
BOOKS_APP=$(echo "$BOOKS_APP" | $linkerd_path -l $linkerd_namespace inject -)
BOOKS_APP=$(echo "$BOOKS_APP" | "$linkerd_path" -l $linkerd_namespace inject -)
# deploy books apps to N namespaces
for i in $(eval echo {1..$NAMESPACES}); do
@ -121,14 +125,14 @@ EMOJIVOTO=$(curl -s https://run.linkerd.io/emojivoto.yml)
# delete namespace
EMOJIVOTO=$(echo "$EMOJIVOTO" | tail -n +6)
emojins="namespace: emojivoto"
emojins='namespace: emojivoto'
EMOJIVOTO=$(echo "${EMOJIVOTO//$emojins/}")
emojins=".emojivoto:"
newns=":"
emojins=.emojivoto:
newns=:
EMOJIVOTO=$(echo "${EMOJIVOTO//$emojins/$newns}")
# inject
EMOJIVOTO=$(echo "$EMOJIVOTO" | $linkerd_path -l $linkerd_namespace inject -)
EMOJIVOTO=$(echo "$EMOJIVOTO" | "$linkerd_path" -l $linkerd_namespace inject -)
for i in $(eval echo {1..$NAMESPACES}); do
emojins=$linkerd_namespace-emoji-$i
@ -161,4 +165,4 @@ done
# Watch performance
#
watch $linkerd_path -l $linkerd_namespace stat ns
watch "$linkerd_path" -l $linkerd_namespace stat ns

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
set -eu
@ -8,14 +8,14 @@ git clone https://github.com/kubernetes/code-generator.git vendor/k8s.io/code-ge
git -C vendor/k8s.io/code-generator checkout aae79feb89bdded3679da91fd8c19b6dfcbdb79a
# ROOT_PACKAGE :: the package that is the target for code generation
ROOT_PACKAGE="github.com/linkerd/linkerd2"
ROOT_PACKAGE=github.com/linkerd/linkerd2
# CUSTOM_RESOURCE_NAME :: the name of the custom resource that we're generating client code for
CUSTOM_RESOURCE_NAME="serviceprofile"
CUSTOM_RESOURCE_NAME=serviceprofile
# CUSTOM_RESOURCE_VERSION :: the version of the resource
CUSTOM_RESOURCE_VERSION="v1alpha2"
CUSTOM_RESOURCE_VERSION=v1alpha2
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"
bindir=$( cd "${0%/*}" && pwd )
rootdir=$( cd "$bindir"/.. && pwd )
# run the code-generator entrypoint script
${rootdir}/vendor/k8s.io/code-generator/generate-groups.sh all "$ROOT_PACKAGE/controller/gen/client" "$ROOT_PACKAGE/controller/gen/apis" "$CUSTOM_RESOURCE_NAME:$CUSTOM_RESOURCE_VERSION"
"$rootdir"/vendor/k8s.io/code-generator/generate-groups.sh all "$ROOT_PACKAGE/controller/gen/client" "$ROOT_PACKAGE/controller/gen/apis" "$CUSTOM_RESOURCE_NAME:$CUSTOM_RESOURCE_VERSION"

View File

@ -4,11 +4,11 @@ set -eu
# Updates the tag for `linkerd-io/go-deps` across all Dockerfiles in this repository.
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
sha=$(. $bindir/_tag.sh ; go_deps_sha)
sha=$(. "$bindir"/_tag.sh ; go_deps_sha)
for f in $( grep -lR --include=Dockerfile\* go-deps: $bindir/.. ) ; do
sed -E -i.bak -e "s|linkerd-io/go-deps:[^ ]+|linkerd-io/go-deps:${sha}|" "$f"
sed -E -i.bak -e "s|linkerd-io/go-deps:[^ ]+|linkerd-io/go-deps:$sha|" "$f"
rm "$f".bak
done

62
bin/web
View File

@ -2,7 +2,7 @@
set -o errexit -o nounset -o pipefail
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
ROOT=$( cd "${BASH_SOURCE[0]%/*}"/.. && pwd )
DEV_PORT=8080
export NODE_ENV=${NODE_ENV:=development}
@ -26,40 +26,40 @@ USAGE: web <command>
USAGE
}; function --help { -h ;}
function check-for-linkerd {
check-for-linkerd() {
controller_pod=$(get-pod controller)
grafana_pod=$(get-pod grafana)
if [[ -z "${controller_pod// }" ]]; then
err "Controller is not running. Have you installed Linkerd?"
err 'Controller is not running. Have you installed Linkerd?'
exit 1
fi
if [[ -z "${grafana_pod// }" ]]; then
err "Controller is not running. Have you installed Linkerd?"
err 'Controller is not running. Have you installed Linkerd?'
exit 1
fi
}
function dev {
dev() {
while getopts "p:" opt; do
case "$opt" in
p) DEV_PORT=$OPTARG
esac
done
cd $ROOT/web/app && yarn webpack-dev-server --port $DEV_PORT &
cd "$ROOT"/web/app && yarn webpack-dev-server --port $DEV_PORT &
run
}
function build {
cd $ROOT/web/app
build() {
cd "$ROOT"/web/app
yarn webpack
}
function get-pod {
if [[ "$#" -ne 1 ]]; then
echo "usage: bin/web get-pod component-name" >&2
get-pod() {
if [ $# -ne 1 ]; then
echo "usage: bin/${0##*/} get-pod component-name" >&2
exit 1
fi
@ -69,9 +69,9 @@ function get-pod {
-o jsonpath='{.items[*].metadata.name}'
}
function port-forward {
if [[ "$#" -ne 2 ]]; then
echo "usage: bin/web port-forward component-name port-number" >&2
port-forward() {
if [ $# -ne 2 ]; then
echo "usage: bin/${0##*/} port-forward component-name port-number" >&2
exit 1
fi
@ -79,11 +79,11 @@ function port-forward {
kubectl --namespace=linkerd port-forward $(get-pod $1) "$2:$2"
}
function run {
run() {
# Stop everything in the process group (in the background) whenever the
# parent process experiences an error and exits.
trap "exit" INT TERM
trap "kill 0" EXIT
trap 'exit' INT TERM
trap 'kill 0' EXIT
build
@ -92,42 +92,42 @@ function run {
port-forward grafana 3000 &
)
cd $ROOT/web && \
cd "$ROOT"/web && \
../bin/go-run . --addr=:7777 $*
}
function setup {
cd $ROOT/web/app
setup() {
cd "$ROOT"/web/app
yarn $*
}
function test {
cd $ROOT/web/app
cd "$ROOT"/web/app
yarn jest "$*"
}
function integration {
if [[ "$#" -ne 1 || ($1 != "cloud" && $1 != "local") ]]; then
echo "usage: bin/web integration (cloud|local)" >&2
integration() {
if [[ $# -ne 1 || ($1 != "cloud" && $1 != "local") ]]; then
echo "usage: bin/${0##*/} integration (cloud|local)" >&2
exit 1
fi
if [ $1 = "cloud" ]; then
cd $ROOT/web/app && \
if [ "$1" = cloud ]; then
cd "$ROOT"/web/app && \
./node_modules/.bin/wdio ./integration/wdio-sauce.conf.js
else
cd $ROOT/web/app && \
cd "$ROOT"/web/app && \
./node_modules/.bin/wdio ./integration/wdio.conf.js
fi
}
function main {
main() {
setup
build
}
function msg { out "$*" >&2 ;}
function err { local x=$? ; msg "$*" ; return $(( $x == 0 ? 1 : $x )) ;}
function out { printf '%s\n' "$*" ;}
msg() { out "$*" >&2 ;}
err() { local x=$? ; msg "$*" ; return $(( x == 0 ? 1 : x )) ;}
out() { printf '%s\n' "$*" ;}
if [[ ${1:-} ]] && declare -F | cut -d' ' -f3 | grep -Fqx -- "${1:-}"
then "$@"