Skip to content

Commit b1aa169

Browse files
authored
Merge pull request #8 from MrMatAP/feature/auth
Edge Variants
2 parents 6f29f54 + 57336d6 commit b1aa169

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ CONTAINER_SOURCES := $(shell find var/container)
1515
HELM_SOURCES := $(shell find var/helm)
1616
HELM_TARGET := dist/mrmat-python-api-fastapi-$(VERSION).tgz
1717

18+
# Can be either 'sidecar' or 'ambient'
19+
ISTIO := ambient
20+
1821
all: python container helm
1922
python: $(PYTHON_TARGET)
2023
helm: $(HELM_TARGET)
@@ -40,13 +43,16 @@ container: $(PYTHON_TARGET) $(CONTAINER_SOURCES)
4043

4144
helm-install: $(HELM_TARGET)
4245
kubectl create ns mpafastapi || true
43-
kubectl label --overwrite ns mpafastapi istio-injection=true
46+
if test "$(ISTIO)" == "sidecar"; then kubectl label --overwrite ns mpafastapi istio-injection=true; fi
47+
if test "$(ISTIO)" == "ambient"; then kubectl label --overwrite ns mpafastapi istio.io/dataplane-mode=ambient; fi
4448
helm upgrade \
4549
mrmat-python-api-fastapi \
4650
${HELM_TARGET} \
4751
--install \
52+
--wait \
4853
--force \
49-
--namespace mpafastapi
54+
--namespace mpafastapi \
55+
--set istio=$(ISTIO)
5056

5157
helm-uninstall:
5258
helm delete -n mpafastapi mrmat-python-api-fastapi

src/mrmat_python_api_fastapi/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222

2323
from fastapi import FastAPI
24+
from fastapi.security import OAuth2PasswordBearer
2425

2526
from prometheus_fastapi_instrumentator import Instrumentator
2627

@@ -29,6 +30,7 @@
2930
from mrmat_python_api_fastapi.apis.platform import api_platform_v1
3031

3132
app = FastAPI(title='MrMat :: Python :: API :: FastAPI')
33+
oauth2_scheme = OAuth2PasswordBearer(tokenUrl='token')
3234
app.include_router(api_healthz, prefix='/api/healthz', tags=['health'])
3335
app.include_router(api_greeting_v1, prefix='/api/greeting/v1', tags=['greeting'])
3436
app.include_router(api_greeting_v2, prefix='/api/greeting/v2', tags=['greeting'])

var/helm/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec:
3737
- name: APP_CONFIG
3838
value: /config/app_config.json
3939
- name: OTEL_SERVICE_NAME
40-
value: "mrmat-python-api-fastapi"
40+
value: "{{ .Release.Namespace }}.mpafastapi"
4141
- name: OTEL_TRACES_EXPORTER
4242
value: "otlp"
4343
- name: OTEL_METRICS_EXPORTER
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.ingress.enabled }}
1+
{{- if eq .Values.edge.kind "ingress" }}
22
---
33
apiVersion: networking.k8s.io/v1
44
kind: Ingress

var/helm/templates/route.yaml renamed to var/helm/templates/edge-istio-gateway-api.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.route.enabled -}}
1+
{{- if eq .Values.edge.kind "istio-gateway-api" -}}
22
apiVersion: gateway.networking.k8s.io/v1
33
kind: HTTPRoute
44
metadata:
@@ -11,13 +11,11 @@ spec:
1111
- {{ . | quote }}
1212
{{- end }}
1313
parentRefs:
14-
{{- range .Values.route.parents }}
1514
- group: gateway.networking.k8s.io
1615
kind: Gateway
17-
name: {{ .name }}
18-
namespace: {{ .namespace }}
16+
name: {{ .Values.edge.name }}
17+
namespace: {{ .Values.edge.ns }}
1918
sectionName: mpafastapi
20-
{{- end }}
2119
rules:
2220
- backendRefs:
2321
- kind: Service

var/helm/templates/edge-istio.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if eq .Values.edge.kind "istio" }}
2+
---
3+
apiVersion: gateway.networking.k8s.io/v1
4+
kind: Gateway
5+
metadata:
6+
name: waypoint
7+
namespace: {{ .Release.Namespace }}
8+
spec:
9+
gatewayClassName: istio-waypoint
10+
listeners:
11+
- name: mesh
12+
port: 15008
13+
protocol: HBONE
14+
{{- end }}

var/helm/values.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,25 @@ svc:
1515
name: svc-mpafastapi
1616
port: 80
1717

18+
edge:
19+
ns: edge
20+
name: edge-ingress
21+
kind: istio-gateway-api
22+
1823
route:
1924
enabled: false
2025
name: route-mpafastapi
2126
hostnames:
22-
- mpafastapi.covenant.local
27+
- mpafastapi.nostromo.k8s
2328
parents:
2429
- name: edge-ingress
2530
namespace: edge
2631

32+
istio: ambient
33+
2734
ingress:
28-
enabled: true
35+
enabled: false
2936
hostname: mpafastapi.nostromo.k8s
3037

3138
config:
32-
db_url: "sqlite://data/db.sqlite3"
39+
db_url: "sqlite:////data/db.sqlite3"

0 commit comments

Comments
 (0)