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

feat: add wasm filter-chain entity support #987

Merged
merged 11 commits into from
Jun 14, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions .ci/clean_kong.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -euo pipefail

source ./.ci/lib.sh

cleanup() {
local -r resource=${1?resource type required}
shift

docker "$resource" ls "$@" \
--filter "label=$DOCKER_LABEL" \
--quiet \
| while read -r id; do
docker "$resource" rm \
--force \
"$id"
done
}

cleanup container --all
cleanup volume
cleanup network
86 changes: 86 additions & 0 deletions .ci/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
set -euo pipefail
flrgh marked this conversation as resolved.
Show resolved Hide resolved

readonly NETWORK_NAME=deck-test
readonly DOCKER_LABEL=com.konghq.test.deck=1
readonly KONG_PG_HOST=kong-postgres
readonly KONG_PG_USER=kong
readonly KONG_PG_DATABASE=kong
readonly KONG_PG_PASSWORD=kong
readonly KONG_PG_PORT=5432

readonly DOCKER_ARGS=(
--label "$DOCKER_LABEL"
--network "$NETWORK_NAME"
--volume "$PWD/tests/integration/testdata/filters:/filters:ro"
-e "KONG_DATABASE=postgres"
-e "KONG_PG_HOST=$KONG_PG_HOST"
-e "KONG_PG_PORT=$KONG_PG_PORT"
-e "KONG_PG_USER=$KONG_PG_USER"
-e "KONG_PG_DATABASE=$KONG_PG_DATABASE"
-e "KONG_PG_PASSWORD=$KONG_PG_PASSWORD"
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout"
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout"
-e "KONG_PROXY_ERROR_LOG=/dev/stderr"
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr"
-e "KONG_LOG_LEVEL=${KONG_LOG_LEVEL:-notice}"
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database"
-e "KONG_WASM_FILTERS_PATH=/filters"
-e "KONG_WASM=on"
)

waitContainer() {
local -r container=$1
shift

for _ in {1..100}; do
echo "waiting for $container"
if docker exec \
--user root \
"$container" \
"$@"
then
return
fi
sleep 0.2
done

echo "FATAL: failed waiting for $container"
exit 1
}

initNetwork() {
docker network create \
--label "$DOCKER_LABEL" \
"$NETWORK_NAME"
}

initDb() {
docker run \
--rm \
--detach \
--name "$KONG_PG_HOST" \
--label "$DOCKER_LABEL" \
--network $NETWORK_NAME \
-p "${KONG_PG_PORT}:${KONG_PG_PORT}" \
-e "POSTGRES_USER=$KONG_PG_USER" \
-e "POSTGRES_DB=$KONG_PG_DATABASE" \
-e "POSTGRES_PASSWORD=$KONG_PG_PASSWORD" \
postgres:9.6

waitContainer "$KONG_PG_HOST" pg_isready
}

initMigrations() {
local -r image=$1
shift

docker run \
--rm \
"${DOCKER_ARGS[@]}" \
"$@" \
"$image" \
kong migrations bootstrap \
--yes \
--force \
--db-timeout 30
}
77 changes: 19 additions & 58 deletions .ci/setup_kong.sh
Original file line number Diff line number Diff line change
@@ -1,65 +1,26 @@
#!/bin/bash

set -e
set -euo pipefail

KONG_IMAGE=${KONG_IMAGE:-kong}
NETWORK_NAME=deck-test
source ./.ci/lib.sh

PG_CONTAINER_NAME=pg
DATABASE_USER=kong
DATABASE_NAME=kong
KONG_DB_PASSWORD=kong
KONG_PG_HOST=pg
readonly KONG_IMAGE=${KONG_IMAGE:-kong}
readonly GATEWAY_CONTAINER_NAME=kong

GATEWAY_CONTAINER_NAME=kong

waitContainer() {
for try in {1..100}; do
echo "waiting for $1"
docker exec --user root $2 $3 && break;
sleep 0.2
done
}

