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

include sessionCookieEnabled when syncing routes #121

Merged
merged 20 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
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
6 changes: 4 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.11"
- name: Install deps
run: |
sudo apt update
sudo apt install -y pipx git
pipx ensurepath
pipx install poetry

- name: Test coverage for Gateway API
run: |
export PATH=/root/.local/bin:$PATH
cd microservices/gatewayApi
poetry install --no-root
poetry env use 3.11
poetry install --no-root --no-cache
ENV=test GITHASH=11223344 \
poetry run coverage run --branch -m pytest -s -v
poetry run coverage xml
Expand Down
2 changes: 1 addition & 1 deletion microservices/gatewayApi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# && go mod download \
# && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o deck \
# -ldflags "-s -w -X github.com/kong/deck/cmd.VERSION=$TAG -X github.com/kong/deck/cmd.COMMIT=$COMMIT"
FROM python:3.9-alpine3.18
FROM python:3.11-alpine3.20

RUN mkdir /.kube

Expand Down
931 changes: 462 additions & 469 deletions microservices/gatewayApi/poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions microservices/gatewayApi/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "Gateway API for multi-tenant configuration on Kong API Gateway"
authors = []

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.11"
werkzeug = "2.2.2"
ply = "3.10"
cryptography = "38.0.4"
Expand All @@ -23,7 +23,7 @@ gevent = "22.10.2"
# greenlet = "2.0.2"
gunicorn = "20.1.0"
python-keycloak = "0.22.0"
requests = "2.31.0"
requests = "^2.32"
flask-jwt-simple = "0.0.3"

[tool.poetry.dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion microservices/gatewayJobScheduler/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def transform_data_by_ns(data):

logger.debug("%s - %s" % (namespace, ns_attr_dict[namespace].get('perm-data-plane', [''])))

# check if namespace has data plane attribute
# check if namespace has data plane attribute and needs to be synced
if ns_attr_dict[namespace].get('perm-data-plane', [''])[0] == os.getenv('DATA_PLANE'):
session_cookie_enabled = False
if 'aps.route.session.cookie.enabled' in route_obj['tags']:
Expand Down
7 changes: 4 additions & 3 deletions microservices/kubeApi/routers/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ async def verify_and_create_routes(namespace: str, request: Request):
"name": route["metadata"]["name"],
"selectTag": route["metadata"]["labels"]["aps-select-tag"],
"host": route["spec"]["host"],
"dataPlane": route["spec"]["to"]["name"]
"dataPlane": route["spec"]["to"]["name"],
"sessionCookieEnabled": True if route["metadata"]["labels"].get("aps-template-version") == "v1" else False
}
)

insert_batch = [x for x in source_routes if not in_list(x, existing_routes)]
delete_batch = [y for y in existing_routes if not in_list(y, source_routes)]

logger.debug("insert batch: " + str(insert_batch))

logger.debug("delete batch: " + str(delete_batch))
Expand Down Expand Up @@ -244,4 +245,4 @@ def in_list (match, list):
return False

def build_ref(v):
return "%s%s%s%s" % (v['name'], v['selectTag'], v['host'], v['dataPlane'])
return "%s%s%s%s%s" % (v['name'], v['selectTag'], v['host'], v['dataPlane'], v['sessionCookieEnabled'])
6 changes: 4 additions & 2 deletions microservices/kubeApi/tests/routers/test_bulk_sync.py
ikethecoder marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def test_bulk_sync(client):
"metadata": {
"name": "wild-ns-example",
"labels": {
"aps-select-tag": "ns.EXAMPLE-NS"
"aps-select-tag": "ns.EXAMPLE-NS",
"aps-template-version": "v2"
}
},
"spec": {
Expand All @@ -28,7 +29,8 @@ def test_bulk_sync(client):
"name": "wild-ns-example",
"selectTag": "ns.EXAMPLE-NS",
"dataPlane": "data-plane-1",
"host": "abc.api.gov.bc.ca"
"host": "abc.api.gov.bc.ca",
"sessionCookieEnabled": False
}]
response = client.post('/namespaces/examplens/routes/sync', json=data)
assert response.status_code == 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def test_bulk_sync_new_route(client):
"name": "wild-ns-example",
"selectTag": "ns.EXAMPLE-NS",
"dataPlane": "data-plane-1",
"host": "abc.api.gov.bc.ca"
"host": "abc.api.gov.bc.ca",
"sessionCookieEnabled": False
}]
response = client.post('/namespaces/examplens/routes/sync', json=data)
assert response.status_code == 200
Expand Down
ikethecoder marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from unittest import mock

def test_bulk_sync(client):
with mock.patch("routers.routes.get_gwa_ocp_routes") as call:
call.return_value = [{
"metadata": {
"name": "wild-ns-example",
"labels": {
"aps-select-tag": "ns.EXAMPLE-NS",
"aps-template-version": "v1"
}
},
"spec": {
"host": "abc.api.gov.bc.ca",
"to": {
"name": "data-plane-1"
}
}
}]


with mock.patch("routers.routes.prepare_apply_routes") as call_apply:
call_apply.return_value = 0

with mock.patch("routers.routes.apply_routes") as call_mismatch_routes:
call_mismatch_routes.return_value = None

data = [{
"name": "wild-ns-example",
"selectTag": "ns.EXAMPLE-NS",
"dataPlane": "data-plane-1",
"host": "abc.api.gov.bc.ca",
"sessionCookieEnabled": True
}]
response = client.post('/namespaces/examplens/routes/sync', json=data)
assert response.status_code == 200
assert response.json()['message'] == 'synced'
Loading