Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for ingress-nginx. #173

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ingress/single-cluster/ingress-nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ GKE allows customers to deploy their own Ingress Controllers instead of the stan
- 1.16.5-gke.1 and later.


## Note
NGINX is not one of the GKE offering, this is just an exmaple of using custom controller.

### Networking Manifests

In this example an internal Ingress resource matches for HTTP traffic with `foo.example.com` for path `/foo` and sends it to the `foo` Service at port 8080. A public IP address is automatically provisioned by the Ngnix controller which listens for traffic on port 8080. The Ingress resource below shows that there is one host match. Any traffic which does not match this is sent to the default backend to provide 404 responses.
In this example an external Ingress resource matches for HTTP traffic with `foo.example.com` for path `/foo` and sends it to the `foo` Service at port 8080. A public IP address is automatically provisioned by the Ngnix controller which listens for traffic on port 8080. The Ingress resource below shows that there is one host match. Any traffic which does not match this is sent to the default backend to provide 404 responses.


```yaml
Expand Down
42 changes: 42 additions & 0 deletions ingress/single-cluster/ingress-nginx/cleanup.sh
Original file line number Diff line number Diff line change
@@ -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
test_name="ingress-nginx"
context=$(get_context "${test_name}")

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-nginx/ingress-nginx.yaml -n "${test_name}" || true
kubectl --context "${context}" delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml || true
kubectl --context "${context}" delete clusterrolebinding cluster-admin-binding || 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}" "${REGION}"
32 changes: 32 additions & 0 deletions ingress/single-cluster/ingress-nginx/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/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
test_name="ingress-nginx"
context=$(get_context "${test_name}")

if [[ -z "${context}" ]]; then
exit 1
fi

vip=$(wait_for_ingress_ip "foo-external" "${test_name}" "${context}")

check_http_status "${vip}/foo" 200 "host: foo.example.com"
42 changes: 42 additions & 0 deletions ingress/single-cluster/ingress-nginx/setup.sh
Original file line number Diff line number Diff line change
@@ -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
test_name="ingress-nginx"
setup_gke_basic "${test_name}" "${ZONE}" "${REGION}"
context=$(get_context "${test_name}")

if [[ -z "${context}" ]]; then
exit 1
fi

kubectl --context "${context}" create namespace "${test_name}"
kubectl --context "${context}" create clusterrolebinding cluster-admin-binding \
--clusterrole cluster-admin \
--user $(gcloud config get-value account)
kubectl --context "${context}" apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml

for ATTEMPT in $(seq 30); do
if kubectl --context "${context}" apply -f ingress/single-cluster/ingress-nginx/ingress-nginx.yaml -n "${test_name}"; then
break
fi
sleep 10 # Wait for webhook to be fully setup.
done