Skip to content

Commit

Permalink
fix: add new service prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightknight3000 committed Aug 16, 2024
1 parent 5b360ed commit e52d545
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/k8s/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,19 @@ def _create_nginx_config_map(analysis_name: str,


def _create_service(name: str, ports: list[int], target_ports: list[int], namespace: str = 'default') -> str:
service_name = f"analysis-{name}"
core_client = client.CoreV1Api()

service_spec = client.V1ServiceSpec(selector={'app': name},
ports=[client.V1ServicePort(port=port, target_port=target_port)
for port, target_port in zip(ports, target_ports)])
service_body = client.V1Service(metadata=client.V1ObjectMeta(name=name,
labels={'app': name}),
service_body = client.V1Service(metadata=client.V1ObjectMeta(name=service_name,
labels={'app': service_name}),
spec=service_spec)
core_client.create_namespaced_service(body=service_body, namespace=namespace)

# service_ip = core_client.read_namespaced_service(name=service_name, namespace=namespace).spec.cluster_ip
return name
return service_name


def _create_analysis_network_policy(analysis_name: str, nginx_name: str, namespace: str = 'default') -> None:
Expand Down Expand Up @@ -322,7 +323,7 @@ def delete_deployment(depl_name: str, namespace: str = 'default') -> None:
for name in [depl_name, f'nginx-{depl_name}']:
try:
app_client.delete_namespaced_deployment(async_req=False, name=name, namespace=namespace)
_delete_service(name, namespace)
_delete_service(f"analysis-{name}", namespace)
except client.exceptions.ApiException as e:
if e.reason != 'Not Found':
print(f"Not Found {name}")
Expand Down

0 comments on commit e52d545

Please sign in to comment.