Skip to content

Commit

Permalink
feat: Smaller code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightknight3000 committed Aug 7, 2024
1 parent 121e1a5 commit 4cdb6c4
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@


class CreateAnalysis(BaseModel):
analysis_id: str = 'flame-test'
project_id: str = 'project1'
registry_url: str = ''
registry_user: str = ''
registry_password: str = ''
analysis_id: str = 'analysis_id'
project_id: str = 'project_id'
registry_url: str = 'harbor.privateaim'
registry_user: str = 'robot_user'
registry_password: str = 'default_pw'


@router.post("/", response_class=JSONResponse)
Expand Down
10 changes: 7 additions & 3 deletions src/k8s/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,22 @@ def _create_nginx_config_map(analysis_name: str,

# get the service ip of the message broker and analysis service
message_broker_service_name = get_element_by_substring(service_names, 'message-broker')
message_broker_service_ip = core_client.read_namespaced_service(name=message_broker_service_name, namespace=namespace).spec.cluster_ip
message_broker_service_ip = core_client.read_namespaced_service(name=message_broker_service_name,
namespace=namespace).spec.cluster_ip

# wait until analysis pod receives a cluster ip
analysis_ip = None
while analysis_ip is None:
pod_list_object = core_client.list_namespaced_pod(label_selector=f"app={analysis_name}", watch=False, namespace=namespace)
pod_list_object = core_client.list_namespaced_pod(label_selector=f"app={analysis_name}",
watch=False,
namespace=namespace)
analysis_ip = pod_list_object.items[0].status.pod_ip
print(analysis_ip)
time.sleep(1)

# analysis_ip = core_client.read_namespaced_pod(name=analysis_name, namespace=namespace).spec.cluster_ip
# analysis_service_ip = core_client.read_namespaced_service(name=analysis_service_name, namespace=namespace).spec.cluster_ip
# analysis_service_ip = core_client.read_namespaced_service(name=analysis_service_name,
# namespace=namespace).spec.cluster_ip
kong_proxy_name = get_element_by_substring(service_names, 'kong-proxy')
result_service_name = get_element_by_substring(service_names, 'result-service')
data = {
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def tearDown(self):

def test_create_analysis(self):
analysis = self.database.create_analysis(analysis_id="123", image_registry_address="harbor.com",
ports=[80, 443],pod_ids=["a1"], status="running")
ports=[80, 443], pod_ids=["a1"], status="running")
print(f"{analysis.analysis_id}, 123")

def test_get_analysis(self):
Expand Down
7 changes: 0 additions & 7 deletions src/utils/other.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import os
from httpx import AsyncClient
import asyncio


# def create_image_address(analysis_id: str) -> str:
# return f"{_add_slash(os.getenv('HARBOR_URL'))}"\
# f"{_add_slash(os.getenv('NODE_NAME'))}"\
# f"{analysis_id}:latest"


def _add_slash(string: str) -> str:
return string + ('' if string.endswith('/') else '/')

Expand Down
0 down.sh → tobedeleted/down.sh
100755 → 100644
File renamed without changes.
0 setup.sh → tobedeleted/setup.sh
100755 → 100644
File renamed without changes.
File renamed without changes.

0 comments on commit 4cdb6c4

Please sign in to comment.