Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Deltachaos authored Jul 21, 2024
1 parent 049308c commit 150f3ce
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,29 @@ def read_job_files_from_directory(directory):
job_files.append(file.read())
return job_files

def get_job_name_from_pod(namespace, pod_name):
v1 = client.CoreV1Api()
pod = v1.read_namespaced_pod(name=pod_name, namespace=namespace)
for owner in pod.metadata.owner_references:
if owner.kind == 'Job':
return owner.name
return None

def main():
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.info("Starting the job sequence script.")

config.load_incluster_config()
namespace = os.getenv('NAMESPACE', 'default')
configmap_name = os.getenv('JOB_CONFIGMAP')
job_name_env = "job"

if os.getenv('JOB_NAME'):
job_name_env = os.getenv('JOB_NAME')
job_name_env = os.getenv('JOB_NAME')

if not job_name_env:
pod_name = get_pod_name()
job_name_env = get_job_name_from_pod(namespace, pod_name)
if not job_name_env:
logging.error("Could not determine the job name from the pod metadata and JOB_NAME is not set.")
exit(1)

v1 = client.CoreV1Api()

Expand Down

0 comments on commit 150f3ce

Please sign in to comment.