Skip to content

Commit

Permalink
pipelines 1.13 don't have anymore taskRuns in status, but only
Browse files Browse the repository at this point in the history
childReferences

Signed-off-by: Robert Cerven <rcerven@redhat.com>
  • Loading branch information
rcerven committed Feb 28, 2024
1 parent b0a61b1 commit c057e2d
Showing 1 changed file with 40 additions and 31 deletions.
71 changes: 40 additions & 31 deletions osbs/tekton.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,22 +493,15 @@ def get_task_results(self):
if not data:
return task_results

task_runs_status = data['status'].get('taskRuns', {})
child_references = data['status'].get('childReferences', [])

for _, stats in get_sorted_task_runs(task_runs_status):
if not ('status' in stats and 'conditions' in stats['status']):
continue

if stats['status']['conditions'][0]['reason'] != 'Succeeded':
continue
for task_run in child_references:
task_info = TaskRun(os=self.os,task_run_name=task_run['name']).get_info()

if 'taskResults' not in stats['status']:
continue

task_name = stats['pipelineTaskName']
task_name = task_info['metadata']['labels']['tekton.dev/pipelineTask']
results = {}

for result in stats['status']['taskResults']:
for result in task_info['status']['taskResults']:
results[result['name']] = result['value']

task_results[task_name] = results
Expand All @@ -521,9 +514,7 @@ def get_error_message(self):
if not data:
return "pipeline run removed;"

task_runs_status = data['status'].get('taskRuns', {})
sorted_tasks = get_sorted_task_runs(task_runs_status)

child_references = data['status'].get('childReferences', [])
plugin_errors = None
annotations_str = None
task_results = self.get_task_results()
Expand All @@ -550,14 +541,16 @@ def get_error_message(self):

pipeline_error = data['status']['conditions'][0].get('message')

for _, stats in sorted_tasks:
task_name = stats['pipelineTaskName']
for task_run in child_references:
task_info = TaskRun(os=self.os,task_run_name=task_run['name']).get_info()

task_name = task_info['metadata']['labels']['tekton.dev/pipelineTask']
got_task_error = False
if stats['status']['conditions'][0]['reason'] == 'Succeeded':
if task_info['status']['conditions'][0]['reason'] == 'Succeeded':
continue

if 'steps' in stats['status']:
for step in stats['status']['steps']:
if 'steps' in task_info['status']:
for step in task_info['status']['steps']:
if 'terminated' in step:
exit_code = step['terminated']['exitCode']
if exit_code == 0:
Expand All @@ -578,7 +571,7 @@ def get_error_message(self):

if not got_task_error:
err_message += f"Error in {task_name}: " \
f"{stats['status']['conditions'][0]['message']};\n"
f"{task_info['status']['conditions'][0]['message']};\n"

if not err_message:
if pipeline_error:
Expand Down Expand Up @@ -651,9 +644,11 @@ def _any_task_run_in_state(

def matches_state(task_run: Dict[str, Any]) -> bool:
task_run_status = task_run['status']
task_name = task_run['metadata']['labels']['tekton.dev/pipelineTask']

if 'conditions' not in task_run_status:
logger.debug('conditions are missing from status in task %s : %s',
task_run['pipelineTaskName'], task_run_status)
task_name, task_run_status)
return False

status = task_run_status['conditions'][0]['status']
Expand All @@ -663,13 +658,19 @@ def matches_state(task_run: Dict[str, Any]) -> bool:
if match_state(status, reason, completion_time is not None):
logger.debug(
'Found %s task: name=%s; status=%s; reason=%s; completionTime=%s',
state_name, task_run['pipelineTaskName'], status, reason, completion_time,
state_name, task_name, status, reason, completion_time,
)
return True

return False

task_runs = self.data['status'].get('taskRuns', {}).values()
child_references = self.data['status'].get('childReferences', [])

task_runs = []
for task_run in child_references:
task_info = TaskRun(os=self.os,task_run_name=task_run['name']).get_info()
task_runs.append(task_info)

return any(matches_state(tr) for tr in task_runs)

def wait_for_finish(self):
Expand Down Expand Up @@ -785,17 +786,22 @@ def wait_for_taskruns(self):
return []

try:
task_runs = pipeline_run['status']['taskRuns']
child_references = self.data['status'].get('childReferences', [])
except KeyError:
logger.debug(
"Pipeline run '%s' does not have any task runs yet",
self.pipeline_run_name)
continue
current_task_runs = []
for task_run_name, task_run_data in task_runs.items():

for task_run in child_references:
task_run_name = task_run['name']
task_info = TaskRun(os=self.os,task_run_name=task_run_name).get_info()
task_name = task_info['metadata']['labels']['tekton.dev/pipelineTask']

if task_run_name not in watched_task_runs:
watched_task_runs.add(task_run_name)
current_task_runs.append((task_run_data['pipelineTaskName'], task_run_name))
current_task_runs.append((task_name, task_run_name))

yield current_task_runs

Expand All @@ -815,12 +821,15 @@ def _get_logs(self):
if not pipeline_run:
return None

task_runs = pipeline_run['status']['taskRuns']
child_references = self.data['status'].get('childReferences', [])

for task_run in child_references:
task_run_object = TaskRun(os=self.os, task_run_name=task_run['name'])
task_info = task_run_object.get_info()
pipeline_task_name = task_info['metadata']['labels']['tekton.dev/pipelineTask']

for task_run_name, task_run_data in get_sorted_task_runs(task_runs):
pipeline_task_name = task_run_data['pipelineTaskName']
logs[pipeline_task_name] = task_run_object.get_logs()

logs[pipeline_task_name] = TaskRun(os=self.os, task_run_name=task_run_name).get_logs()
return logs

def _get_logs_stream(self):
Expand Down

0 comments on commit c057e2d

Please sign in to comment.