mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-01 09:18:45 +00:00
Merge pull request #84871 from liggitt/cmd-test
Make test-cmd effective again
This commit is contained in:
@@ -138,6 +138,8 @@ kube::test::describe_object_assert() {
|
||||
|
||||
for match in "${matches[@]}"; do
|
||||
if grep -q "${match}" <<< "${result}"; then
|
||||
echo "matched ${match}"
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "$(kube::test::get_caller): FAIL!"
|
||||
echo "Describe ${resource} ${object}"
|
||||
@@ -204,6 +206,8 @@ kube::test::describe_resource_assert() {
|
||||
|
||||
for match in "${matches[@]}"; do
|
||||
if grep -q "${match}" <<< "${result}"; then
|
||||
echo "matched ${match}"
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "FAIL!"
|
||||
echo "Describe ${resource}"
|
||||
@@ -256,14 +260,10 @@ kube::test::describe_resource_events_assert() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Compare sort-by resource name output with expected order specify in the last parameter
|
||||
# Compare sort-by resource name output (first column, skipping first line) with expected order specify in the last parameter
|
||||
kube::test::if_sort_by_has_correct_order() {
|
||||
IFS=" " read -r -a array <<< "$(echo "$1" |awk '{if(NR!=1) print $1}')"
|
||||
local var
|
||||
for i in "${array[@]}"; do
|
||||
var+="${i}:"
|
||||
done
|
||||
|
||||
var="$(echo "$1" | awk '{if(NR!=1) print $1}' | tr '\n' ':')"
|
||||
kube::test::if_has_string "${var}" "${@:$#}"
|
||||
}
|
||||
|
||||
|
@@ -278,15 +278,15 @@ run_pod_tests() {
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||
# Command
|
||||
kubectl create -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml "${kube_flags[@]}"
|
||||
kubectl create -f test/e2e/testing-manifests/kubectl/redis-master-pod.yaml "${kube_flags[@]}"
|
||||
# Post-condition: valid-pod and redis-master PODs are created
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'redis-master:valid-pod:'
|
||||
kubectl create -f test/e2e/testing-manifests/kubectl/agnhost-master-pod.yaml "${kube_flags[@]}"
|
||||
# Post-condition: valid-pod and agnhost-master PODs are created
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'agnhost-master:valid-pod:'
|
||||
|
||||
### Delete multiple PODs at once
|
||||
# Pre-condition: valid-pod and redis-master PODs exist
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'redis-master:valid-pod:'
|
||||
# Pre-condition: valid-pod and agnhost-master PODs exist
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'agnhost-master:valid-pod:'
|
||||
# Command
|
||||
kubectl delete pods valid-pod redis-master "${kube_flags[@]}" --grace-period=0 --force # delete multiple pods at once
|
||||
kubectl delete pods valid-pod agnhost-master "${kube_flags[@]}" --grace-period=0 --force # delete multiple pods at once
|
||||
# Post-condition: no POD exists
|
||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||
|
||||
|
@@ -96,11 +96,7 @@ run_kubectl_get_tests() {
|
||||
# Post-condition: POD abc should error since it doesn't exist
|
||||
kube::test::if_has_string "${output_message}" 'pods "abc" not found'
|
||||
# Post-condition: make sure we don't display an empty List
|
||||
if kube::test::if_has_string "${output_message}" 'List'; then
|
||||
echo 'Unexpected List output'
|
||||
echo "${LINENO} $(basename "$0")"
|
||||
exit 1
|
||||
fi
|
||||
kube::test::if_has_not_string "${output_message}" 'List'
|
||||
|
||||
### Test kubectl get all
|
||||
output_message=$(kubectl --v=6 --namespace default get all --chunk-size=0 2>&1 "${kube_flags[@]}")
|
||||
|
@@ -128,9 +128,17 @@ function record_command() {
|
||||
local output="${KUBE_JUNIT_REPORT_DIR:-/tmp/junit-results}"
|
||||
echo "Recording: ${name}"
|
||||
echo "Running command: $*"
|
||||
if ! juLog -output="${output}" -class="test-cmd" -name="${name}" "$@"
|
||||
then
|
||||
echo "Error when running ${name}"
|
||||
juLog -output="${output}" -class="test-cmd" -name="${name}" "$@"
|
||||
local exitCode=$?
|
||||
if [[ ${exitCode} -ne 0 ]]; then
|
||||
# Record failures for any non-canary commands
|
||||
if [ "${name}" != "record_command_canary" ]; then
|
||||
echo "Error when running ${name}"
|
||||
foundError="${foundError}""${name}"", "
|
||||
fi
|
||||
elif [ "${name}" == "record_command_canary" ]; then
|
||||
# If the canary command passed, fail
|
||||
echo "record_command_canary succeeded unexpectedly"
|
||||
foundError="${foundError}""${name}"", "
|
||||
fi
|
||||
|
||||
@@ -138,6 +146,22 @@ function record_command() {
|
||||
set -o errexit
|
||||
}
|
||||
|
||||
# Ensure our record_command stack correctly propagates and detects errexit failures in invoked commands - see https://issue.k8s.io/84871
|
||||
foundError=""
|
||||
function record_command_canary()
|
||||
{
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
bogus-expected-to-fail
|
||||
set +o nounset
|
||||
set +o errexit
|
||||
}
|
||||
KUBE_JUNIT_REPORT_DIR=$(mktemp -d /tmp/record_command_canary.XXXXX) record_command record_command_canary
|
||||
if [[ -n "${foundError}" ]]; then
|
||||
echo "FAILED TESTS: record_command_canary"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Stops the running kubectl proxy, if there is one.
|
||||
function stop-proxy()
|
||||
{
|
||||
|
32
test/e2e/testing-manifests/kubectl/agnhost-master-pod.yaml
Normal file
32
test/e2e/testing-manifests/kubectl/agnhost-master-pod.yaml
Normal file
@@ -0,0 +1,32 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
labels:
|
||||
name: agnhost
|
||||
role: master
|
||||
name: agnhost-master
|
||||
spec:
|
||||
containers:
|
||||
- name: master
|
||||
image: gcr.io/kubernetes-e2e-test-images/agnhost:1.0
|
||||
env:
|
||||
- name: MASTER
|
||||
value: "true"
|
||||
ports:
|
||||
- containerPort: 6379
|
||||
resources:
|
||||
limits:
|
||||
cpu: "0.1"
|
||||
volumeMounts:
|
||||
- mountPath: /agnhost-master-data
|
||||
name: data
|
||||
- name: sentinel
|
||||
image: gcr.io/kubernetes-e2e-test-images/agnhost:1.0
|
||||
env:
|
||||
- name: SENTINEL
|
||||
value: "true"
|
||||
ports:
|
||||
- containerPort: 26379
|
||||
volumes:
|
||||
- name: data
|
||||
emptyDir: {}
|
Reference in New Issue
Block a user