Skip to content

Commit

Permalink
Merge pull request #114 from bcgov/dev
Browse files Browse the repository at this point in the history
Feature route template override
  • Loading branch information
ikethecoder authored May 21, 2024
2 parents f1b7c16 + 8eaa190 commit cf8a1aa
Show file tree
Hide file tree
Showing 72 changed files with 4,056 additions and 1,878 deletions.
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

0 comments on commit cf8a1aa

Please sign in to comment.