Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argo CLI list command results not predictable with -o name flag #7581

Closed
samene opened this issue Jan 19, 2022 · 2 comments · Fixed by #7594
Closed

argo CLI list command results not predictable with -o name flag #7581

samene opened this issue Jan 19, 2022 · 2 comments · Fixed by #7594
Assignees
Labels

Comments

@samene
Copy link

samene commented Jan 19, 2022

Summary

Using argo CLI I want keep the latest 20 workflows and delete the rest. This runs in a cron job (not argo cron job, normal linux cron)

When I do this

argo list -n argo --no-headers  | tail -n 6
patch-generator-basic-c2pc5      Succeeded   15d   3m   0
patch-generator-basic-vxj92      Succeeded   15d   3m   0
patch-generator-basic-6db47      Succeeded   15d   2m   0
patch-generator-basic-wcwkb      Succeeded   19d   2m   0
patch-generator-basic-tgpqf      Succeeded   20d   2m   0
patch-generator-basic-ldsrb      Succeeded   20d   2m   0

and when I do it with -o name, I get different result

argo list -n argo --no-headers -o name | tail -n 6
patch-generator-basic-6db47
patch-generator-basic-ccklj
patch-generator-basic-tgpqf
patch-generator-basic-mc2bp
patch-generator-advanced-rm76g
patch-generator-basic-vtknt

As you can see both return a different list.

Is there a way to sort the output of argo list in order of creation time? Why ordering is different when -o name is used.

Version: v3.2.4
Kubernetes: v1.21.2
Docker: 20.10.7

@alexec
Copy link
Contributor

alexec commented Jan 19, 2022

This should be the case already:

sort.Sort(workflows)

Can you please make sure you're running the latest version of the CLI?

@dinever
Copy link
Member

dinever commented Jan 20, 2022

Looks like this issue exists in the latest version.

sort.Sort(workflows) will sort the workflows by their CreationTimestamp and FinishedAt:

func (w Workflows) Less(i, j int) bool {
iStart := w[i].ObjectMeta.CreationTimestamp
iFinish := w[i].Status.FinishedAt
jStart := w[j].ObjectMeta.CreationTimestamp
jFinish := w[j].Status.FinishedAt
if iFinish.IsZero() && jFinish.IsZero() {
return !iStart.Before(&jStart)
}
if iFinish.IsZero() && !jFinish.IsZero() {
return true
}
if !iFinish.IsZero() && jFinish.IsZero() {
return false
}
return jFinish.Before(&iFinish)
}

When we list workflows with -o name, these timestamps won't be selected by the field selector, so the workflows we got all have 0001-01-01 00:00:00 +0000 UTC timestamps, making the sorting inconsistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants