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

Feature/route template override #113

Merged
merged 57 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
a64a972
add special route tag
ikethecoder May 6, 2024
b9f676b
upd sonar scanning
ikethecoder May 6, 2024
2556ffb
upd sonar scanning
ikethecoder May 6, 2024
773bf4f
tests for kubeapi
ikethecoder May 8, 2024
56d7159
upg poetry in dockerfile
ikethecoder May 8, 2024
74c3370
fix missing func
ikethecoder May 8, 2024
2aaa08a
upgd python for kube api
ikethecoder May 8, 2024
11828a0
try getting coverage to work in sonar
ikethecoder May 8, 2024
0811513
try getting coverage to work in sonar
ikethecoder May 8, 2024
53ac1f3
try getting coverage to work upd sources
ikethecoder May 8, 2024
5b14181
try getting coverage to work upd sources
ikethecoder May 8, 2024
4b6e621
try getting coverage to work upd sources
ikethecoder May 8, 2024
a56b7af
try getting coverage to work upd sources
ikethecoder May 8, 2024
3f4ccc2
try getting coverage to work upd sources
ikethecoder May 8, 2024
c0c7dc6
fix schedule route sync
ikethecoder May 8, 2024
30e16a4
fix schedule route sync
ikethecoder May 8, 2024
a3e8177
move where coverage relative path
ikethecoder May 8, 2024
41e54bd
move where coverage relative path
ikethecoder May 8, 2024
e6ab803
tweak coverage
ikethecoder May 8, 2024
7a32f83
tweak coverage
ikethecoder May 8, 2024
c0c9d1d
tweak coverage
ikethecoder May 8, 2024
22f002a
tweak coverage
ikethecoder May 8, 2024
705bc92
getting coverage to work
ikethecoder May 8, 2024
6345b41
getting coverage to work
ikethecoder May 8, 2024
7552ba5
getting coverage to work
ikethecoder May 8, 2024
07295c8
getting coverage to work
ikethecoder May 8, 2024
51ccfb3
move cov to setup python
ikethecoder May 8, 2024
900abf6
move cov to setup python
ikethecoder May 9, 2024
8cc5018
move cov to setup python
ikethecoder May 9, 2024
5f7f5c2
move cov to setup python
ikethecoder May 9, 2024
2b6c479
another attempt for coverage
ikethecoder May 9, 2024
a3459ce
separate by module
ikethecoder May 9, 2024
2373db7
coverage
ikethecoder May 9, 2024
4169b09
coverage
ikethecoder May 9, 2024
ea9f865
coverage
ikethecoder May 9, 2024
5e70870
coverage
ikethecoder May 9, 2024
c388913
upd coverage reporting
ikethecoder May 9, 2024
90430fd
some code cleanup
ikethecoder May 9, 2024
787a9cc
omit tests from coverage
ikethecoder May 9, 2024
092badd
move gwa-api to using poetry
ikethecoder May 9, 2024
a7eda09
upd sonarcube
ikethecoder May 9, 2024
795e187
add coverage for gateway api
ikethecoder May 21, 2024
548cb8d
add coverage for gateway api
ikethecoder May 21, 2024
4da2829
add coverage for gateway api
ikethecoder May 21, 2024
f21d328
upd gateway tests
ikethecoder May 21, 2024
9a5d0bb
upd tests for gw
ikethecoder May 21, 2024
51aca31
include exclusions
ikethecoder May 21, 2024
70a6666
upd readme
ikethecoder May 21, 2024
806b69e
upd readme
ikethecoder May 21, 2024
44f8ba1
fix the bulk sync api spec
ikethecoder May 21, 2024
3431b2f
fix tests for kube api
ikethecoder May 21, 2024
a2364d1
resolve sonar issues
ikethecoder May 21, 2024
8234a9a
add unit tests for scheduler
ikethecoder May 21, 2024
91b2faa
add unit tests for ocp routes
ikethecoder May 21, 2024
8148c98
add unit test for resourceset
ikethecoder May 21, 2024
419978d
upd readme
ikethecoder May 21, 2024
4d17c48
upd master workflow
ikethecoder May 21, 2024
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
36 changes: 36 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,42 @@ jobs:
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- 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
ENV=test GITHASH=11223344 \
poetry run coverage run --branch -m pytest -s -v
poetry run coverage xml

- name: Test coverage for Scheduler API
run: |
export PATH=/root/.local/bin:$PATH
cd microservices/gatewayJobScheduler
poetry install --no-root
SYNC_INTERVAL=1000 \
DATA_PLANE=test-dp \
poetry run coverage run --branch -m pytest -s -v
poetry run coverage xml

- name: Test coverage for Kube API
run: |
export PATH=/root/.local/bin:$PATH
cd microservices/kubeApi
poetry install --no-root
ACCESS_USER=kubeuser ACCESS_SECRET=s3cret \
poetry run coverage run --branch -m pytest -s -v
poetry run coverage xml

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@ jobs:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: "3.12"
- 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
ENV=test GITHASH=11223344 \
poetry run coverage run --branch -m pytest -s -v
poetry run coverage xml

- name: Test coverage for Scheduler API
run: |
export PATH=/root/.local/bin:$PATH
cd microservices/gatewayJobScheduler
poetry install --no-root
SYNC_INTERVAL=1000 \
DATA_PLANE=test-dp \
poetry run coverage run --branch -m pytest -s -v
poetry run coverage xml

