diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index 22e22e1..fbe0e20 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -11,5 +11,18 @@
$ProjectFileDir$
+
+ postgresql
+ true
+ Kube Eng :: PostgreSQL
+ org.postgresql.Driver
+ jdbc:postgresql://localhost:5432/postgres
+
+
+
+
+
+ $ProjectFileDir$
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index be83902..aaa3def 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,5 +3,5 @@
-
+
\ No newline at end of file
diff --git a/.idea/mrmat-python-api-fastapi.iml b/.idea/mrmat-python-api-fastapi.iml
index 24ec1fd..674ba84 100644
--- a/.idea/mrmat-python-api-fastapi.iml
+++ b/.idea/mrmat-python-api-fastapi.iml
@@ -7,7 +7,7 @@
-
+
diff --git a/.idea/runConfigurations/run.xml b/.idea/runConfigurations/run.xml
index 028572a..98d83e2 100644
--- a/.idea/runConfigurations/run.xml
+++ b/.idea/runConfigurations/run.xml
@@ -5,6 +5,9 @@
+
+
+
diff --git a/Makefile b/Makefile
index 7578cfa..187aa14 100644
--- a/Makefile
+++ b/Makefile
@@ -5,9 +5,12 @@
GIT_SHA := $(shell git rev-parse --short HEAD)
VERSION ?= 0.0.0-dev0.${GIT_SHA}
PYTHON_VERSION := $(shell echo "${VERSION}" | sed -e 's/-dev0\./-dev0+/')
+WHEEL_VERSION := $(shell echo "${VERSION}" | sed -e 's/-dev0\./.dev0+/')
+
+ROOT_PATH := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
PYTHON_SOURCES := $(shell find src/mrmat_python_api_fastapi -name '*.py')
-PYTHON_TARGET := dist/mrmat_python_api_fastapi-${PYTHON_VERSION}-py3-none-any.whl
+PYTHON_TARGET := dist/mrmat_python_api_fastapi-${WHEEL_VERSION}-py3-none-any.whl
CONTAINER_SOURCES := $(shell find var/container)
HELM_SOURCES := $(shell find var/helm)
HELM_TARGET := dist/mrmat-python-api-fastapi-$(VERSION).tgz
@@ -31,16 +34,22 @@ container: $(PYTHON_TARGET) $(CONTAINER_SOURCES)
-f var/container/Dockerfile \
-t localhost:5001/mrmat-python-api-fastapi:$(VERSION) \
--build-arg MRMAT_VERSION=$(VERSION) \
- .
+ --build-arg WHEEL=$(PYTHON_TARGET) \
+ $(ROOT_PATH)
docker push localhost:5001/mrmat-python-api-fastapi:$(VERSION)
helm-install: $(HELM_TARGET)
+ kubectl create ns mpafastapi || true
+ kubectl label --overwrite ns mpafastapi istio-injection=true
helm upgrade \
mrmat-python-api-fastapi \
${HELM_TARGET} \
--install \
- --create-namespace \
- --namespace mrmat-python-api-fastapi
+ --force \
+ --namespace mpafastapi
+
+helm-uninstall:
+ helm delete -n mpafastapi mrmat-python-api-fastapi
clean:
rm -rf build dist
diff --git a/README.md b/README.md
index 2e615c5..99e2157 100644
--- a/README.md
+++ b/README.md
@@ -3,5 +3,5 @@
[](https://github.com/MrMatOrg/mrmat-python-api-fastapi/actions/workflows/build.yml)
-Boilerplate (and playground) for a code-first Python FastAPI API, with all the bells and whistles we've come to expect
+Boilerplate (and playground) for a code-first Python FastAPI API, with all the bells and whistles we've come to expect.
diff --git a/requirements.txt b/requirements.txt
index 7e66d3c..e4b4554 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,7 +1,32 @@
#
# Runtime requirements
-fastapi==0.115.11 # MIT
-sqlalchemy[asyncio]==2.0.40 # MIT
-uvicorn==0.34.0 # BSD 3-Clause
-pydantic==2.10.6 # MIT
+fastapi==0.115.11 # MIT
+sqlalchemy[asyncio]==2.0.40 # MIT
+uvicorn==0.34.0 # BSD 3-Clause
+pydantic==2.10.6 # MIT
+psycopg2-binary==2.9.10 # LGPL with exceptions
+
+prometheus-fastapi-instrumentator==7.1.0 # ISC
+
+# For zero-code-instrumentation
+# Check the requirements by using opentelemetry-bootstrap -a requirements
+opentelemetry-distro # Apache 2.0
+opentelemetry-exporter-otlp
+opentelemetry-instrumentation-asyncio==0.53b1
+opentelemetry-instrumentation-dbapi==0.53b1
+opentelemetry-instrumentation-logging==0.53b1
+opentelemetry-instrumentation-sqlite3==0.53b1
+opentelemetry-instrumentation-threading==0.53b1
+opentelemetry-instrumentation-urllib==0.53b1
+opentelemetry-instrumentation-wsgi==0.53b1
+opentelemetry-instrumentation-asgi==0.53b1
+opentelemetry-instrumentation-click==0.53b1
+opentelemetry-instrumentation-fastapi==0.53b1
+opentelemetry-instrumentation-grpc==0.53b1
+opentelemetry-instrumentation-httpx==0.53b1
+opentelemetry-instrumentation-requests==0.53b1
+opentelemetry-instrumentation-sqlalchemy==0.53b1
+opentelemetry-instrumentation-starlette==0.53b1
+opentelemetry-instrumentation-tortoiseorm==0.53b1
+opentelemetry-instrumentation-urllib3==0.53b1
diff --git a/src/mrmat_python_api_fastapi/__init__.py b/src/mrmat_python_api_fastapi/__init__.py
index 32dea2a..30ca700 100644
--- a/src/mrmat_python_api_fastapi/__init__.py
+++ b/src/mrmat_python_api_fastapi/__init__.py
@@ -19,10 +19,11 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+
from pydantic import BaseModel
from .config import Config
-app_config = Config.from_json_file()
+app_config = Config.from_context()
from sqlalchemy.orm import DeclarativeBase
class ORMBase(DeclarativeBase):
diff --git a/src/mrmat_python_api_fastapi/apis/greeting/v2/api.py b/src/mrmat_python_api_fastapi/apis/greeting/v2/api.py
index 2f92a2a..3248d07 100644
--- a/src/mrmat_python_api_fastapi/apis/greeting/v2/api.py
+++ b/src/mrmat_python_api_fastapi/apis/greeting/v2/api.py
@@ -26,6 +26,7 @@
from typing import Optional
from fastapi import APIRouter
+
from mrmat_python_api_fastapi.apis.greeting.v2 import GreetingV2Output
router = APIRouter()
diff --git a/src/mrmat_python_api_fastapi/apis/greeting/v3/api.py b/src/mrmat_python_api_fastapi/apis/greeting/v3/api.py
index 50a0b89..80e8a9d 100644
--- a/src/mrmat_python_api_fastapi/apis/greeting/v3/api.py
+++ b/src/mrmat_python_api_fastapi/apis/greeting/v3/api.py
@@ -21,6 +21,7 @@
# SOFTWARE.
from fastapi import APIRouter
+
from mrmat_python_api_fastapi.apis.greeting.v3 import GreetingV3Output
router = APIRouter()
diff --git a/src/mrmat_python_api_fastapi/apis/platform/v1/api.py b/src/mrmat_python_api_fastapi/apis/platform/v1/api.py
index 3a54c46..1c50b87 100644
--- a/src/mrmat_python_api_fastapi/apis/platform/v1/api.py
+++ b/src/mrmat_python_api_fastapi/apis/platform/v1/api.py
@@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+import uuid
+
from fastapi import APIRouter, Depends, status, HTTPException
from fastapi.responses import Response
from sqlalchemy.exc import SQLAlchemyError
@@ -93,12 +95,13 @@ async def create_resource(data: ResourceInputSchema,
response: Response,
session: Session = Depends(get_db)):
try:
- resource = Resource(name=data.name, owner_uid=data.owner_uid)
+ resource = Resource(uid=str(uuid.uuid4()), name=data.name, owner_uid=data.owner_uid)
session.add(resource)
session.commit()
response.status_code = 201
return resource
except SQLAlchemyError as e:
+ session.rollback()
raise HTTPException(status_code=500, detail="A database error occurred") from e
@@ -131,6 +134,7 @@ async def modify_resource(uid: str,
session.commit()
return resource
except SQLAlchemyError as e:
+ session.rollback()
raise HTTPException(status_code=500, detail="A database error occurred") from e
@@ -161,6 +165,7 @@ async def remove_resource(uid: str,
response.status_code = 204
return {}
except SQLAlchemyError as e:
+ session.rollback()
raise HTTPException(status_code=500, detail="A database error occurred") from e
@@ -216,12 +221,13 @@ async def create_owner(data: OwnerInputSchema,
response: Response,
session: Session = Depends(get_db)):
try:
- owner = Owner(name=data.name, client_id='TODO')
+ owner = Owner(uid=str(uuid.uuid4()), name=data.name)
session.add(owner)
session.commit()
response.status_code = 201
return owner
except SQLAlchemyError as e:
+ session.rollback()
# Handle the error appropriately, maybe raise an HTTPException
raise HTTPException(status_code=500, detail="A database error occurred") from e
@@ -255,6 +261,7 @@ async def modify_owner(uid: str,
session.commit()
return owner
except SQLAlchemyError as e:
+ session.rollback()
raise HTTPException(status_code=500, detail="A database error occurred") from e
@@ -284,4 +291,5 @@ async def remove_owner(uid: str,
session.commit()
response.status_code = status.HTTP_204_NO_CONTENT
except SQLAlchemyError as e:
+ session.rollback()
raise HTTPException(status_code=500, detail="A database error occurred") from e
diff --git a/src/mrmat_python_api_fastapi/apis/platform/v1/db.py b/src/mrmat_python_api_fastapi/apis/platform/v1/db.py
index fb90a02..4452a85 100644
--- a/src/mrmat_python_api_fastapi/apis/platform/v1/db.py
+++ b/src/mrmat_python_api_fastapi/apis/platform/v1/db.py
@@ -30,9 +30,9 @@
class Owner(ORMBase):
__tablename__ = 'owners'
__schema__ = 'mrmat-python-api-fastapi'
- uid: Mapped[str] = mapped_column(String, primary_key=True, default=str(uuid.uuid4()))
+ uid: Mapped[str] = mapped_column(String, primary_key=True)
- client_id: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
+ client_id: Mapped[str] = mapped_column(String(255), nullable=True, unique=True)
name: Mapped[str] = mapped_column(String(255), nullable=False)
resources: Mapped[list["Resource"]] = relationship('Resource', back_populates='owner')
@@ -40,7 +40,7 @@ class Owner(ORMBase):
class Resource(ORMBase):
__tablename__ = 'resources'
__schema__ = 'mrmat-python-api-fastapi'
- uid: Mapped[str] = mapped_column(String, primary_key=True, default=str(uuid.uuid4()))
+ uid: Mapped[str] = mapped_column(String, primary_key=True)
owner_uid: Mapped[str] = mapped_column(String, ForeignKey('owners.uid'), nullable=False)
name: Mapped[str] = mapped_column(String(255), nullable=False)
diff --git a/src/mrmat_python_api_fastapi/app.py b/src/mrmat_python_api_fastapi/app.py
index 0f00470..277d4a2 100644
--- a/src/mrmat_python_api_fastapi/app.py
+++ b/src/mrmat_python_api_fastapi/app.py
@@ -22,6 +22,8 @@
from fastapi import FastAPI
+from prometheus_fastapi_instrumentator import Instrumentator
+
from mrmat_python_api_fastapi.apis.healthz import api_healthz
from mrmat_python_api_fastapi.apis.greeting import api_greeting_v1, api_greeting_v2, api_greeting_v3
from mrmat_python_api_fastapi.apis.platform import api_platform_v1
@@ -33,6 +35,7 @@
app.include_router(api_greeting_v3, prefix='/api/greeting/v3', tags=['greeting'])
app.include_router(api_platform_v1, prefix='/api/platform/v1', tags=['platform'])
+Instrumentator().instrument(app).expose(app)
@app.get('/')
def index():
diff --git a/src/mrmat_python_api_fastapi/config.py b/src/mrmat_python_api_fastapi/config.py
index a7b2691..5698b1c 100644
--- a/src/mrmat_python_api_fastapi/config.py
+++ b/src/mrmat_python_api_fastapi/config.py
@@ -30,14 +30,18 @@ class Config:
A class to deal with application configuration
"""
secret_key: str = secrets.token_urlsafe(16)
- db_url: str = 'sqlite://'
+ db_url: str = 'sqlite:///'
@staticmethod
- def from_json_file(file: str | None = os.getenv('APP_CONFIG')):
+ def from_context(file: str | None = os.getenv('APP_CONFIG')):
runtime_config = Config()
if file and os.path.exists(file):
with open(file, 'r', encoding='UTF-8') as c:
file_config = json.load(c)
- runtime_config.secret_key = file_config.get_owner('secret_key', secrets.token_urlsafe(16))
- runtime_config.db_url = file_config.get_owner('db_url', 'sqlite://')
+ runtime_config.secret_key = file_config.get('secret_key', secrets.token_urlsafe(16))
+ runtime_config.db_url = file_config.get('db_url', 'sqlite:///')
+ if 'APP_CONFIG_SECRET_KEY' in os.environ:
+ runtime_config.secret_key = os.getenv('APP_CONFIG_SECRET_KEY', secrets.token_urlsafe(16))
+ if 'APP_CONFIG_DB_URL' in os.environ:
+ runtime_config.db_url = os.getenv('APP_CONFIG_DB_URL', '')
return runtime_config
diff --git a/src/mrmat_python_api_fastapi/db.py b/src/mrmat_python_api_fastapi/db.py
index 4ae9335..988eec3 100644
--- a/src/mrmat_python_api_fastapi/db.py
+++ b/src/mrmat_python_api_fastapi/db.py
@@ -35,5 +35,6 @@ def get_db() -> Session:
else:
engine = create_engine(url=app_config.db_url)
session_local = sessionmaker(autocommit=False, autoflush=False, bind=engine)
- ORMBase.metadata.create_all(bind=engine)
+ with session_local():
+ ORMBase.metadata.create_all(bind=engine)
return session_local()
diff --git a/var/client-k8s.http b/var/client-k8s.http
new file mode 100644
index 0000000..30fe249
--- /dev/null
+++ b/var/client-k8s.http
@@ -0,0 +1,19 @@
+### GET Owners
+GET https://mpafastapi.covenant.local/api/platform/v1/owners
+
+### GET resources
+GET https://mpafastapi.covenant.local/api/platform/v1/resources
+
+### Create Owner
+POST https://mpafastapi.covenant.local/api/platform/v1/owners
+Content-Type: application/json
+
+{
+ "name": "MrMat"
+}
+
+> {%
+ const owner_uid = jsonPath(response.body, ".owner_uid")
+ %}
+
+###
diff --git a/var/client-localhost.http b/var/client-localhost.http
new file mode 100644
index 0000000..c7d7dd0
--- /dev/null
+++ b/var/client-localhost.http
@@ -0,0 +1,19 @@
+### GET Owners
+GET http://localhost:8000/api/platform/v1/owners
+
+### GET resources
+GET http://localhost:8000/api/platform/v1/resources
+
+### Create Owner
+POST http://localhost:8000/api/platform/v1/owners
+Content-Type: application/json
+
+{
+ "name": "MrMat"
+}
+
+> {%
+ const owner_uid = jsonPath(response.body, ".owner_uid")
+ %}
+
+###
diff --git a/var/container/Dockerfile b/var/container/Dockerfile
index 6a64184..b9c2c75 100644
--- a/var/container/Dockerfile
+++ b/var/container/Dockerfile
@@ -1,7 +1,8 @@
FROM python:3.12-alpine AS build
ARG MRMAT_VERSION="0.0.0.dev0"
-ADD dist/mrmat_python_api_fastapi-*-py3-none-any.whl /
-RUN pip install --user /mrmat_python_api_fastapi-*-py3-none-any.whl
+ARG WHEEL=""
+ADD "$WHEEL" /
+RUN pip install --user /mrmat_python_api_fastapi-*.whl
FROM python:3.12-alpine
ARG MRMAT_VERSION="0.0.0.dev0"
@@ -13,5 +14,5 @@ RUN chown -R 1000:1000 /home/app/.local
USER app:app
EXPOSE 8000
-#CMD ["/home/app/.local/bin/uvicorn", "--host", "0.0.0.0", "--port", "8000", "mrmat_python_api_fastapi.app:app"]
-CMD ["/home/app/.local/bin/mrmat-python-api-fastapi"]
+CMD ["/home/app/.local/bin/opentelemetry-instrument", \
+ "/home/app/.local/bin/uvicorn", "--host", "0.0.0.0", "--port", "8000", "mrmat_python_api_fastapi.app:app"]
diff --git a/var/helm/Chart.yaml b/var/helm/Chart.yaml
index d91f08e..62ae3d6 100644
--- a/var/helm/Chart.yaml
+++ b/var/helm/Chart.yaml
@@ -2,14 +2,5 @@ apiVersion: v2
name: mrmat-python-api-fastapi
description: A Helm chart for MrMat Python API FastAPI
type: application
-
-# This is the chart version. This version number should be incremented each time you make changes
-# to the chart and its templates, including the app version.
-# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: "0.0.0"
-
-# This is the version number of the application being deployed. This version number should be
-# incremented each time you make changes to the application. Versions are not expected to
-# follow Semantic Versioning. They should reflect the version the application is using.
-# It is recommended to use it with quotes.
appVersion: "0.0.0.dev0"
diff --git a/var/helm/templates/_helpers.tpl b/var/helm/templates/_helpers.tpl
new file mode 100644
index 0000000..0962353
--- /dev/null
+++ b/var/helm/templates/_helpers.tpl
@@ -0,0 +1,8 @@
+
+{{/* Common labels */}}
+{{ define "common.labels" }}
+app: mpafastapi
+version: {{ .Chart.AppVersion }}
+app.kubernetes.io/part-of: mpafastapi
+app.kubernetes.io/version: {{ .Chart.AppVersion }}
+{{ end }}
diff --git a/var/helm/templates/deployment.yaml b/var/helm/templates/deployment.yaml
index c20f14c..c8005a9 100644
--- a/var/helm/templates/deployment.yaml
+++ b/var/helm/templates/deployment.yaml
@@ -1,34 +1,67 @@
apiVersion: apps/v1
kind: Deployment
metadata:
- name: mrmat-python-api-fastapi
+ name: mpafastapi
labels:
- app.kubernetes.io/name: mrmat-python-api-fastapi
- app.kubernetes.io/part-of: mrmat-python-api-fastapi
+ app.kubernetes.io/name: mpafastapi
+ {{ include "common.labels" . | nindent 4 }}
spec:
- replicas: 2
+ replicas: {{ .Values.pod.replicas | int }}
selector:
matchLabels:
- app: {{ .Values.pod.name }}
- version: {{ .Chart.AppVersion }}
+ {{ include "common.labels" . | nindent 6 }}
template:
metadata:
labels:
- sidecar.istio.io/inject: "true"
- app: {{ .Values.pod.name }}
- version: {{ .Chart.AppVersion }}
- app.kubernetes.io/name: mrmat-python-api-fastapi
- app.kubernetes.io/part-of: mrmat-python-api-fastapi
+ {{ include "common.labels" . | nindent 8 }}
+ annotations:
+ prometheus.io/scrape: "true"
+ prometheus.io/scheme: http
+ prometheus.io/port: "8000"
+ prometheus.io/path: /metrics
spec:
- serviceAccountName: {{ .Values.serviceAccount.name }}
+ serviceAccountName: {{ .Values.sa.name }}
+ volumes:
+ - name: config-volume
+ secret:
+ secretName: config-mpafastapi
+ - name: data-volume
+ emptyDir:
+ sizeLimit: 10Mi
+ medium: Memory
containers:
- - name: mrmat-python-api-fastapi
+ - name: mpafastapi
image: {{ .Values.pod.repository }}:{{ .Chart.AppVersion }}
imagePullPolicy: {{ .Values.pod.imagePullPolicy }}
+ env:
+ - name: APP_CONFIG
+ value: /config/app_config.json
+ - name: OTEL_SERVICE_NAME
+ value: "mrmat-python-api-fastapi"
+ - name: OTEL_TRACES_EXPORTER
+ value: "otlp"
+ - name: OTEL_METRICS_EXPORTER
+ value: "none"
+ - name: OTEL_LOGS_EXPORTER
+ value: "none"
+ - name: OTEL_EXPORTER_OTLP_ENDPOINT
+ value: "jaeger-collector.stack.svc.cluster.local:4317"
+ - name: OTEL_EXPORTER_OTLP_INSECURE
+ value: "true"
+ - name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
+ value: "jaeger-collector.stack.svc.cluster.local:4317"
+ - name: OTEL_EXPORTER_OTLP_TRACES_INSECURE
+ value: "true"
ports:
- name: http
containerPort: {{ .Values.pod.port }}
protocol: TCP
+ volumeMounts:
+ - name: config-volume
+ mountPath: /config
+ readOnly: true
+ - name: data-volume
+ mountPath: /data
securityContext:
capabilities:
drop:
@@ -37,13 +70,17 @@ spec:
runAsNonRoot: true
runAsUser: 1000
livenessProbe:
+ periodSeconds: 10
httpGet:
path: /api/healthz/liveness/
port: {{ .Values.pod.port }}
+ scheme: HTTP
readinessProbe:
+ periodSeconds: 10
httpGet:
path: /api/healthz/readiness/
port: {{ .Values.pod.port }}
+ scheme: HTTP
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
diff --git a/var/helm/templates/httproute.yaml b/var/helm/templates/httproute.yaml
deleted file mode 100644
index 7c76989..0000000
--- a/var/helm/templates/httproute.yaml
+++ /dev/null
@@ -1,34 +0,0 @@
-{{- if .Values.httproute.enabled -}}
-apiVersion: gateway.networking.k8s.io/v1
-kind: HTTPRoute
-metadata:
- name: {{ .Values.httproute.name }}
- labels:
- app: {{ .Values.pod.name }}
- version: {{ .Chart.AppVersion }}
- app.kubernetes.io/name: {{ .Values.httproute.name }}
- app.kubernetes.io/part-of: mrmat-python-api-fastapi
-spec:
- hostnames:
- {{- range .Values.httproute.hostnames }}
- - {{ . | quote }}
- {{- end }}
- - mrmat-python-api-fastapi.local
- parentRefs:
- {{- range .Values.httproute.parents }}
- - group: gateway.networking.k8s.io
- kind: Gateway
- name: {{ .name }}
- namespace: {{ .namespace }}
- {{- end }}
- rules:
- - backendRefs:
- - kind: Service
- name: {{ .Values.service.name }}
- port: {{ .Values.service.port }}
- weight: 1
- matches:
- - path:
- type: PathPrefix
- value: /
-{{- end -}}
diff --git a/var/helm/templates/ingress.yaml b/var/helm/templates/ingress.yaml
deleted file mode 100644
index 5bdb791..0000000
--- a/var/helm/templates/ingress.yaml
+++ /dev/null
@@ -1,43 +0,0 @@
-{{- if .Values.ingress.enabled -}}
-apiVersion: networking.k8s.io/v1
-kind: Ingress
-metadata:
- name: {{ include "helm.fullname" . }}
- labels:
- {{- include "helm.labels" . | nindent 4 }}
- {{- with .Values.ingress.annotations }}
- annotations:
- {{- toYaml . | nindent 4 }}
- {{- end }}
-spec:
- {{- with .Values.ingress.className }}
- ingressClassName: {{ . }}
- {{- end }}
- {{- if .Values.ingress.tls }}
- tls:
- {{- range .Values.ingress.tls }}
- - hosts:
- {{- range .hosts }}
- - {{ . | quote }}
- {{- end }}
- secretName: {{ .secretName }}
- {{- end }}
- {{- end }}
- rules:
- {{- range .Values.ingress.hosts }}
- - host: {{ .host | quote }}
- http:
- paths:
- {{- range .paths }}
- - path: {{ .path }}
- {{- with .pathType }}
- pathType: {{ . }}
- {{- end }}
- backend:
- service:
- name: {{ include "helm.fullname" $ }}
- port:
- number: {{ $.Values.service.port }}
- {{- end }}
- {{- end }}
-{{- end }}
diff --git a/var/helm/templates/route.yaml b/var/helm/templates/route.yaml
new file mode 100644
index 0000000..2ccaca0
--- /dev/null
+++ b/var/helm/templates/route.yaml
@@ -0,0 +1,31 @@
+{{- if .Values.route.enabled -}}
+apiVersion: gateway.networking.k8s.io/v1
+kind: HTTPRoute
+metadata:
+ name: {{ .Values.route.name }}
+ labels:
+ {{ include "common.labels" . | nindent 4 }}
+spec:
+ hostnames:
+ {{- range .Values.route.hostnames }}
+ - {{ . | quote }}
+ {{- end }}
+ parentRefs:
+ {{- range .Values.route.parents }}
+ - group: gateway.networking.k8s.io
+ kind: Gateway
+ name: {{ .name }}
+ namespace: {{ .namespace }}
+ sectionName: mpafastapi
+ {{- end }}
+ rules:
+ - backendRefs:
+ - kind: Service
+ name: {{ .Values.svc.name }}
+ port: {{ .Values.svc.port }}
+ weight: 1
+ matches:
+ - path:
+ type: PathPrefix
+ value: /
+{{- end -}}
diff --git a/var/helm/templates/secret.yaml b/var/helm/templates/secret.yaml
new file mode 100644
index 0000000..84dd330
--- /dev/null
+++ b/var/helm/templates/secret.yaml
@@ -0,0 +1,10 @@
+apiVersion: v1
+kind: Secret
+metadata:
+ name: config-mpafastapi
+ labels:
+ app.kubernetes.io/name: config-mpafastapi
+ {{ include "common.labels" . | nindent 4 }}
+stringData:
+ app_config.json: |-
+ { "db_url": {{ .Values.config.db_url | quote }} }
diff --git a/var/helm/templates/service.yaml b/var/helm/templates/service.yaml
index 3f38c96..4738ee5 100644
--- a/var/helm/templates/service.yaml
+++ b/var/helm/templates/service.yaml
@@ -1,16 +1,13 @@
apiVersion: v1
kind: Service
metadata:
- name: {{ .Values.service.name }}
+ name: {{ .Values.svc.name }}
labels:
- app: {{ .Values.pod.name }}
- version: {{ .Chart.AppVersion }}
- app.kubernetes.io/name: {{ .Values.service.name }}
- app.kubernetes.io/part-of: mrmat-python-api-fastapi
+ {{ include "common.labels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- - port: {{ .Values.service.port }}
+ - port: {{ .Values.svc.port }}
targetPort: {{ .Values.pod.port }}
protocol: TCP
name: http
diff --git a/var/helm/templates/serviceaccount.yaml b/var/helm/templates/serviceaccount.yaml
index 88b1e7a..3df429c 100644
--- a/var/helm/templates/serviceaccount.yaml
+++ b/var/helm/templates/serviceaccount.yaml
@@ -1,10 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
- name: {{ .Values.serviceAccount.name }}
+ name: {{ .Values.sa.name }}
labels:
- app: {{ .Values.pod.name }}
- version: {{ .Chart.AppVersion }}
- app.kubernetes.io/name: {{ .Values.serviceAccount.name }}
- app.kubernetes.io/part-of: mrmat-python-api-fastapi
+ {{ include "common.labels" . | nindent 4 }}
automountServiceAccountToken: true
diff --git a/var/helm/values.yaml b/var/helm/values.yaml
index 25a7a29..d488153 100644
--- a/var/helm/values.yaml
+++ b/var/helm/values.yaml
@@ -1,46 +1,28 @@
#
-# Default values
+# Default values for MrMat :: Python API FastAPI
-# This is to override the chart name.
-nameOverride: ""
-fullnameOverride: ""
-
-serviceAccount:
- name: mrmat-python-api-fastapi-sa
+sa:
+ name: sa-mpafastapi
pod:
- name: mrmat-python-api-fastapi
- replicas: 2
- repository: mrmat-registry:5000/mrmat-python-api-fastapi
- imagePullPolicy: IfNotPresent
+ name: mpafastapi
+ replicas: 1
+ repository: registry:5000/mrmat-python-api-fastapi
+ imagePullPolicy: Always
port: 8000
-service:
- name: mrmat-python-api-fastapi-svc
+svc:
+ name: svc-mpafastapi
port: 80
-httproute:
+route:
enabled: true
- name: mrmat-python-api-fastapi-httproute
+ name: route-mpafastapi
hostnames:
- - mrmat-python-api-fastapi.local
+ - mpafastapi.covenant.local
parents:
- - name: istio-ingress
+ - name: edge-ingress
namespace: edge
-ingress:
- enabled: false
- name: mrmat-python-api-fastapi-ing
- className: ""
- annotations: { }
- # kubernetes.io/ingress.class: nginx
- # kubernetes.io/tls-acme: "true"
- hosts:
- - host: mrmat-python-api-fastapi.local
- paths:
- - path: /
- pathType: ImplementationSpecific
- tls: [ ]
- # - secretName: chart-example-tls
- # hosts:
- # - chart-example.local
+config:
+ db_url: "sqlite:///data/db.sqlite"