Skip to content

Commit

Permalink
DRY test scripts + improve documentation
Browse files Browse the repository at this point in the history
Closes knative-extensions#322.
Closes knative-extensions#292.

Think along the lines on how to refactor and organize for having tests for multiple vendors. This is only a start.
  • Loading branch information
Carlisia Thompson authored and carlisia committed Jul 1, 2022
1 parent a15b90b commit d2a24b4
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 287 deletions.
191 changes: 22 additions & 169 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,187 +1,40 @@
# Development

This doc explains how to setup a development environment so you can get started
[contributing](https://www.knative.dev/contributing/) to Knative
`net-gateway-api`. Also take a look at:
contributing to Knative `net-gateway-api`.

Before submitting a PR, see also:
- [CONTRIBUTING.md](./CONTRIBUTING.md).
- [The pull request workflow](https://knative.dev/community/contributing/reviewing/)

## Getting started
__NOTE__ If you use the konk script to setup your cluster, your cluster will be named `knative`. However, most of the scripts expect it to be the default `kind` name. Set the kind cluster name env `export KIND_CLUSTER_NAME=knative` to point to `knative` cluster. KO requires a registry which if you are developing locally you could use `export KO_DOCKER_REPO=kind.local` to use the local one on kind. Please see official [KO documentation](https://github.com/google/ko#local-publishing-options) for more information.

1. Create [a GitHub account](https://github.com/join)
1. Setup
[GitHub access via SSH](https://help.github.com/articles/connecting-to-github-with-ssh/)
1. Install [requirements](#requirements)
1. Set up your [shell environment](#environment-setup)
1. [Create and checkout a repo fork](#checkout-your-fork)
__NOTE__ Versions to be installed are listed in `./hack/test-env.sh`.

Before submitting a PR, see also [CONTRIBUTING.md](./CONTRIBUTING.md).
__NOTE__ Tests are currently wip. Please see [README#tests](README.md#tests)

### Requirements
1. A Kind cluster
1. [Knative serving installed](README.md#install-knative-serving)
1. [`ko`](https://github.com/google/ko): For development.
1. [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/): For managing development environments.

You must install these tools:

1. [`go`](https://golang.org/doc/install): The language Knative `net-gateway-api`
is built in
1. [`git`](https://help.github.com/articles/set-up-git/): For source control
1. [`dep`](https://github.com/golang/dep): For managing external dependencies.

### Environment setup

To get started you'll need to set these environment variables (we recommend
adding them to your `.bashrc`):

1. `GOPATH`: If you don't have one, simply pick a directory and add
`export GOPATH=...`

1. `$GOPATH/bin` on `PATH`: This is so that tooling installed via `go get` will
work properly.

`.bashrc` example:

```shell
export GOPATH="$HOME/go"
export PATH="${PATH}:${GOPATH}/bin"
```

### Checkout your fork

The Go tools require that you clone the repository to the
`src/knative.dev/net-gateway-api` directory in your
[`GOPATH`](https://github.com/golang/go/wiki/SettingGOPATH).

To check out this repository:

1. Create your own
[fork of this repo](https://help.github.com/articles/fork-a-repo/)

1. Clone it to your machine:

```shell
mkdir -p ${GOPATH}/src/knative.dev
cd ${GOPATH}/src/knative.dev
git clone git@github.com:${YOUR_GITHUB_USERNAME}/net-gateway-api.git
cd net-gateway-api
git remote add upstream https://github.com/knative-sandbox/net-gateway-api.git
git remote set-url --push upstream no_push
```

_Adding the `upstream` remote sets you up nicely for regularly
[syncing your fork](https://help.github.com/articles/syncing-a-fork/)._

Once you reach this point you are ready to do a full build and deploy as
described below.

### Execute conformance tests

Currently this repo tests with Istio and Contour. Please follow
[Test with Istio](#test-with-istio) or [Test with Contour](#test-with-contour).

### Test with Istio

#### Prepare test resources such as namespaces

```
kubectl apply -f test/config/
```

#### Load tested environment versions

```
source ./hack/test-env.sh
```

#### Install Gateway API CRDs

```
kubectl apply -k "github.com/kubernetes-sigs/gateway-api/config/crd?ref=${GATEWAY_API_VERSION}"
```

#### Deploy Istio

Run the following command to install Istio:

__NOTE__ You can find the Istio version to be installed in `./hack/test-env.sh`.

```shell
curl -sL https://istio.io/downloadIstioctl | sh -
$HOME/.istioctl/bin/istioctl install -y
```

#### Deploy GatewayClass and Gateway

```
kubectl apply -f ./third_party/istio/gateway/
```

#### Execute test

```shell
GATEWAY_OVERRIDE=istio-ingressgateway
GATEWAY_NAMESPACE_OVERRIDE=istio-system
IPS=( $(kubectl get nodes -lkubernetes.io/hostname!=kind-control-plane -ojsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}') )

go test -v -tags=e2e -count=1 ./test/conformance/ingressv2/ -run "TestIngressConformance/basics" \
--ingressClass=istio \
--ingressendpoint="${IPS[0]}"
```

Some tests are still not available. Please see
https://github.com/knative-sandbox/net-gateway-api/issues/23.

### Test with Contoour

#### Prepare test resources such as namespaces

```
kubectl apply -f test/config/
```

#### Load tested environment versions

```
source ./hack/test-env.sh
```

#### Install Gateway API CRDs

This step is not necessary for Contour as contour operator installs Gateway API
CRDs.

#### Deploy Contour

Run the following command to install Contour and its operator.

__NOTE__ You can find the Contour version to be installed in `./hack/test-env.sh`.
## Testing
Currently this repo contains Knative conformance tests that run with Istio and Contour.

```shell
kubectl apply -f "https://raw.githubusercontent.com/projectcontour/contour-operator/${CONTOUR_VERSION}/examples/operator/operator.yaml"
```
### Conformance
#### Istio

#### Deploy GatewayClass and Gateway
`./test/kind-conformance-istio.sh`

```
ko resolve -f ./third_party/contour/gateway/gateway-external.yaml | \
sed 's/LoadBalancerService/NodePortService/g' | \
kubectl apply -f -
#### Contour

ko resolve -f ./third_party/contour/gateway/gateway-internal.yaml | \
kubectl apply -f -
```
`./test/kind-conformance-contour.sh`

#### Execute test
### e2e
#### Istio

```shell
GATEWAY_OVERRIDE=envoy
GATEWAY_NAMESPACE_OVERRIDE=contour-external
LOCAL_GATEWAY_OVERRIDE=envoy
LOCAL_GATEWAY_NAMESPACE_OVERRIDE=contour-internal
IPS=( $(kubectl get nodes -lkubernetes.io/hostname!=kind-control-plane -ojsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}') )
`./test/kind-e2e-istio.sh`

go test -v -tags=e2e -count=1 ./test/conformance/ingressv2/ -run "TestIngressConformance/hosts/basics" \
--ingressClass=contour \
--ingressendpoint="${IPS[0]}"
```
#### Contour

Some tests are still not available. Please see
https://github.com/knative-sandbox/net-gateway-api/issues/36.
`./test/kind-e2e-contour.sh`
73 changes: 46 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,44 @@
[![GoDoc](https://godoc.org/knative-sandbox.dev/net-gateway-api?status.svg)](https://godoc.org/knative.dev/net-gateway-api)
[![Go Report Card](https://goreportcard.com/badge/knative-sandbox/net-gateway-api)](https://goreportcard.com/report/knative-sandbox/net-gateway-api)

net-gateway-api repository contains a KIngress implementation and testing for Knative
integration with the
[Kubernetes Gateway API](https://gateway-api.sigs.k8s.io/).
net-gateway-api repository contains a KIngress implementation and testing for Knative integration with the [Kubernetes Gateway API](https://gateway-api.sigs.k8s.io/).

This work is still in early development, which means it's _not ready for production_, but also that your feedback can have a big impact. You can find the tested Ingress and unavailable features [here](docs/test-version.md).

This work is still in early development, which means it's _not ready for production_, but also that your feedback can have a big impact.
You can also find the tested Ingress and unavailable features [here](docs/test-version.md).

## Tests
Note: conformance and e2e tests are a wip at the moment. Please see:

- [EPIC - Contour tests · Issue #36 · knative-sandbox/net-gateway-api](https://github.com/knative-sandbox/net-gateway-api/issues/36)
- [EPIC - Istio tests · Issue #23 · knative-sandbox/net-gateway-api](https://github.com/knative-sandbox/net-gateway-api/issues/23)

---

## Getting started
### Requirements
1. A Kind cluster
1. Knative serving installed
1. [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
1. `export KO_DOCKER_REPO=kind.local`

- Load tested environment versions
### Load tested environment versions

```
source ./hack/test-env.sh
```

- Install Knative Serving
### Install Knative serving

```bash
kubectl apply -f https://github.com/knative/serving/releases/latest/download/serving-crds.yaml
kubectl apply -f https://github.com/knative/serving/releases/latest/download/serving-core.yaml
```

- Install net-gateway-api

```bash
ko apply -f config/
```

- Then install Istio and its gateway resources:

__NOTE__ You can find the Istio version to be installed in `./hack/test-env.sh`.

```bash
curl -sL https://istio.io/downloadIstioctl | sh -
$HOME/.istioctl/bin/istioctl install -y

kubectl apply -f third_party/istio/gateway/
```

- Configure Knative Serving to use the proper "ingress.class":
#### Configure Knative
##### Ingress
Configuration so Knative serving uses the proper "ingress.class":

```bash
kubectl patch configmap/config-network \
Expand All @@ -53,7 +51,8 @@ kubectl patch configmap/config-network \
-p '{"data":{"ingress.class":"gateway-api.ingress.networking.knative.dev"}}'
```

- Configure Knative Serving to use nip.io for DNS. For `kind` the loadbalancer IP is `127.0.0.1`:
##### Load balancer
Configuration so Knative serving uses nip.io for DNS. For `kind` the loadbalancer IP is `127.0.0.1`:

```bash
kubectl patch configmap/config-domain \
Expand All @@ -62,7 +61,7 @@ kubectl patch configmap/config-domain \
-p '{"data":{"127.0.0.1.nip.io":""}}'
```

- (OPTIONAL) Deploy a sample hello world app:
##### (OPTIONAL) Deploy a sample hello world app:

```bash
cat <<-EOF | kubectl apply -f -
Expand All @@ -81,15 +80,35 @@ spec:
EOF
```

- (OPTIONAL) For testing purposes, you can use port-forwarding to make requests
to ingress from your machine:

### Install net-gateway-api

```bash
kubectl apply -k config/
```

### Install Istio
__NOTE__ You can find the Istio version to be installed in `./hack/test-env.sh`.

```bash
curl -sL https://istio.io/downloadIstioctl | sh -
$HOME/.istioctl/bin/istioctl install -y

kubectl apply -f third_party/istio/gateway/
```


### (OPTIONAL) For testing purpose
You can use port-forwarding to make requests to ingress from your machine:

```bash
kubectl port-forward -n istio-system $(kubectl get pod -n istio-system -l "app=istio-ingressgateway" --output=jsonpath="{.items[0].metadata.name}") 8080:8080

curl -v -H "Host: helloworld-go.default.127.0.0.1.nip.io" http://localhost:8080
```

---

To learn more about Knative, please visit our
[Knative docs](https://github.com/knative/docs) repository.

Expand Down
27 changes: 18 additions & 9 deletions test/e2e-common.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
# limitations under the License.

# This script includes common functions for testing setup and teardown.
# Expected prerequisites:
# * A Kind cluster
# * Knative serving installed

source $(dirname $0)/../vendor/knative.dev/hack/e2e-tests.sh
source $(dirname $0)/../hack/test-env.sh

export CONTROL_NAMESPACE=knative-serving
export KO_DOCKER_REPO=kind.local
export CLUSTER_SUFFIX=${CLUSTER_SUFFIX:-cluster.local}
export IPS=( $(kubectl get nodes -lkubernetes.io/hostname!=kind-control-plane -ojsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}') )

# Setup resources.
function test_setup() {
function log_setup() {
echo ">> Setting up logging..."
# Install kail if needed.
if ! which kail >/dev/null; then
Expand All @@ -32,7 +37,10 @@ function test_setup() {
local kail_pid=$!
# Clean up kail so it doesn't interfere with job shutting down
add_trap "kill $kail_pid || true" EXIT
}

# Setup resources.
function test_setup() {
# Setting up test resources.
echo ">> Publishing test images"
$(dirname $0)/upload-test-images.sh || fail_test "Error uploading test images"
Expand All @@ -49,14 +57,15 @@ function test_setup() {
echo ">> Waiting for controller components to be running..."
kubectl -n "${CONTROL_NAMESPACE}" rollout status deployment net-gateway-api-controller || return 1

echo ">> Bringing up Istio"
curl -sL https://istio.io/downloadIstioctl | sh -
$HOME/.istioctl/bin/istioctl install -y
wait_until_service_has_external_http_address istio-system istio-ingressgateway
}

# Deploy artifacts specific for a suported vendor implementation.
# Parameters: $1 - name of vendor implementation.
function deploy() {
local vendor=$1
echo ">> Deploy Gateway API resources"
kubectl apply -f ./third_party/istio/gateway/

wait_until_service_has_external_http_address istio-system istio-ingressgateway
kubectl apply -f ./third_party/"$vendor"/gateway/
}

# Add function call to trap
Expand Down
Loading

0 comments on commit d2a24b4

Please sign in to comment.