Skip to content

Commit

Permalink
Add instance deletion from itself
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasHerve committed Apr 3, 2024
1 parent 02719a7 commit f04c8fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/app/handlers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create_room():

# Create a pod
containers = []
container1 = client.V1Container(name='instance', image=image)
container1 = client.V1Container(name='instance', image=image, env=[client.V1EnvVar(name="INSTANCE_NAME", value=pod_id), client.V1EnvVar(name="BACKEND_URL", value=os.environ["BACKEND_URL"])])
containers.append(container1)

pod_spec = client.V1PodSpec(containers=containers)
Expand Down
4 changes: 4 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ spec:
value: "{{ .Values.ingress.name }}"
- name: KUBERNETES_PORT
value: "{{ .Values.service.port }}"
- name: BACKEND_URL
{{- with (index .Values.ingress.hosts 0) }}
value: {{ .host }}
{{- end }}
ports:
- name: http
containerPort: 8000
Expand Down
11 changes: 10 additions & 1 deletion instance/app/handlers/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import hug
import requests
import os

messages = []

Expand All @@ -13,4 +15,11 @@ def pull():
def publish(body):
global messages
messages.append(body["message"])
return f"Message published : {body['message']}"
return f"Message published : {body['message']}"

@hug.post('/stop')
def stop():
instance_name = os.environ["INSTANCE_NAME"]
backend_url = os.environ["BACKEND_URL"]
requests.post(f"{backend_url}/delete-room", data={"instance": instance_name})
return "deleted"
3 changes: 2 additions & 1 deletion instance/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
hug == 2.4.8
hug-middleware-cors == 1.0.0
hug-middleware-cors == 1.0.0
requests == 2.25.1

0 comments on commit f04c8fa

Please sign in to comment.