Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Add conformance testing workflow for GitHub Actions #139

Merged
merged 22 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6fd25a8
Add conformance testing workflow for GitHub Actions
nathancoleman Mar 31, 2022
43e63a7
Consolidate single commands onto one line
nathancoleman Mar 31, 2022
e3e0afb
Remove debugging command
nathancoleman Mar 31, 2022
385dbde
add schedule trigger
sarahalsmiller Apr 1, 2022
3009a6b
Adjust workflow triggers + job name
nathancoleman Apr 1, 2022
58820e8
add report status action
sarahalsmiller Apr 1, 2022
2c70bd4
Merge branch 'conformance-ci' of github.com:hashicorp/consul-api-gate…
sarahalsmiller Apr 1, 2022
6d1404a
comment out report status pending approvals
sarahalsmiller Apr 1, 2022
b8845de
fix dirty merge
sarahalsmiller Apr 1, 2022
7192c57
Update conformance testing README
nathancoleman Apr 1, 2022
56c41f9
Merge branch 'main' into conformance-ci
nathancoleman Apr 1, 2022
5a7b79f
Remove run script now that it's translated into actions workflow
nathancoleman Apr 1, 2022
cc16f7d
Comment docker build command in workflow
nathancoleman Apr 4, 2022
7070ab7
Remove unnecessary Consul config values
nathancoleman Apr 4, 2022
1cec51c
Move tmate tip to README, add TODO for webhook
nathancoleman Apr 4, 2022
a3724a3
Use consistent branch trigger pattern
nathancoleman Apr 4, 2022
f60a6a0
Run on pull requests with pr/run-conformance label
nathancoleman Apr 4, 2022
d68ec4a
Use correct actions context property for event type
nathancoleman Apr 4, 2022
54771c2
Remove connect-inject enable annotation in favor of config
nathancoleman Apr 4, 2022
45c165f
Update conformance testing README
nathancoleman Apr 4, 2022
e72ecf2
Check out repos side-by-side instead of nesting
nathancoleman Apr 4, 2022
d965fa5
Add labeling strategy to conformance testing README
nathancoleman Apr 4, 2022
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
111 changes: 111 additions & 0 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: conformance

on:
push:
branches:
- "*-conformance"
- "conformance-*"

schedule:
- cron: '0 0 * * *'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will run at midnight UTC every day


workflow_dispatch:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to kick off runs manually in the repo Actions tab if we choose

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be triggered manually on specific branches/PRs, or only on main?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep yep. Here's the blogpost I initially read about it



env:
GO_VERSION: "1.17"

jobs:
run-on-kind:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Goenv
uses: ./.github/actions/goenv
with:
go-version: ${{ env.GO_VERSION }}

- name: Create Kind cluster
uses: helm/kind-action@2a525709fd0874b75d7ae842d257981b0e0f557d
with:
cluster_name: "consul-api-gateway-test"
kubectl_version: "v1.21.0"

- name: Install MetalLB
run: |
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml
kubectl apply -f ./internal/testing/conformance/metallb-config.yaml
kubectl wait --for=condition=Ready --timeout=60s --namespace=metallb-system pods --all

- name: Build binary
env:
CGO_ENABLED: "0"
GOARCH: "amd64"
GOOS: "linux"
run: go build -o ./consul-api-gateway

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build Docker image
uses: docker/build-push-action@v2
with:
context: .
platforms: "linux/amd64"
file: "Dockerfile.local"
load: true
push: false
tags: "consul-api-gateway:test"

- name: Load Docker image into Kind
run: kind load docker-image consul-api-gateway:test --name consul-api-gateway-test

- name: Install Consul API Gateway CRDs
run: kubectl apply --kustomize="./config/crd"

- name: Clone consul-k8s
uses: actions/checkout@v2
with:
repository: "hashicorp/consul-k8s"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to run using the main branch of consul-k8s for now because of some fixes that haven't been released yet. Once those fixes are released, we can drop this installation from a clone.

path: "./internal/testing/conformance/consul-k8s"
fetch-depth: "1"

- name: Clone gateway-api
uses: actions/checkout@v2
with:
repository: "nathancoleman/gateway-api"
ref: "eventually-consistent-conformance"
Copy link
Member Author

@nathancoleman nathancoleman Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses my fork + branch of the gateway-api repo from kubernetes-sigs/gateway-api#1080.
Hoping that merges in the next week or so and we can update this to use kubernetes-sigs/gateway-api@master.

path: "./internal/testing/conformance/gateway-api"
fetch-depth: "1"

- name: Install Consul
working-directory: "./internal/testing/conformance"
run: |
helm install --values ./consul-config.yaml consul ./consul-k8s/charts/consul --create-namespace --namespace=consul
kubectl wait --for=condition=Ready --timeout=60s --namespace=consul pods --all

