From e5b1c35fbbfb576abbc0770781eb07fd9f282204 Mon Sep 17 00:00:00 2001 From: Erick Fejta Date: Thu, 18 Oct 2018 11:48:47 -0700 Subject: [PATCH] Use kubectl get foo/name not get foo name --- examples/hellogrpc/e2e-test.sh | 40 ++++++++++-------- examples/hellohttp/e2e-test.sh | 41 +++++++++--------- examples/todocontroller/e2e-test.sh | 64 ++++++++++++++++------------- k8s/describe.sh.tpl | 7 ++-- 4 files changed, 84 insertions(+), 68 deletions(-) diff --git a/examples/hellogrpc/e2e-test.sh b/examples/hellogrpc/e2e-test.sh index 96a2378b..69b4b30d 100755 --- a/examples/hellogrpc/e2e-test.sh +++ b/examples/hellogrpc/e2e-test.sh @@ -24,44 +24,49 @@ if [[ -z "${1:-}" ]]; then fi get_lb_ip() { - kubectl --namespace=${USER} get service hello-grpc-staging \ - -o jsonpath='{.status.loadBalancer.ingress[0].ip}' + kubectl --namespace=${USER} get service hello-grpc-staging \ + -o jsonpath='{.status.loadBalancer.ingress[0].ip}' } # Ensure there is an ip address for hell-grpc-staging:50051 apply-lb() { + echo Applying service... bazel build examples/hellogrpc:staging-service.apply bazel-bin/examples/hellogrpc/staging-service.apply } create() { - bazel build examples/hellogrpc/${LANGUAGE}/server:staging.create - bazel-bin/examples/hellogrpc/${LANGUAGE}/server/staging.create + echo Creating $LANGUAGE... + bazel build examples/hellogrpc/${LANGUAGE}/server:staging.create + bazel-bin/examples/hellogrpc/${LANGUAGE}/server/staging.create } check_msg() { - bazel build examples/hellogrpc/${LANGUAGE}/client + bazel build examples/hellogrpc/${LANGUAGE}/client - OUTPUT=$(./bazel-bin/examples/hellogrpc/${LANGUAGE}/client/client $(get_lb_ip)) - echo Checking response from service: "${OUTPUT}" matches: "DEMO$1" - echo "${OUTPUT}" | grep "DEMO$1[ ]" + OUTPUT=$(./bazel-bin/examples/hellogrpc/${LANGUAGE}/client/client $(get_lb_ip)) + echo Checking response from service: "${OUTPUT}" matches: "DEMO$1" + echo "${OUTPUT}" | grep "DEMO$1[ ]" } edit() { - ./examples/hellogrpc/${LANGUAGE}/server/edit.sh "$1" + echo Setting $LANGUAGE to "$1" + ./examples/hellogrpc/${LANGUAGE}/server/edit.sh "$1" } update() { - bazel build examples/hellogrpc/${LANGUAGE}/server:staging.replace - bazel-bin/examples/hellogrpc/${LANGUAGE}/server/staging.replace + echo Updating $LANGUAGE... + bazel build examples/hellogrpc/${LANGUAGE}/server:staging.replace + bazel-bin/examples/hellogrpc/${LANGUAGE}/server/staging.replace } delete() { - kubectl get all --namespace="${USER}" --selector=app=hello-grpc-staging - bazel build examples/hellogrpc/${LANGUAGE}/server:staging.describe - bazel-bin/examples/hellogrpc/${LANGUAGE}/server/staging.describe - bazel build examples/hellogrpc/${LANGUAGE}/server:staging.delete - bazel-bin/examples/hellogrpc/${LANGUAGE}/server/staging.delete + echo Deleting $LANGUAGE... + kubectl get all --namespace="${USER}" --selector=app=hello-grpc-staging + bazel build examples/hellogrpc/${LANGUAGE}/server:staging.describe + bazel-bin/examples/hellogrpc/${LANGUAGE}/server/staging.describe + bazel build examples/hellogrpc/${LANGUAGE}/server:staging.delete + bazel-bin/examples/hellogrpc/${LANGUAGE}/server/staging.delete } @@ -71,8 +76,9 @@ while [[ -n "${1:-}" ]]; do LANGUAGE="$1" shift + delete || true create - trap "delete" EXIT + trap "echo FAILED, cleaning up...; delete" EXIT sleep 25 check_msg "" diff --git a/examples/hellohttp/e2e-test.sh b/examples/hellohttp/e2e-test.sh index 38d31b0c..edd32edb 100755 --- a/examples/hellohttp/e2e-test.sh +++ b/examples/hellohttp/e2e-test.sh @@ -25,12 +25,13 @@ fi get_lb_ip() { kubectl --namespace=${USER} get service hello-http-staging \ - -o jsonpath='{.status.loadBalancer.ingress[0].ip}' + -o jsonpath='{.status.loadBalancer.ingress[0].ip}' } # Ensure there is an ip address for hello-http-staging:8080 apply-lb() { - bazel run examples/hellohttp:staging-service.apply + echo Applying service... + bazel run examples/hellohttp:staging-service.apply } check_msg() { @@ -40,33 +41,35 @@ check_msg() { } edit() { - ./examples/hellohttp/${LANGUAGE}/edit.sh "$1" + echo Setting $LANGUAGE to "$1" + ./examples/hellohttp/${LANGUAGE}/edit.sh "$1" } apply() { - bazel run examples/hellohttp/${LANGUAGE}:staging.apply + echo Applying $LANGUAGE... + bazel run examples/hellohttp/${LANGUAGE}:staging.apply } delete() { - kubectl get all --namespace="${USER}" --selector=app=hello-http-staging - bazel run examples/hellohttp/${LANGUAGE}:staging.describe - bazel run examples/hellohttp/${LANGUAGE}:staging.delete + echo Deleting $LANGUAGE... + kubectl get all --namespace="${USER}" --selector=app=hello-http-staging + bazel run examples/hellohttp/${LANGUAGE}:staging.describe + bazel run examples/hellohttp/${LANGUAGE}:staging.delete } check_bad_substitution() { - echo Checking a bad substitution - if ! bazel run examples/hellohttp:error-on-run; - then - echo "Success, substitution failed." - return - else - echo "Bad substitution should fail!" - exit 1 - fi + echo Checking a bad substitution... + if ! bazel run examples/hellohttp:error-on-run; then + echo "Success, substitution failed." + return 0 + else + echo "Bad substitution should fail!" + exit 1 + fi } check_no_images_resolution() { - echo Checking resolution with no images attribute. + echo Checking resolution with no images attribute... bazel build examples/hellohttp:resolve-external OUTPUT=$(bazel-bin/examples/hellohttp/resolve-external 2>&1) echo Checking output: "${OUTPUT}" matches: "/pause@" @@ -83,8 +86,8 @@ while [[ -n "${1:-}" ]]; do LANGUAGE="$1" shift - apply - trap "delete" EXIT + apply # apply will handle already created + trap "echo FAILED, cleaning up...; delete" EXIT sleep 25 check_msg "" diff --git a/examples/todocontroller/e2e-test.sh b/examples/todocontroller/e2e-test.sh index da4fa504..2506356a 100755 --- a/examples/todocontroller/e2e-test.sh +++ b/examples/todocontroller/e2e-test.sh @@ -18,66 +18,72 @@ set -e LANGUAGE="$1" function get_lb_ip() { - kubectl --namespace=${USER} get service hello-grpc-staging \ - -o jsonpath='{.status.loadBalancer.ingress[0].ip}' + kubectl --namespace=${USER} get service hello-grpc-staging \ + -o jsonpath='{.status.loadBalancer.ingress[0].ip}' } function create() { - bazel build examples/todocontroller/${LANGUAGE}:staging.create - bazel-bin/examples/todocontroller/${LANGUAGE}/staging.create - bazel build examples/todocontroller:example-todo.create - bazel-bin/examples/todocontroller/example-todo.create + echo Creating $LANGUAGE... + bazel build examples/todocontroller/${LANGUAGE}:staging.create + bazel-bin/examples/todocontroller/${LANGUAGE}/staging.create + bazel build examples/todocontroller:example-todo.create + bazel-bin/examples/todocontroller/example-todo.create } function check_msg() { - bazel build examples/todocontroller:example-todo.describe + bazel build examples/todocontroller:example-todo.describe - OUTPUT=$(./bazel-bin/examples/todocontroller/example-todo.describe) - echo Checking response from service: "${OUTPUT}" matches: "DEMO$1" - echo "${OUTPUT}" | grep "DEMO$1[ ]" + OUTPUT=$(./bazel-bin/examples/todocontroller/example-todo.describe) + echo Checking response from service: "${OUTPUT}" matches: "DEMO$1" + echo "${OUTPUT}" | grep "DEMO$1[ ]" } function edit() { - ./examples/todocontroller/${LANGUAGE}/edit.sh "$1" + echo Editing $LANGUAGE to $1... + ./examples/todocontroller/${LANGUAGE}/edit.sh "$1" } function update_controller() { - bazel build examples/todocontroller/${LANGUAGE}:controller-deployment.replace - bazel-bin/examples/todocontroller/${LANGUAGE}/controller-deployment.replace + echo Replacing $LANGUAGE controller... + bazel build examples/todocontroller/${LANGUAGE}:controller-deployment.replace + bazel-bin/examples/todocontroller/${LANGUAGE}/controller-deployment.replace } function update_todo() { - bazel build examples/todocontroller:example-todo.replace - bazel-bin/examples/todocontroller/example-todo.replace + echo Replacing example-todo... + bazel build examples/todocontroller:example-todo.replace + bazel-bin/examples/todocontroller/example-todo.replace } function delete() { - bazel run examples/todocontroller/example-todo.describe - bazel run examples/todocontroller/${LANGUAGE}:controller-deployment.describe - - bazel build examples/todocontroller/example-todo.delete - bazel-bin/examples/todocontroller/example-todo.delete - bazel build examples/todocontroller/${LANGUAGE}:staging.delete - bazel-bin/examples/todocontroller/${LANGUAGE}/staging.delete + echo Deleting $LANGUAGE... + bazel run examples/todocontroller/example-todo.describe + bazel run examples/todocontroller/${LANGUAGE}:controller-deployment.describe + + bazel build examples/todocontroller/example-todo.delete + bazel-bin/examples/todocontroller/example-todo.delete + bazel build examples/todocontroller/${LANGUAGE}:staging.delete + bazel-bin/examples/todocontroller/${LANGUAGE}/staging.delete } function check_reverse_delete_k8s_object() { - echo Checking deletion in reverse order via k8s_object. - bazel run examples/todocontroller:joined.apply - bazel run examples/todocontroller:joined.delete + echo Checking deletion in reverse order via k8s_object... + bazel run examples/todocontroller:joined.apply + bazel run examples/todocontroller:joined.delete } function check_reverse_delete_k8s_objects() { - echo Checking deletion in reverse order via k8s_objects. - bazel run examples/todocontroller:everything.apply - bazel run examples/todocontroller:everything.delete + echo Checking deletion in reverse order via k8s_objects... + bazel run examples/todocontroller:everything.apply + bazel run examples/todocontroller:everything.delete } check_reverse_delete_k8s_object check_reverse_delete_k8s_objects +delete || true create -trap "delete" EXIT +trap "echo FAILED, cleaning up...; delete" EXIT sleep 25 check_msg diff --git a/k8s/describe.sh.tpl b/k8s/describe.sh.tpl index c5618b12..68798e2e 100644 --- a/k8s/describe.sh.tpl +++ b/k8s/describe.sh.tpl @@ -23,7 +23,8 @@ function guess_runfiles() { RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}" -RESOURCE_NAME=$(kubectl create --dry-run -f "%{unresolved}" | cut -d'"' -f 2) +RESOURCE_NAME=$(kubectl create --dry-run -f "%{unresolved}" -o name | cut -d'"' -f 2) -kubectl --cluster="%{cluster}" --context="%{context}" --user="%{user}" %{namespace_arg} describe %{kind} \ - "${RESOURCE_NAME}" \ No newline at end of file +kubectl \ + --cluster="%{cluster}" --context="%{context}" --user="%{user}" \ + %{namespace_arg} describe "${RESOURCE_NAME}"