Skip to content

Commit

Permalink
Refactor tests + improve docs + revert config dir
Browse files Browse the repository at this point in the history
- Reverted:
    - third_party/gateway-api/ -> config/
- Refactored out test configuration for different vendor into a common setup file
- Improved docs for installation (README) (closes knative-extensions#292) and for development/testing (DEVELOPMENT).
  • Loading branch information
Carlisia Thompson authored Jul 3, 2022
1 parent 1de3836 commit d988245
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 288 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kind-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
set -o pipefail
# Build and Publish our containers to the docker daemon (including test assets)
ko resolve -f test/config/ -f third_party/gateway-api/ | kubectl apply -f -
ko resolve -f test/config/ -f config/ | kubectl apply -f -
- name: Upload Test Images
run: |
Expand Down
200 changes: 48 additions & 152 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,184 +1,80 @@
# 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

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)

Before submitting a PR, see also [CONTRIBUTING.md](./CONTRIBUTING.md).

### Requirements

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
## Notes
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.

#### Prepare test resources such as namespaces
Versions to be installed are listed in [`hack/test-env.sh`](hack/test-env.sh).

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

#### Load tested environment versions

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

#### Install Gateway API CRDs
Tests are currently wip. Please see [README#tests](README.md#tests)

```
kubectl apply -f third_party/gateway-api/00-crds.yaml
```

#### Deploy Istio

Run the following command to install Istio:
## Requirements
1. A running cluster
2. [Knative serving installed](README.md#install-knative-serving)
3. [`ko`](https://github.com/google/ko) (for development and testing)
4. [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/) (for managing development environments)
5. [`bash`](https://www.gnu.org/software/bash/) v4 or later. On macOS the default bash is too old, you can use [Homebrew](https://brew.sh) to install a later version.

__NOTE__ You can find the Istio version to be installed in `./hack/test-env.sh`.
## Environment
To start your environment you'll need to set `KO_DOCKER_REPO`: The repository to which developer/test images should be pushed. Ex:

```shell
curl -sL https://istio.io/downloadIstioctl | sh -
$HOME/.istioctl/bin/istioctl install -y
export KO_DOCKER_REPO='gcr.io/my-gcloud-project-id'
```

#### Deploy GatewayClass and Gateway
### Notes
- If you are using Docker Hub to store your images your `KO_DOCKER_REPO` variable should be `docker.io/<username>`.
- Currently Docker Hub doesn't let you create subdirs under your username.
- You'll need to be authenticated with your `KO_DOCKER_REPO` before pushing images.
- Google Container Registry: `gcloud auth configure-docker`
- Docker Hub: `docker login`

```
kubectl apply -f ./third_party/istio/gateway/
```
## Building the test images
NOTE: this is only required when you run conformance/e2e tests locally with `go test` commands, and may be required periodically.

#### Execute tests
The [`upload-test-images.sh`](test/upload-test-images.sh) script can be used to build and push the test images used by the conformance and e2e tests.

```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}') )
To run the script for all end to end test images:

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

### Test with Contour
## Tests
### Conformance
#### Istio
`./test/kind-conformance-istio.sh`

#### Prepare test resources such as namespaces
#### Contour
`./test/kind-conformance-contour.sh`

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

#### Load tested environment versions

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

#### Install Gateway API CRDs
### e2e
Calling a script without arguments will create a new cluster in your current GCP project (assuming you have one) and run the tests against it.

This step is not necessary for Contour as contour operator installs Gateway API
CRDs.
Calling a script with `--run-tests` and the variable `KO_DOCKER_REPO` set will immediately start the tests against the cluster currently configured for `kubectl`.

#### Deploy Contour
#### Istio
`./test/kind-e2e-istio.sh`

Run the following command to install Contour and its operator.
#### Contour
`./test/kind-e2e-contour.sh`

__NOTE__ You can find the Contour version to be installed in `./hack/test-env.sh`.
## Adding new tests
1) To add a new test for a new vendor/implementation, add the corresponding bash script file(s) with the following header:

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

#### Deploy GatewayClass and Gateway
set -euo pipefail

```
ko resolve -f ./third_party/contour/gateway/gateway-external.yaml | \
sed 's/LoadBalancerService/NodePortService/g' | \
kubectl apply -f -
source "$(dirname $0)"/setup-and-deploy.sh

ko resolve -f ./third_party/contour/gateway/gateway-internal.yaml | \
kubectl apply -f -
deploy_new_vendor
```

#### Execute test

```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}') )

go test -v -tags=e2e -count=1 ./test/conformance/gateway-api/ -run "TestIngressConformance/hosts/basics" \
--ingressClass=contour \
--ingressendpoint="${IPS[0]}"
```
2) Add a new function to the file [`setup-and-deploy.sh`](test/setup-and-deploy.sh) and name it `function deploy_new_vendor()`.

Some tests are still not available. Please see
https://github.com/knative-sandbox/net-gateway-api/issues/36.
3) Add the configuration specific to this vendor inside the `deploy_new_vendor()` function.
97 changes: 61 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,41 @@
# Knative net-gateway-api

**[This component is ALPHA](https://github.com/knative/community/tree/main/mechanics/MATURITY-LEVELS.md)**

[![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)

Versions to be installed are listed in [`hack/test-env.sh`](hack/test-env.sh).
---
## Requirements
1. A Kind cluster
1. Knative serving installed
2. [`ko`](https://github.com/google/ko) (for installing the net-gateway-api)
3. [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
4. `export KO_DOCKER_REPO=kind.local`

## Getting started

- 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 third_party/gateway-api/
```

- 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 @@ -60,7 +44,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 @@ -69,8 +54,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 -
apiVersion: serving.knative.dev/v1
Expand All @@ -88,15 +72,56 @@ spec:
EOF
```

- (OPTIONAL) For testing purposes, you can use port-forwarding to make requests
to ingress from your machine:
### Install net-gateway-api
```bash
ko apply -f config/
```

### Load tested environment versions
```
source ./hack/test-env.sh
```

### Install a supported implementation
#### Istio
```bash
# gateway-api CRD must be installed before Istio.
echo ">> Installing Gateway API CRDs"
kubectl apply -f config/100-gateway-api.yaml

echo ">> Bringing up Istio"
curl -sL https://istio.io/downloadIstioctl | sh -
"$HOME"/.istioctl/bin/istioctl install -y --set values.gateways.istio-ingressgateway.type=NodePort --set values.global.proxy.clusterDomain="${CLUSTER_SUFFIX}"

echo ">> Deploy Gateway API resources"
kubectl apply -f ./third_party/istio/gateway/
```

#### Contour
```bash
echo ">> Bringing up Contour"
kubectl apply -f "https://raw.githubusercontent.com/projectcontour/contour-operator/${CONTOUR_VERSION}/examples/operator/operator.yaml"

# wait for operator deployment to be Available
kubectl wait deploy --for=condition=Available --timeout=120s -n "contour-operator" -l '!job-name'

echo ">> Deploy Gateway API resources"
ko resolve -f ./third_party/contour/gateway/ | \
sed 's/LoadBalancerService/NodePortService/g' | \
kubectl apply -f -
```

### (OPTIONAL) For testing purpose (Istio)
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d988245

Please sign in to comment.