- name: Patch testing resources
working-directory: "./internal/testing/conformance"
run: |
cp kustomization.yaml proxydefaults.yaml ./gateway-api/conformance/
cd ./gateway-api/conformance/
kubectl kustomize ./ --output ./base/manifests.yaml

# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# timeout-minutes: 10

- name: Run tests
working-directory: "./internal/testing/conformance/gateway-api/conformance"
run: go test -v -timeout 10m ./ --gateway-class consul-api-gateway
# - name: Report Status
# if: always()
# uses: ravsamhq/notify-slack-action@v1
# with:
# status: ${{ job.status }}
# notify_when: 'failure'
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ refresh.yml
cover.out
demo-deployment
bin
pkg/bin
pkg/bin

# Repos cloned for conformance testing
internal/testing/conformance/consul-k8s/
internal/testing/conformance/gateway-api
4 changes: 2 additions & 2 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM alpine:3.13
FROM alpine:latest
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to match the default step in Dockerfile. I don't think there's a reason to be on an older version, but can pin this if we generally prefer keeping it pinned.


COPY ./consul-api-gateway /bin/consul-api-gateway
ENTRYPOINT ["/bin/consul-api-gateway"]
CMD ["version"]
CMD ["version"]
55 changes: 4 additions & 51 deletions internal/testing/conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,10 @@ need for these patches.
each `Deployment`'s template. They all use the same port.
- The Consul services default to a protocol of `tcp`; however, the testing framework uses `http`. To make this work, we create
a `ProxyDefaults` resource which sets the protocol to `http` globally.
- GitHub Actions' default hosted runner is not powerful enough to run all pods specified upstream in kind.
To cope with this, we reduce all `Deployments` to 1 replica.

## Status

The conformance tests cannot currently run in an automated fashion. They are not included in our CI yet.

Due to the controller not currently knowing when Consul/Envoy are ready after syncing in new routes, the route appears
"ready" to the conformance testing framework before the gateway can actually respond to requests for the route. The
framework then sends HTTP requests as soon as the route appears ready and the request is rejected with an error like
the following:

```log
Get "http://35.229.22.36": dial tcp 35.229.22.36:80: connect: connection refused
```

This doesn't mean we cannot run the conformance tests, they just have to be run manually, one at a time.
To run a particular conformance test, you need to:

1. Create a GKE cluster (or any other standard Kubernetes cluster) and install Consul + Consul API Gateway.
The [usage docs](https://www.consul.io/docs/api-gateway/api-gateway-usage#installation) explain how to do this.

2. clone the [kubernetes-sigs/gateway-api](https://github.com/kubernetes-sigs/gateway-api)
repo and copy our patches into the `conformance` subdirectory:

```shell
git clone --depth 1 git@github.com:kubernetes-sigs/gateway-api
cp kustomization.yaml proxydefaults.yaml gateway-api/conformance/
```

3. make your way into the `conformance` directory, then patch and install the base resources:

```shell
cd gateway-api/conformance/
kubectl kustomize ./ --output ./base/manifests.yaml
kubectl apply -f ./base/manifests.yaml --validate=false
```

4. install the test-specific resources (adjust name appropriately):

```shell
kubectl apply -f tests/httproute-matching.yaml
```

5. modify the last line of `conformance_test.go` that passes the list of tests to include only the test that you want to run:

```go
cSuite.Run(t, []suite.ConformanceTest{tests.HTTPRouteMatchingAcrossRoutes})
```

6. run the test:
```shell
go test ./ --gateway-class consul-api-gateway --cleanup=0
```

7. repeat steps 4-6 for other tests
The conformance tests are run nightly in GitHub Actions using the workflow [here](/.github/workflows/conformance.yml).
You may also run the workflow on demand from this repo's Actions tab or by following the branch naming conventions listed in the workflow.
20 changes: 20 additions & 0 deletions internal/testing/conformance/consul-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
global:
name: consul
datacenter: dc1
tls:
enabled: true
server:
replicas: 1
ui:
enabled: true
service:
type: NodePort
connectInject:
enabled: true
default: true
controller:
enabled: true
apiGateway:
enabled: true
logLevel: info
image: "consul-api-gateway:test"
7 changes: 7 additions & 0 deletions internal/testing/conformance/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ patches:
value: {'consul.hashicorp.com/connect-inject': 'true', 'consul.hashicorp.com/connect-service-port': '3000'}
target:
kind: Deployment
# We don't have enough resources in the GitHub-hosted Actions runner to support 2 replicas
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out kind runs out of CPU before all of the conformance testing resources can spin up. There's no easy option for increasing the size of the runner today. It sounds like the consul team is running into similar issues that we may need to figure out in the future if/when upstream adds more deployments.

- patch: |-
- op: replace
path: "/spec/replicas"
value: 1
target:
kind: Deployment
12 changes: 12 additions & 0 deletions internal/testing/conformance/metallb-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 172.18.255.200-172.18.255.250