- name: Test coverage for Kube API
run: |
export PATH=/root/.local/bin:$PATH
cd microservices/kubeApi
poetry install --no-root
ACCESS_USER=kubeuser ACCESS_SECRET=s3cret \
poetry run coverage run --branch -m pytest -s -v
poetry run coverage xml

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# GWA APIs
# Gateway Administration (GWA) Microservice APIs

<img src="https://github.com/bcgov/gwa-api/workflows/Build/badge.svg"></img>
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gwa-api&metric=alert_status)](https://sonarcloud.io/dashboard?id=gwa-api)
[![img](https://img.shields.io/badge/Lifecycle-Stable-97ca00)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![Lifecycle:Stable](https://img.shields.io/badge/Lifecycle-Stable-97ca00?style=for-the-badge)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/bcgov/gwa-api/master.yml?branch=master&style=for-the-badge)](https://github.com/bcgov/api-services-portal/actions/workflows/ci-build-deploy.yaml)
[![Coverage](https://img.shields.io/sonar/coverage/gwa-api/dev?server=https%3A%2F%2Fsonarcloud.io&style=for-the-badge)](https://sonarcloud.io/summary/new_code?id=gwa-api&branch=feature%2Froute-template-override)
![GitHub](https://img.shields.io/github/license/bcgov/gwa-api?style=for-the-badge)
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/bcgov/gwa-api?label=release&style=for-the-badge)

For self-service of APIs, a set of microservices are used to coordinate updates by the providers of APIs.

Expand Down
2 changes: 1 addition & 1 deletion microservices/gatewayApi/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ venv.bak/
# mypy
.mypy_cache/

config/*.json
config/default.json

LOCAL.md
_tmp
18 changes: 13 additions & 5 deletions microservices/gatewayApi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +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.8.15-alpine3.16
FROM python:3.9-alpine3.18

RUN mkdir /.kube

Expand All @@ -31,9 +30,18 @@ RUN curl -sL https://github.com/Kong/deck/releases/download/v1.27.1/deck_1.27.1_
tar -xf deck.tar.gz -C /tmp && \
cp /tmp/deck /usr/local/bin/deck127

COPY requirements.txt requirements.txt

RUN pip install -r requirements.txt
RUN python -m pip install --upgrade pip
# FIX: No module named 'urllib3.packages.six'
RUN pip uninstall urllib3 && pip install urllib3
RUN cd /tmp && \
curl -sSL https://install.python-poetry.org > get-poetry.py && \
POETRY_HOME=/opt/poetry python get-poetry.py --version 1.8.2 && \
cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
poetry config virtualenvs.create false
COPY pyproject.toml /tmp/
COPY poetry.lock /tmp/
RUN cd /tmp && poetry install --no-root --no-dev

COPY . .

Expand Down
22 changes: 11 additions & 11 deletions microservices/gatewayApi/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GWA Kong API

## Installation
## Getting Started

Install requires access to the Kong Admin API.

Expand Down Expand Up @@ -65,25 +65,25 @@ Replace the configuration values as necessary and LOCALPORT with the local port

Go to: http://localhost:2000/docs/

## Helm

### Helm Install (Kubernetes)
### Helm Install

```sh
helm upgrade --install gwa-kong-api --namespace ocwa bcgov/generic-api
```

## Test
### Development

Locally running:

```sh
pip install '.[test]'
ENVIRONMENT=test pytest --verbose
uvicorn wsgi:app --host 0.0.0.0 --port 8080 --reload
```

Run with coverage support. The report will be generated in htmlcov/index.html.
Testing:

```sh
coverage run -m pytest
coverage report
coverage html
ENV=test GITHASH=11223344 \
poetry run coverage run --branch -m pytest -s

coverage xml
```
2 changes: 0 additions & 2 deletions microservices/gatewayApi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import v1.v1 as v1
import v2.v2 as v2
import v3.v3 as v3

def create_app(test_config=None):

Expand Down Expand Up @@ -44,7 +43,6 @@ def create_app(test_config=None):
##Routes##
v1.Register(app)
v2.Register(app)
v3.Register(app)
Compress(app)

@app.before_request
Expand Down
30 changes: 30 additions & 0 deletions microservices/gatewayApi/clients/ocp_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,33 @@ def get_host_list(rootPath):

host_list.sort()
return host_list


def get_route_overrides(root_path, override_tag):

host_list = []

for x in os.walk(root_path):
for file in x[2]:
if file not in files_to_ignore:
full_path = "%s/%s" % (x[0],file)

stream = open(full_path, 'r')
data = yaml.load(stream, Loader=yaml.SafeLoader)

eval_services(host_list, override_tag, data)

host_list.sort()
return host_list


def eval_services(host_list, override_tag, data):
if data is not None and 'services' in data:
for service in data['services']:
if 'routes' in service:
for route in service['routes']:
if 'hosts' in route:
if override_tag in route['tags']:
for host in route['hosts']:
if host not in host_list:
host_list.append(host)
28 changes: 28 additions & 0 deletions microservices/gatewayApi/config/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"logLevel": "DEBUG",
"defaultDataPlane": "test-default-dp",
"kongAdminUrl": "http://kong",
"portal": {
"url": "http://portal"
},
"protectedKubeNamespaces": "[\"platform\"]",
"plugins": {
"rate_limiting": {
"redis_host": "redishost",
"redis_password": "redispassword"
}
},
"hostTransformation": {
"enabled": false
},
"data_planes": {
"test-default-dp": {
"kube-api": "http://kube-api",
"kube-ns": "abcd-1234"
}
},
"kubeApiCreds": {
"kubeApiPass": "password",
"kubeApiUser": "username"
}
}
Loading
Loading