From fdb3ec03f204ed0960f662d1f7bcb7501b4a80bd Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Tue, 11 Jul 2023 15:14:28 -0400 Subject: [PATCH] fix: Live workflow takes precedence during merge to correctly display in the UI (#11336) Signed-off-by: Yuan Tang --- server/workflow/workflow_server.go | 12 +++++++++++- server/workflow/workflow_server_test.go | 14 +++++++++----- ui/src/models/workflows.ts | 7 +------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/server/workflow/workflow_server.go b/server/workflow/workflow_server.go index dab707dc4b76..f5c7ebe55dde 100644 --- a/server/workflow/workflow_server.go +++ b/server/workflow/workflow_server.go @@ -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) diff --git a/server/workflow/workflow_server_test.go b/server/workflow/workflow_server_test.go index f747f8f42997..2fbfc5d698d5 100644 --- a/server/workflow/workflow_server_test.go +++ b/server/workflow/workflow_server_test.go @@ -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) diff --git a/ui/src/models/workflows.ts b/ui/src/models/workflows.ts index e8a653e492db..130289796ebc 100644 --- a/ui/src/models/workflows.ts +++ b/ui/src/models/workflows.ts @@ -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';