# create docker network
docker network create $NETWORK_NAME

# Start a PostgreSQL container
docker run --rm -d --name $PG_CONTAINER_NAME \
--network=$NETWORK_NAME \
-p 5432:5432 \
-e "POSTGRES_USER=$DATABASE_USER" \
-e "POSTGRES_DB=$DATABASE_NAME" \
-e "POSTGRES_PASSWORD=$KONG_DB_PASSWORD" \
postgres:9.6

waitContainer "PostGres" $PG_CONTAINER_NAME pg_isready

# Prepare the Kong database
docker run --rm --network=$NETWORK_NAME \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=$KONG_PG_HOST" \
-e "KONG_PG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_PASSWORD=$KONG_DB_PASSWORD" \
$KONG_IMAGE kong migrations bootstrap
initNetwork
initDb
initMigrations "$KONG_IMAGE"

# Start Kong Gateway
docker run -d --name $GATEWAY_CONTAINER_NAME \
--network=$NETWORK_NAME \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=$KONG_PG_HOST" \
-e "KONG_PG_USER=$DATABASE_USER" \
-e "KONG_PG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-p 8000:8000 \
-p 8443:8443 \
-p 127.0.0.1:8001:8001 \
-p 127.0.0.1:8444:8444 \
$KONG_IMAGE

waitContainer "Kong" $GATEWAY_CONTAINER_NAME "kong health"
docker run \
--detach \
--name "$GATEWAY_CONTAINER_NAME" \
"${DOCKER_ARGS[@]}" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-p 8000:8000 \
-p 8443:8443 \
-p 127.0.0.1:8001:8001 \
-p 127.0.0.1:8444:8444 \
"$KONG_IMAGE"

waitContainer "$GATEWAY_CONTAINER_NAME" kong health
96 changes: 29 additions & 67 deletions .ci/setup_kong_ee.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

set -e
set -euo pipefail

source ./.ci/lib.sh

MY_SECRET_CERT='''-----BEGIN CERTIFICATE-----
MIIEczCCAlugAwIBAgIJAMw8/GAiHIFBMA0GCSqGSIb3DQEBCwUAMDYxCzAJBgNV
Expand Down Expand Up @@ -57,73 +59,33 @@ KlBs7O9y+fc4AIIn6JD+9tymB1TWEn1B+3Vv6jmtzbztuCQTbJ6rTT3CFcE6TdyJ
8rYuG3/p2VkcG29TWbQARtj5ewv9p5QNfaecUzN+tps89YzawWQBanwI
-----END RSA PRIVATE KEY-----'''

KONG_IMAGE=${KONG_IMAGE:-kong/kong-gateway}
NETWORK_NAME=deck-test

PG_CONTAINER_NAME=pg
DATABASE_USER=kong
DATABASE_NAME=kong
KONG_DB_PASSWORD=kong
KONG_PG_HOST=pg

GATEWAY_CONTAINER_NAME=kong

waitContainer() {
for try in {1..100}; do
echo "waiting for $1"
docker exec --user root $2 $3 && break;
sleep 0.2
done
}

# create docker network
docker network create $NETWORK_NAME

# Start a PostgreSQL container
docker run --rm -d --name $PG_CONTAINER_NAME \
--network=$NETWORK_NAME \
-p 5432:5432 \
-e "POSTGRES_USER=$DATABASE_USER" \
-e "POSTGRES_DB=$DATABASE_NAME" \
-e "POSTGRES_PASSWORD=$KONG_DB_PASSWORD" \
postgres:9.6

waitContainer "PostGres" $PG_CONTAINER_NAME pg_isready
readonly KONG_IMAGE=${KONG_IMAGE:-kong/kong-gateway}
readonly GATEWAY_CONTAINER_NAME=kong

