Skip to content

Commit

Permalink
fix: Live workflow takes precedence during merge to correctly display…
Browse files Browse the repository at this point in the history
… in the UI (#11336)

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>
  • Loading branch information
terrytangyuan authored Jul 11, 2023
1 parent 15a8365 commit fdb3ec0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
12 changes: 11 additions & 1 deletion server/workflow/workflow_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,17 @@ func mergeWithArchivedWorkflows(liveWfs v1alpha1.WorkflowList, archivedWfs v1alp
}

for _, v := range uidToWfs {
mergedWfs = append(mergedWfs, v[0])
// The archived workflow we saved in the database will only have "Pending" as the archival status.
// We want to only keep the workflow that has the correct label to display correctly in the UI.
if len(v) == 1 {
mergedWfs = append(mergedWfs, v[0])
} else {
if ok := v[0].Labels[common.LabelKeyWorkflowArchivingStatus] == "Archived"; ok {
mergedWfs = append(mergedWfs, v[0])
} else {
mergedWfs = append(mergedWfs, v[1])
}
}
}
mergedWfsList := v1alpha1.WorkflowList{Items: mergedWfs, ListMeta: liveWfs.ListMeta}
sort.Sort(mergedWfsList.Items)
Expand Down
14 changes: 9 additions & 5 deletions server/workflow/workflow_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,19 @@ func (t testWatchWorkflowServer) Send(*workflowpkg.WorkflowWatchEvent) error {

func TestMergeWithArchivedWorkflows(t *testing.T) {
timeNow := time.Now()
wf1 := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "1", CreationTimestamp: metav1.Time{Time: timeNow.Add(time.Second)}}}
wf1Live := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "1", CreationTimestamp: metav1.Time{Time: timeNow.Add(time.Second)},
Labels: map[string]string{common.LabelKeyWorkflowArchivingStatus: "Archived"}}}
wf1Archived := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "1", CreationTimestamp: metav1.Time{Time: timeNow.Add(time.Second)},
Labels: map[string]string{common.LabelKeyWorkflowArchivingStatus: "Pending"}}}
wf2 := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "2", CreationTimestamp: metav1.Time{Time: timeNow.Add(2 * time.Second)}}}
wf3 := v1alpha1.Workflow{
ObjectMeta: metav1.ObjectMeta{UID: "3", CreationTimestamp: metav1.Time{Time: timeNow.Add(3 * time.Second)}}}
liveWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf1, wf2}}
archivedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf1, wf3, wf2}}
expectedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf3, wf2, wf1}}
liveWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf1Live, wf2}}
archivedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf1Archived, wf3, wf2}}
expectedWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf3, wf2, wf1Live}}
expectedShortWfList := v1alpha1.WorkflowList{Items: []v1alpha1.Workflow{wf3, wf2}}
assert.Equal(t, expectedWfList.Items, mergeWithArchivedWorkflows(liveWfList, archivedWfList, 0).Items)
assert.Equal(t, expectedShortWfList.Items, mergeWithArchivedWorkflows(liveWfList, archivedWfList, 2).Items)
Expand Down
7 changes: 1 addition & 6 deletions ui/src/models/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,8 @@ export interface Workflow {

export const execSpec = (w: Workflow) => Object.assign({}, w.status.storedWorkflowTemplateSpec, w.spec);

// The label may not have been updated on time but usually this indicates that they are already archived.
export function isArchivedWorkflow(wf: Workflow): boolean {
return (
wf.metadata.labels &&
(wf.metadata.labels['workflows.argoproj.io/workflow-archiving-status'] === 'Archived' ||
wf.metadata.labels['workflows.argoproj.io/workflow-archiving-status'] === 'Pending')
);
return wf.metadata.labels && wf.metadata.labels['workflows.argoproj.io/workflow-archiving-status'] === 'Archived';
}

export type NodeType = 'Pod' | 'Container' | 'Steps' | 'StepGroup' | 'DAG' | 'Retry' | 'Skipped' | 'TaskGroup' | 'Suspend';
Expand Down

0 comments on commit fdb3ec0

Please sign in to comment.