From a21acf99f708fa09d63009d121dcd7085f3b060a Mon Sep 17 00:00:00 2001 From: David Cheung Date: Wed, 18 Oct 2023 19:58:50 +0000 Subject: [PATCH] Add ingress-internal and ingress-external tests. * Add test scripts for ingress-internal and ingress-external. --- .../ingress-external-basic/cleanup.sh | 22 +++++++++- .../ingress-external-basic/run-test.sh | 15 ++++++- .../ingress-external-basic/setup.sh | 14 ++++++- .../ingress-internal-basic/cleanup.sh | 42 +++++++++++++++++++ .../ingress-internal-basic/run-test.sh | 35 ++++++++++++++++ .../ingress-internal-basic/setup.sh | 35 ++++++++++++++++ 6 files changed, 160 insertions(+), 3 deletions(-) mode change 100644 => 100755 ingress/single-cluster/ingress-external-basic/run-test.sh create mode 100755 ingress/single-cluster/ingress-internal-basic/cleanup.sh create mode 100755 ingress/single-cluster/ingress-internal-basic/run-test.sh create mode 100755 ingress/single-cluster/ingress-internal-basic/setup.sh diff --git a/ingress/single-cluster/ingress-external-basic/cleanup.sh b/ingress/single-cluster/ingress-external-basic/cleanup.sh index 18732a86..7649e1da 100755 --- a/ingress/single-cluster/ingress-external-basic/cleanup.sh +++ b/ingress/single-cluster/ingress-external-basic/cleanup.sh @@ -19,4 +19,24 @@ set -o nounset; set -o pipefail; set -o xtrace; -echo "Running external basic cleanup." +source ./test/helper.sh +source ./test/test.conf +test_name="ingress-external-basic" +suffix=$(get_hash "${test_name}") +context=$(kubectl config view -o json | jq -r ".contexts[] | select(.name | test(\"-${suffix}\")).name" || true) + +if [[ ! -z "${context}" ]]; then + ingress_name="foo-external" + fr=$(get_forwarding_rule "${ingress_name}" "${test_name}" "${context}") + thp=$(get_target_http_proxy "${ingress_name}" "${test_name}" "${context}") + thsp=$(get_target_https_proxy "${ingress_name}" "${test_name}" "${context}") + um=$(get_url_map "${ingress_name}" "${test_name}" "${context}") + backends=$(get_backends "${ingress_name}" "${test_name}" "${context}") + negs=$(get_negs "${context}") + + kubectl --context "${context}" delete -f ingress/single-cluster/ingress-external-basic/external-ingress-basic.yaml -n "${test_name}" || true + wait_for_glbc_deletion "${fr}" "${thp}" "${thsp}" "${um}" "${backends}" "${negs}" + kubectl --context "${context}" delete namespace "${test_name}" || true +fi + +cleanup_gke_basic "${test_name}" "${zone}" "${subnet_region}" diff --git a/ingress/single-cluster/ingress-external-basic/run-test.sh b/ingress/single-cluster/ingress-external-basic/run-test.sh old mode 100644 new mode 100755 index e472aaf4..86b75cf0 --- a/ingress/single-cluster/ingress-external-basic/run-test.sh +++ b/ingress/single-cluster/ingress-external-basic/run-test.sh @@ -19,4 +19,17 @@ set -o nounset; set -o pipefail; set -o xtrace; -echo "Running external basic test." +source ./test/helper.sh +source ./test/test.conf +test_name="ingress-external-basic" +suffix=$(get_hash "${test_name}") +context=$(kubectl config view -o json | jq -r ".contexts[] | select(.name | test(\"-${suffix}\")).name") + +if [[ -z "${context}" ]]; then + exit 1 +fi + +vip=$(wait_for_ingress_ip "foo-external" "${test_name}" "${context}") + +check_http_status "${vip}" 200 "host: foo.example.com" +check_http_status "${vip}" 404 "host: bar.example.com" diff --git a/ingress/single-cluster/ingress-external-basic/setup.sh b/ingress/single-cluster/ingress-external-basic/setup.sh index 7d37fdfc..a1f8957d 100755 --- a/ingress/single-cluster/ingress-external-basic/setup.sh +++ b/ingress/single-cluster/ingress-external-basic/setup.sh @@ -19,4 +19,16 @@ set -o nounset; set -o pipefail; set -o xtrace; -echo "Running external basic setup." +source ./test/helper.sh +source ./test/test.conf +test_name="ingress-external-basic" +setup_gke_basic "${test_name}" "${zone}" "${subnet_region}" +suffix=$(get_hash "${test_name}") +context=$(kubectl config view -o json | jq -r ".contexts[] | select(.name | test(\"-${suffix}\")).name") + +if [[ -z "${context}" ]]; then + exit 1 +fi + +kubectl --context "${context}" create namespace "${test_name}" +kubectl --context "${context}" apply -f ingress/single-cluster/ingress-external-basic/external-ingress-basic.yaml -n "${test_name}" diff --git a/ingress/single-cluster/ingress-internal-basic/cleanup.sh b/ingress/single-cluster/ingress-internal-basic/cleanup.sh new file mode 100755 index 00000000..ec4bdfb0 --- /dev/null +++ b/ingress/single-cluster/ingress-internal-basic/cleanup.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit; +set -o nounset; +set -o pipefail; +set -o xtrace; + +source ./test/helper.sh +source ./test/test.conf +test_name="ingress-internal-basic" +suffix=$(get_hash "${test_name}") +context=$(kubectl config view -o json | jq -r ".contexts[] | select(.name | test(\"-${suffix}\")).name" || true) + +if [[ ! -z "${context}" ]]; then + ingress_name="foo-internal" + fr=$(get_forwarding_rule "${ingress_name}" "${test_name}" "${context}") + thp=$(get_target_http_proxy "${ingress_name}" "${test_name}" "${context}") + thsp=$(get_target_https_proxy "${ingress_name}" "${test_name}" "${context}") + um=$(get_url_map "${ingress_name}" "${test_name}" "${context}") + backends=$(get_backends "${ingress_name}" "${test_name}" "${context}") + negs=$(get_negs "${context}") + + kubectl --context "${context}" delete -f ingress/single-cluster/ingress-internal-basic/internal-ingress-basic.yaml -n "${test_name}" || true + wait_for_glbc_deletion "${fr}" "${thp}" "${thsp}" "${um}" "${backends}" "${negs}" + kubectl --context "${context}" delete namespace "${test_name}" || true +fi + +cleanup_gke_basic "${test_name}" "${zone}" "${subnet_region}" diff --git a/ingress/single-cluster/ingress-internal-basic/run-test.sh b/ingress/single-cluster/ingress-internal-basic/run-test.sh new file mode 100755 index 00000000..ba2a1c16 --- /dev/null +++ b/ingress/single-cluster/ingress-internal-basic/run-test.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit; +set -o nounset; +set -o pipefail; +set -o xtrace; + +source ./test/helper.sh +source ./test/test.conf +test_name="ingress-internal-basic" +suffix=$(get_hash "${test_name}") +context=$(kubectl config view -o json | jq -r ".contexts[] | select(.name | test(\"-${suffix}\")).name") + +if [[ -z "${context}" ]]; then + exit 1 +fi + +vip=$(wait_for_ingress_ip "foo-internal" "${test_name}" "${context}") + +check_http_status "${vip}" 200 "host: foo.example.com" "${test_name}" "${zone}" +check_http_status "${vip}" 404 "host: bar.example.com" "${test_name}" "${zone}" diff --git a/ingress/single-cluster/ingress-internal-basic/setup.sh b/ingress/single-cluster/ingress-internal-basic/setup.sh new file mode 100755 index 00000000..42230be2 --- /dev/null +++ b/ingress/single-cluster/ingress-internal-basic/setup.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit; +set -o nounset; +set -o pipefail; +set -o xtrace; + +source ./test/helper.sh +source ./test/test.conf +test_name="ingress-internal-basic" +setup_gke_basic "${test_name}" "${zone}" "${subnet_region}" +setup_ilb "${test_name}" "${subnet_region}" +suffix=$(get_hash "${test_name}") +context=$(kubectl config view -o json | jq -r ".contexts[] | select(.name | test(\"-${suffix}\")).name") + +if [[ -z "${context}" ]]; then + exit 1 +fi + +kubectl --context "${context}" create namespace "${test_name}" +kubectl --context "${context}" apply -f ingress/single-cluster/ingress-internal-basic/internal-ingress-basic.yaml -n "${test_name}"