# Prepare the Kong database
docker run --rm --network=$NETWORK_NAME \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=$KONG_PG_HOST" \
-e "KONG_PG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_LICENSE_DATA=$KONG_LICENSE_DATA" \
$KONG_IMAGE kong migrations bootstrap
initNetwork
initDb
initMigrations "${KONG_IMAGE}" \
-e "KONG_LICENSE_DATA=${KONG_LICENSE_DATA}"

# Start Kong Gateway EE
docker run -d --name $GATEWAY_CONTAINER_NAME \
--network=$NETWORK_NAME \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=$KONG_PG_HOST" \
-e "KONG_PG_USER=$DATABASE_USER" \
-e "KONG_PG_PASSWORD=$KONG_DB_PASSWORD" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001" \
-e "KONG_PORTAL_GUI_URI=127.0.0.1:8003" \
-e "KONG_ADMIN_GUI_URL=http://127.0.0.1:8002" \
-e "KONG_LICENSE_DATA=$KONG_LICENSE_DATA" \
-e "MY_SECRET_CERT=$MY_SECRET_CERT" \
-e "MY_SECRET_KEY=$MY_SECRET_KEY" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
-p 8002:8002 \
-p 8445:8445 \
-p 8003:8003 \
-p 8004:8004 \
$KONG_IMAGE
docker run \
--detach \
--name $GATEWAY_CONTAINER_NAME \
"${DOCKER_ARGS[@]}" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001" \
-e "KONG_PORTAL_GUI_URI=127.0.0.1:8003" \
-e "KONG_ADMIN_GUI_URL=http://127.0.0.1:8002" \
-e "KONG_LICENSE_DATA=$KONG_LICENSE_DATA" \
-e "MY_SECRET_CERT=$MY_SECRET_CERT" \
-e "MY_SECRET_KEY=$MY_SECRET_KEY" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
-p 8002:8002 \
-p 8445:8445 \
-p 8003:8003 \
-p 8004:8004 \
"$KONG_IMAGE"

waitContainer "Kong" $GATEWAY_CONTAINER_NAME "kong health"
waitContainer "${GATEWAY_CONTAINER_NAME}" kong health
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- 'kong:3.4'
- 'kong:3.5'
- 'kong:3.6'
- 'kong/kong:master-alpine'
- 'kong/kong:master'
env:
KONG_ANONYMOUS_REPORTS: "off"
KONG_IMAGE: ${{ matrix.kong_image }}
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ test-integration:
go test -v -count=1 -tags=integration \
-race \
./tests/integration/...

.PHONY: clean
clean:
bash .ci/clean_kong.sh
1 change: 1 addition & 0 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ func containsProxyConfiguration(content reconcilerUtils.KongRawState) bool {
return len(content.Services) != 0 ||
len(content.Routes) != 0 ||
len(content.Plugins) != 0 ||
len(content.FilterChains) != 0 ||
len(content.Upstreams) != 0 ||
len(content.Certificates) != 0 ||
len(content.CACertificates) != 0 ||
Expand Down
3 changes: 3 additions & 0 deletions cmd/gateway_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,8 @@ func ensureGetAllMethods() error {
if _, err := reconcilerUtils.CallGetAll(dummyEmptyState.RBACRoles); err != nil {
return err
}
if _, err := reconcilerUtils.CallGetAll(dummyEmptyState.FilterChains); err != nil {
return err
}
return nil
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/fatih/color v1.15.0
github.com/google/go-cmp v0.6.0
github.com/kong/go-apiops v0.1.33
github.com/kong/go-database-reconciler v1.12.1
github.com/kong/go-database-reconciler v1.12.2
github.com/kong/go-kong v0.55.0
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -40,7 +40,7 @@ require (
github.com/pb33f/doctor v0.0.6 // indirect
github.com/pb33f/libopenapi v0.16.1 // indirect
github.com/pb33f/libopenapi-validator v0.0.49 // indirect
github.com/shirou/gopsutil/v3 v3.24.4 // indirect
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
github.com/ssgelm/cookiejarparser v1.0.1 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
Expand Down Expand Up @@ -131,8 +131,8 @@ require (
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down