Skip to content

Commit

Permalink
Add templates for recipe test files, and update Contribution.md.
Browse files Browse the repository at this point in the history
* Add template and instruction for new recipe test in test/README.md.
* Update Contribution.md and README.md for newly created recipes.
  • Loading branch information
sawsa307 committed Oct 27, 2023
1 parent 4a19889 commit dc73771
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The goal for GKE Networking Recipes is to provide a bite-sized, easy to consume,
- Each recipe should have its own folder that includes all of the deployment YAML necessary to achieve the use-case in addition to its README.
- The resource manifests should be stored in a single YAML file so that it can be easily copied, pasted, and deployed with a single command. Exceptions include multiple deployment steps (like v1 and v2 of an app) or multiple clusters where different manifests are deployed to each.
- Each recipe should use the [whereami sample application](https://github.com/GoogleCloudPlatform/kubernetes-engine-samples/tree/master/whereami) wherever possible to demonstrate the use-case. There may be use-cases that depend on specific application functionality so it is fine to diverge in these instances.
- Each recipe should include its corresponding test files that follows the testing framework and guideline described in the [test README page](./test/README.md).
- Recipes should rely on the shared [GKE cluster setup](./cluster-setup.md) steps instead of instructing how to deploy the cluster or environment. Each recipe should focus on just the use-case without repeating any boilerplate setup. Please make sure to use Anchor links (Exp: cluster-setup.md#Multi-cluster-environment-basic) to send the user to the proper section of the doc.
- For special cases where a unique environment or more than one cluster is required, feel free to include these steps in the recipe.
- There should be clear ownership of a recipe. Each recipe has one owner. If you contributed it then you own it until someone else has agreed to be the owner. If functionality changes and your recipe is no longer valid or no longer makes sense, it is your responsibility to update over time.
Expand Down Expand Up @@ -47,8 +48,11 @@ Each recipe's README should consist of the following sections. In general the RE
| [Secure Ingress](./ingress/single-cluster/ingress-https) | |
| [IAP Ingress](./ingress/single-cluster/ingress-iap) | |
| [CloudArmor Ingress](./ingress/single-cluster/ingress-cloudarmor) | |
| [Nginx Ingress](./ingress/single-cluster/ingress-nginx) | |
| [Custom default backend Ingress](./ingress/single-cluster/ingress-custom-default-backend) | |
| [Custom HTTP Health Check Ingress](./ingress/single-cluster/ingress-custom-http-health-check) | |
| [Ingress gRPC Health Check Ingress](./ingress/single-cluster/ingress-custom-grpc-health-check) | [@rramkumar1](https://github.com/rramkumar1) |
| [Istio Ingress Gateway with multiple Backend Configs](./ingress/single-cluster/ingress-asm-multi-backendconfig) | |
| [Basic Multi-Cluster Ingress](./ingress/multi-cluster/mci-basic) | [@mark-church](https://github.com/mark-church) |
| [Multi-Cluster Ingress Blue-Green Cluster Migration](./ingress/multi-cluster/mci-blue-green-cluster) | |
| [Multi-Cluster Ingress Blue-Green App Migration](./ingress/multi-cluster/mci-blue-green-app) | |
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ GKE is a managed Kubernetes platform that provides a more opinionated and seamle
- [IAP Ingress](./ingress/single-cluster/ingress-iap) - GKE Ingress with Identity-Aware Proxy based authentication.
- [CloudArmor Ingress](./ingress/single-cluster/ingress-cloudarmor) - GKE Ingress with Google CloudArmor policy protection.
- [Nginx Ingress](./ingress/single-cluster/ingress-nginx) - Deploy an internet-facing HTTP load balancer with Nginx Ingress.
- [Custom default backend Ingress](./ingress/single-cluster/ingress-custom-default-backend) - GKE Ingress with custom default backend.
- [Custom HTTP health check Ingress](./ingress/single-cluster/ingress-custom-http-health-check) - GKE Ingress with custom HTTP based health check.
- [Custom gRPC health check Ingress](./ingress/single-cluster/ingress-custom-grpc-health-check) - GKE Ingress with custom gRPC based health check.
- [Istio Ingress Gateway with multiple Backend Configs](./ingress/single-cluster/ingress-asm-multi-backendconfig) - Deploy ASM ingress gateway to run multiple different backends with different Backend Configs

- Multi-cluster Ingress
- [Basic Multi-cluster Ingress](./ingress/multi-cluster/mci-basic) - Deploy applications across different clusters and different regions but retain a single global load balancer and public IP for global traffic management.
Expand Down
31 changes: 28 additions & 3 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.

The tests here are intended to test the recipes in this repo to make sure it workable and up-to-date.

## Running the test locally
## Running tests locally

Make sure you have valid credentials for accessing GCP:

Expand All @@ -42,13 +42,13 @@ Make sure you are at the root directory of the repository.
cd gke-networking-recipes
```


Make sure to set ZONE and REGION environment variables before running tests. Resources will be deployed to the specified region and/or zone.
```
export ZONE=zone
export REGION=region
```

### To run a specific test
To run a specific test, run the setup.sh, run-test.sh, and cleanup.sh in order in the recipe directory.

```
Expand All @@ -62,6 +62,7 @@ To cleanup a specific test separately, you can run its cleanup.sh.
./ingress/single-cluster/ingress-external-basic/cleanup.sh
```

### To run all tests
To run all tests, use the following make command:
```
make test
Expand All @@ -70,4 +71,28 @@ make test
To cleanup all tests separately, use the following command from test/:
```
./test/cleanup_all.sh
```
```

## Adding a new recipe test

For a new recipe, in addition to its yaml file and REAME.md, it should also include a set of test files to make sure the recipe is functional and up-to-date.

A recipe directory should have the following layout:
```
gke-networking-recipes/
ingress/
single-cluster/
ingress-external-basic/
external-ingress.yaml
README.md
setup.sh # Test file for setup resources
run-test.sh # Test file for validation
cleanup.sh # Test file for cleanup resources
...
```

Note that the files has to be named in the exact way to be picked up by the [test framework](recipe_test.go). If any of the test files is missing, it would be skipped by the framework.

You should validate your test passes by following instruction from `Running tests locally`. When creating a new test, you can utilize the helper functions defined in the [helper functions library](./helper.sh). You can find examples for each test file in the [test_example](./test_example/). In general, each test should contain at least one `check_http_status` call in its run-test.sh to validate the traffic.

For additional helper functions, please submit a feature request or raise a pull request with example.
37 changes: 37 additions & 0 deletions test/test_example/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/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
# TODO: Fill in your test name here.
# test_name="TEST_NAME"
context=$(get_context "${test_name}")

if [[ ! -z "${context}" ]]; then
# TODO: Delete the k8s resources.
# Use `|| true` to make sure the command won't failed due to resources not exist.
kubectl --context "${context}" delete -f YOUR_YAML.yaml -n "${test_name}" || true
kubectl --context "${context}" delete namespace "${test_name}" || true
fi

# TODO: Delete any additional resources created during setup.
# gcloud ...

cleanup_gke_basic "${test_name}" "${ZONE}" "${REGION}"
33 changes: 33 additions & 0 deletions test/test_example/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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
# TODO: Fill in your test name here.
# test_name="TEST_NAME"
context=$(get_context "${test_name}")

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

# TODO: Validate traffic here.
vip=...
check_http_status "${vip}" ... ...
36 changes: 36 additions & 0 deletions test/test_example/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/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
# TODO: Fill in your test name here.
# test_name="TEST_NAME"
# TODO: You can use setup_gke_basic for common test setup, or define your own test setup.
# 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}"
# TODO: Add any addition setup if needed(gcloud, kubectl, etc.), and deploy the k8s resources.
# gcloud ...
# kubectl --context "${context}" apply -f YOUR_YAML.yaml -n "${test_name}"

0 comments on commit dc73771

Please sign in to comment.