mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Fix shellcheck failures in test/cmd/l.*.sh
This commit is contained in:
parent
3a344c7168
commit
313044abd7
@ -18,5 +18,4 @@
|
|||||||
./hack/lib/test.sh
|
./hack/lib/test.sh
|
||||||
./hack/test-integration.sh
|
./hack/test-integration.sh
|
||||||
./hack/verify-test-featuregates.sh
|
./hack/verify-test-featuregates.sh
|
||||||
./test/cmd/legacy-script.sh
|
|
||||||
./test/images/image-util.sh
|
./test/images/image-util.sh
|
||||||
|
@ -23,7 +23,7 @@ set -o pipefail
|
|||||||
# Set locale to ensure english responses from kubectl commands
|
# Set locale to ensure english responses from kubectl commands
|
||||||
export LANG=C
|
export LANG=C
|
||||||
|
|
||||||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
|
||||||
# Expects the following has already been done by whatever sources this script
|
# Expects the following has already been done by whatever sources this script
|
||||||
# source "${KUBE_ROOT}/hack/lib/init.sh"
|
# source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||||
# source "${KUBE_ROOT}/hack/lib/test.sh"
|
# source "${KUBE_ROOT}/hack/lib/test.sh"
|
||||||
@ -66,14 +66,14 @@ CTLRMGR_PORT=${CTLRMGR_PORT:-10252}
|
|||||||
PROXY_HOST=127.0.0.1 # kubectl only serves on localhost.
|
PROXY_HOST=127.0.0.1 # kubectl only serves on localhost.
|
||||||
|
|
||||||
IMAGE_NGINX="k8s.gcr.io/nginx:1.7.9"
|
IMAGE_NGINX="k8s.gcr.io/nginx:1.7.9"
|
||||||
IMAGE_DEPLOYMENT_R1="k8s.gcr.io/nginx:test-cmd" # deployment-revision1.yaml
|
export IMAGE_DEPLOYMENT_R1="k8s.gcr.io/nginx:test-cmd" # deployment-revision1.yaml
|
||||||
IMAGE_DEPLOYMENT_R2="$IMAGE_NGINX" # deployment-revision2.yaml
|
export IMAGE_DEPLOYMENT_R2="$IMAGE_NGINX" # deployment-revision2.yaml
|
||||||
IMAGE_PERL="k8s.gcr.io/perl"
|
export IMAGE_PERL="k8s.gcr.io/perl"
|
||||||
IMAGE_PAUSE_V2="k8s.gcr.io/pause:2.0"
|
export IMAGE_PAUSE_V2="k8s.gcr.io/pause:2.0"
|
||||||
IMAGE_DAEMONSET_R2="k8s.gcr.io/pause:latest"
|
export IMAGE_DAEMONSET_R2="k8s.gcr.io/pause:latest"
|
||||||
IMAGE_DAEMONSET_R2_2="k8s.gcr.io/nginx:test-cmd" # rollingupdate-daemonset-rv2.yaml
|
export IMAGE_DAEMONSET_R2_2="k8s.gcr.io/nginx:test-cmd" # rollingupdate-daemonset-rv2.yaml
|
||||||
IMAGE_STATEFULSET_R1="k8s.gcr.io/nginx-slim:0.7"
|
export IMAGE_STATEFULSET_R1="k8s.gcr.io/nginx-slim:0.7"
|
||||||
IMAGE_STATEFULSET_R2="k8s.gcr.io/nginx-slim:0.8"
|
export IMAGE_STATEFULSET_R2="k8s.gcr.io/nginx-slim:0.8"
|
||||||
|
|
||||||
# Expose kubectl directly for readability
|
# Expose kubectl directly for readability
|
||||||
PATH="${KUBE_OUTPUT_HOSTBIN}":$PATH
|
PATH="${KUBE_OUTPUT_HOSTBIN}":$PATH
|
||||||
@ -83,8 +83,8 @@ clusterroles="clusterroles"
|
|||||||
configmaps="configmaps"
|
configmaps="configmaps"
|
||||||
csr="csr"
|
csr="csr"
|
||||||
deployments="deployments"
|
deployments="deployments"
|
||||||
horizontalpodautoscalers="horizontalpodautoscalers"
|
export horizontalpodautoscalers="horizontalpodautoscalers"
|
||||||
metrics="metrics"
|
export metrics="metrics"
|
||||||
namespaces="namespaces"
|
namespaces="namespaces"
|
||||||
nodes="nodes"
|
nodes="nodes"
|
||||||
persistentvolumeclaims="persistentvolumeclaims"
|
persistentvolumeclaims="persistentvolumeclaims"
|
||||||
@ -98,10 +98,10 @@ secrets="secrets"
|
|||||||
serviceaccounts="serviceaccounts"
|
serviceaccounts="serviceaccounts"
|
||||||
services="services"
|
services="services"
|
||||||
statefulsets="statefulsets"
|
statefulsets="statefulsets"
|
||||||
static="static"
|
export static="static"
|
||||||
storageclass="storageclass"
|
storageclass="storageclass"
|
||||||
subjectaccessreviews="subjectaccessreviews"
|
subjectaccessreviews="subjectaccessreviews"
|
||||||
selfsubjectaccessreviews="selfsubjectaccessreviews"
|
export selfsubjectaccessreviews="selfsubjectaccessreviews"
|
||||||
customresourcedefinitions="customresourcedefinitions"
|
customresourcedefinitions="customresourcedefinitions"
|
||||||
daemonsets="daemonsets"
|
daemonsets="daemonsets"
|
||||||
controllerrevisions="controllerrevisions"
|
controllerrevisions="controllerrevisions"
|
||||||
@ -131,9 +131,9 @@ function record_command() {
|
|||||||
local name="$1"
|
local name="$1"
|
||||||
local output="${KUBE_JUNIT_REPORT_DIR:-/tmp/junit-results}"
|
local output="${KUBE_JUNIT_REPORT_DIR:-/tmp/junit-results}"
|
||||||
echo "Recording: ${name}"
|
echo "Recording: ${name}"
|
||||||
echo "Running command: $@"
|
echo "Running command: $*"
|
||||||
juLog -output="${output}" -class="test-cmd" -name="${name}" "$@"
|
if ! juLog -output="${output}" -class="test-cmd" -name="${name}" "$@"
|
||||||
if [[ $? -ne 0 ]]; then
|
then
|
||||||
echo "Error when running ${name}"
|
echo "Error when running ${name}"
|
||||||
foundError="${foundError}""${name}"", "
|
foundError="${foundError}""${name}"", "
|
||||||
fi
|
fi
|
||||||
@ -147,7 +147,7 @@ function stop-proxy()
|
|||||||
{
|
{
|
||||||
[[ -n "${PROXY_PORT-}" ]] && kube::log::status "Stopping proxy on port ${PROXY_PORT}"
|
[[ -n "${PROXY_PORT-}" ]] && kube::log::status "Stopping proxy on port ${PROXY_PORT}"
|
||||||
[[ -n "${PROXY_PID-}" ]] && kill "${PROXY_PID}" 1>&2 2>/dev/null
|
[[ -n "${PROXY_PID-}" ]] && kill "${PROXY_PID}" 1>&2 2>/dev/null
|
||||||
[[ -n "${PROXY_PORT_FILE-}" ]] && rm -f ${PROXY_PORT_FILE}
|
[[ -n "${PROXY_PORT_FILE-}" ]] && rm -f "${PROXY_PORT_FILE}"
|
||||||
PROXY_PID=
|
PROXY_PID=
|
||||||
PROXY_PORT=
|
PROXY_PORT=
|
||||||
PROXY_PORT_FILE=
|
PROXY_PORT_FILE=
|
||||||
@ -163,22 +163,22 @@ function start-proxy()
|
|||||||
|
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
kubectl proxy --port=0 --www=. 1>${PROXY_PORT_FILE} 2>&1 &
|
kubectl proxy --port=0 --www=. 1>"${PROXY_PORT_FILE}" 2>&1 &
|
||||||
else
|
else
|
||||||
kubectl proxy --port=0 --www=. --api-prefix="$1" 1>${PROXY_PORT_FILE} 2>&1 &
|
kubectl proxy --port=0 --www=. --api-prefix="$1" 1>"${PROXY_PORT_FILE}" 2>&1 &
|
||||||
fi
|
fi
|
||||||
PROXY_PID=$!
|
PROXY_PID=$!
|
||||||
PROXY_PORT=
|
PROXY_PORT=
|
||||||
|
|
||||||
local attempts=0
|
local attempts=0
|
||||||
while [[ -z ${PROXY_PORT} ]]; do
|
while [[ -z ${PROXY_PORT} ]]; do
|
||||||
if (( ${attempts} > 9 )); then
|
if (( attempts > 9 )); then
|
||||||
kill "${PROXY_PID}"
|
kill "${PROXY_PID}"
|
||||||
kube::log::error_exit "Couldn't start proxy. Failed to read port after ${attempts} tries. Got: $(cat ${PROXY_PORT_FILE})"
|
kube::log::error_exit "Couldn't start proxy. Failed to read port after ${attempts} tries. Got: $(cat "${PROXY_PORT_FILE}")"
|
||||||
fi
|
fi
|
||||||
sleep .5
|
sleep .5
|
||||||
kube::log::status "Attempt ${attempts} to read ${PROXY_PORT_FILE}..."
|
kube::log::status "Attempt ${attempts} to read ${PROXY_PORT_FILE}..."
|
||||||
PROXY_PORT=$(sed 's/.*Starting to serve on 127.0.0.1:\([0-9]*\)$/\1/'< ${PROXY_PORT_FILE})
|
PROXY_PORT=$(sed 's/.*Starting to serve on 127.0.0.1:\([0-9]*\)$/\1/'< "${PROXY_PORT_FILE}")
|
||||||
attempts=$((attempts+1))
|
attempts=$((attempts+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ function cleanup()
|
|||||||
rm -rf "${KUBE_TEMP}"
|
rm -rf "${KUBE_TEMP}"
|
||||||
|
|
||||||
local junit_dir="${KUBE_JUNIT_REPORT_DIR:-/tmp/junit-results}"
|
local junit_dir="${KUBE_JUNIT_REPORT_DIR:-/tmp/junit-results}"
|
||||||
echo "junit report dir:" ${junit_dir}
|
echo "junit report dir:" "${junit_dir}"
|
||||||
|
|
||||||
kube::log::status "Clean up complete"
|
kube::log::status "Clean up complete"
|
||||||
}
|
}
|
||||||
@ -231,9 +231,9 @@ function kubectl-with-retry()
|
|||||||
ERROR_FILE="${KUBE_TEMP}/kubectl-error"
|
ERROR_FILE="${KUBE_TEMP}/kubectl-error"
|
||||||
preserve_err_file=${PRESERVE_ERR_FILE:-false}
|
preserve_err_file=${PRESERVE_ERR_FILE:-false}
|
||||||
for count in {0..3}; do
|
for count in {0..3}; do
|
||||||
kubectl "$@" 2> ${ERROR_FILE} || true
|
kubectl "$@" 2> "${ERROR_FILE}" || true
|
||||||
if grep -q "the object has been modified" "${ERROR_FILE}"; then
|
if grep -q "the object has been modified" "${ERROR_FILE}"; then
|
||||||
kube::log::status "retry $1, error: $(cat ${ERROR_FILE})"
|
kube::log::status "retry $1, error: $(cat "${ERROR_FILE}")"
|
||||||
rm "${ERROR_FILE}"
|
rm "${ERROR_FILE}"
|
||||||
sleep $((2**count))
|
sleep $((2**count))
|
||||||
else
|
else
|
||||||
@ -255,12 +255,12 @@ function wait-for-pods-with-label()
|
|||||||
{
|
{
|
||||||
local i
|
local i
|
||||||
for i in $(seq 1 10); do
|
for i in $(seq 1 10); do
|
||||||
kubeout=`kubectl get po -l $1 --output=go-template --template='{{range.items}}{{.metadata.name}}{{end}}' --sort-by metadata.name "${kube_flags[@]}"`
|
kubeout=$(kubectl get po -l "$1" --output=go-template --template='{{range.items}}{{.metadata.name}}{{end}}' --sort-by metadata.name "${kube_flags[@]}")
|
||||||
if [[ $kubeout = $2 ]]; then
|
if [[ $kubeout = "$2" ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
echo Waiting for pods: $2, found $kubeout
|
echo Waiting for pods: "$2", found "$kubeout"
|
||||||
sleep $i
|
sleep "$i"
|
||||||
done
|
done
|
||||||
kube::log::error_exit "Timeout waiting for pods with label $1"
|
kube::log::error_exit "Timeout waiting for pods with label $1"
|
||||||
}
|
}
|
||||||
@ -324,7 +324,7 @@ runTests() {
|
|||||||
|
|
||||||
# token defined in hack/testdata/auth-tokens.csv
|
# token defined in hack/testdata/auth-tokens.csv
|
||||||
kube_flags_with_token=(
|
kube_flags_with_token=(
|
||||||
-s "https://127.0.0.1:${SECURE_API_PORT}" --token=admin-token --insecure-skip-tls-verify=true
|
-s "https://127.0.0.1:${SECURE_API_PORT}" "--token=admin-token" "--insecure-skip-tls-verify=true"
|
||||||
)
|
)
|
||||||
|
|
||||||
if [[ -z "${ALLOW_SKEW:-}" ]]; then
|
if [[ -z "${ALLOW_SKEW:-}" ]]; then
|
||||||
@ -336,42 +336,42 @@ runTests() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
id_field=".metadata.name"
|
id_field=".metadata.name"
|
||||||
labels_field=".metadata.labels"
|
export labels_field=".metadata.labels"
|
||||||
annotations_field=".metadata.annotations"
|
export annotations_field=".metadata.annotations"
|
||||||
service_selector_field=".spec.selector"
|
export service_selector_field=".spec.selector"
|
||||||
rc_replicas_field=".spec.replicas"
|
export rc_replicas_field=".spec.replicas"
|
||||||
rc_status_replicas_field=".status.replicas"
|
export rc_status_replicas_field=".status.replicas"
|
||||||
rc_container_image_field=".spec.template.spec.containers"
|
export rc_container_image_field=".spec.template.spec.containers"
|
||||||
rs_replicas_field=".spec.replicas"
|
export rs_replicas_field=".spec.replicas"
|
||||||
port_field="(index .spec.ports 0).port"
|
export port_field="(index .spec.ports 0).port"
|
||||||
port_name="(index .spec.ports 0).name"
|
export port_name="(index .spec.ports 0).name"
|
||||||
second_port_field="(index .spec.ports 1).port"
|
export second_port_field="(index .spec.ports 1).port"
|
||||||
second_port_name="(index .spec.ports 1).name"
|
export second_port_name="(index .spec.ports 1).name"
|
||||||
image_field="(index .spec.containers 0).image"
|
export image_field="(index .spec.containers 0).image"
|
||||||
pod_container_name_field="(index .spec.containers 0).name"
|
export pod_container_name_field="(index .spec.containers 0).name"
|
||||||
container_name_field="(index .spec.template.spec.containers 0).name"
|
export container_name_field="(index .spec.template.spec.containers 0).name"
|
||||||
hpa_min_field=".spec.minReplicas"
|
export hpa_min_field=".spec.minReplicas"
|
||||||
hpa_max_field=".spec.maxReplicas"
|
export hpa_max_field=".spec.maxReplicas"
|
||||||
hpa_cpu_field=".spec.targetCPUUtilizationPercentage"
|
export hpa_cpu_field=".spec.targetCPUUtilizationPercentage"
|
||||||
template_labels=".spec.template.metadata.labels.name"
|
export template_labels=".spec.template.metadata.labels.name"
|
||||||
statefulset_replicas_field=".spec.replicas"
|
export statefulset_replicas_field=".spec.replicas"
|
||||||
statefulset_observed_generation=".status.observedGeneration"
|
export statefulset_observed_generation=".status.observedGeneration"
|
||||||
job_parallelism_field=".spec.parallelism"
|
export job_parallelism_field=".spec.parallelism"
|
||||||
deployment_replicas=".spec.replicas"
|
export deployment_replicas=".spec.replicas"
|
||||||
secret_data=".data"
|
export secret_data=".data"
|
||||||
secret_type=".type"
|
export secret_type=".type"
|
||||||
change_cause_annotation='.*kubernetes.io/change-cause.*'
|
export change_cause_annotation='.*kubernetes.io/change-cause.*'
|
||||||
pdb_min_available=".spec.minAvailable"
|
export pdb_min_available=".spec.minAvailable"
|
||||||
pdb_max_unavailable=".spec.maxUnavailable"
|
export pdb_max_unavailable=".spec.maxUnavailable"
|
||||||
generation_field=".metadata.generation"
|
export generation_field=".metadata.generation"
|
||||||
container_len="(len .spec.template.spec.containers)"
|
export container_len="(len .spec.template.spec.containers)"
|
||||||
image_field0="(index .spec.template.spec.containers 0).image"
|
export image_field0="(index .spec.template.spec.containers 0).image"
|
||||||
image_field1="(index .spec.template.spec.containers 1).image"
|
export image_field1="(index .spec.template.spec.containers 1).image"
|
||||||
|
|
||||||
# Make sure "default" namespace exists.
|
# Make sure "default" namespace exists.
|
||||||
if kube::test::if_supports_resource "${namespaces}" ; then
|
if kube::test::if_supports_resource "${namespaces}" ; then
|
||||||
output_message=$(kubectl get "${kube_flags[@]}" namespaces)
|
output_message=$(kubectl get "${kube_flags[@]}" namespaces)
|
||||||
if [[ ! $(echo "${output_message}" | grep "default") ]]; then
|
if ! grep -q "default" <<< "${output_message}"; then
|
||||||
# Create default namespace
|
# Create default namespace
|
||||||
kubectl create "${kube_flags[@]}" ns default
|
kubectl create "${kube_flags[@]}" ns default
|
||||||
fi
|
fi
|
||||||
@ -398,7 +398,7 @@ runTests() {
|
|||||||
do
|
do
|
||||||
# running of kubeadm is captured in hack/make-targets/test-cmd.sh
|
# running of kubeadm is captured in hack/make-targets/test-cmd.sh
|
||||||
if [[ "${pkg}" != "kubeadm" ]]; then
|
if [[ "${pkg}" != "kubeadm" ]]; then
|
||||||
record_command run_${pkg}_tests
|
record_command run_"${pkg}"_tests
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
cleanup_tests
|
cleanup_tests
|
||||||
|
Loading…
Reference in New Issue
Block a user