Skip to content

Commit

Permalink
fix generic
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiionutdamian committed Feb 7, 2024
1 parent bfcc9c3 commit 1016544
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions basic_test_fastapi/.secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: redis-secret
name: basic-test-app-secrets
namespace: basic-ns11
type: Opaque
data:
Expand All @@ -10,7 +10,7 @@ data:
apiVersion: v1
kind: Secret
metadata:
name: redis-secret
name: basic-test-app-secrets
namespace: basic-ns12
type: Opaque
data:
Expand Down
11 changes: 7 additions & 4 deletions basic_test_fastapi/nodeport_example/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ NAMESPACE="basic-ns11"
kubectl delete -f deploy_nodeport.yaml

# Wait for the pods to be deleted
while kubectl get pods -l run=$APP_NAME -n $NAMESPACE; do
echo "Waiting for pods to terminate..."
while true; do
OUTPUT=$(kubectl get pods -l run=$APP_NAME -n $NAMESPACE 2>&1)
echo "$OUTPUT"
if [[ "$OUTPUT" == *"No resources found"* ]]; then
echo "All pods terminated."
break
fi
sleep 5
done

echo "All pods terminated."
4 changes: 2 additions & 2 deletions basic_test_fastapi/nodeport_example/deploy_nodeport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-secret
name: basic-test-app-secrets
key: redis-password
args: ["--requirepass", "$(REDIS_PASSWORD)"]
ports:
Expand Down Expand Up @@ -72,7 +72,7 @@ spec:
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-secret
name: basic-test-app-secrets
key: redis-password
---
apiVersion: v1
Expand Down
2 changes: 1 addition & 1 deletion basic_test_fastapi/nodeport_example/log_nodeport.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
NAMESPACE=basic-ns11
POD_NAME=$(kubectl get pods -n $NAMESPACE -o jsonpath="{.items[0].metadata.name}")
kubectl logs -n basic-ns11 $POD_NAME
kubectl logs -n basic-ns11 $POD_NAME -f

16 changes: 8 additions & 8 deletions basic_test_fastapi/src/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

from app_utils import safe_jsonify

__VER__ = '0.2.5'
__VER__ = '0.3.0'


class AppPaths:
PATH_ROOT = {"PATH": "/", "FUNC": "root"}
PATH_STAT = {"PATH": "/stat", "FUNC": "stat" }
PATH_STAT = {"PATH": "/stats", "FUNC": "stats" }

class AppHandler:
def __init__(self):
Expand Down Expand Up @@ -108,24 +108,24 @@ def handle_request(self, path):
self.process_data()
if path in self.__avail_paths:
func_name = '_handle_' + self.__path_to_func[path]
msg = getattr(self, func_name)()
msg = getattr(self, func_name)(path=path)
else:
msg = self.__handle_generic(path)
result = self._pack_result(msg)
return result


def _handle_root(self):
def _handle_root(self, **kwargs):
msg = "Handler '{}', Local/Global: {}/{}, HOSTNAME: '{}', ID: '{}'".format(
AppPaths.PATH_ROOT, self.__local_count, self.get_cluster_count(),
kwargs['path'], self.__local_count, self.get_cluster_count(),
self.hostname, self.str_local_id
)
return msg

def _handle_stat(self):
def _handle_stat(self, **kwargs):
dct_result = {
'info' : "Handler '{}', Worker HOSTNAME: '{}', ID: '{}'".format(
AppPaths.PATH_STAT, self.hostname, self.str_local_id
kwargs['path'], self.hostname, self.str_local_id
),
'local_count' : self.__local_count,
'cluster_count' : self.get_cluster_count(),
Expand All @@ -134,7 +134,7 @@ def _handle_stat(self):
return dct_result


def __handle_generic(self, path):
def __handle_generic(self, path, **kwargs):
msg = "Generic handler '{}', Local/Global: {}/{}, HOSTNAME: '{}', ID: '{}'".format(
path, self.__local_count, self.get_cluster_count(),
self.hostname, self.str_local_id
Expand Down
9 changes: 4 additions & 5 deletions basic_test_fastapi/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@

@router1.get(AppPaths.PATH_ROOT['PATH'])
async def root():
result = engine.handle_request(AppPaths.PATH_ROOT['PATH'])
return result
return engine.handle_request(AppPaths.PATH_ROOT['PATH'])

@router1.get(AppPaths.PATH_STAT['PATH'])
async def stat():
result = engine.handle_request(AppPaths.PATH_STAT['PATH'])
return result
return engine.handle_request(AppPaths.PATH_STAT['PATH'])

# note: this is a catch-all route, so it should be the last route in the router
@router1.get("/{full_path:path}", include_in_schema=False)
async def catch_all(full_path: str):
result = engine.handle_request(full_path)
return engine.handle_request(full_path)



app.include_router(router1)

0 comments on commit 1016544

Please sign in to comment.