-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
feat(cli): add archive resubmit
command. Fixes #7910
#8166
Conversation
Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
cmd/argo/commands/archive/common.go
Outdated
log bool // --log | ||
} | ||
|
||
func waitWatchOrLog(ctx context.Context, serviceClient workflowpkg.WorkflowServiceClient, namespace string, workflowNames []string, cliSubmitOpts cliSubmitOpts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like copy-and-paste?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't possible to use the functions like waitWatchorLog
without a cycle error and this keeps us from having the same functionality as argo resubmit
with support for these flags. Bala and I's solution was to move these functions we need to a common.go
to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if you make the func s public, and then move to a new package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that, would we move all the command files into a new package then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, just the shared code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still needs doing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can move the functions required for waitWatchOrLog
to a new package in cmd/argo/commands
called util
:
Files / functions needed:
wait.go
// waitWorkflows waits for the given workflowNames.
func WaitWorkflows(ctx context.Context, serviceClient workflowpkg.WorkflowServiceClient, namespace string, workflowNames []string, ignoreNotFound, quiet bool) {
var wg sync.WaitGroup
wfSuccessStatus := true
for _, name := range workflowNames {
wg.Add(1)
go func(name string) {
if !waitOnOne(serviceClient, ctx, name, namespace, ignoreNotFound, quiet) {
wfSuccessStatus = false
}
wg.Done()
}(name)
}
wg.Wait()
if !wfSuccessStatus {
os.Exit(1)
}
}
func waitOnOne(serviceClient workflowpkg.WorkflowServiceClient, ctx context.Context, wfName, namespace string, ignoreNotFound, quiet bool) bool {
req := &workflowpkg.WatchWorkflowsRequest{
Namespace: namespace,
ListOptions: &metav1.ListOptions{
FieldSelector: util.GenerateFieldSelectorFromWorkflowName(wfName),
ResourceVersion: "0",
},
}
stream, err := serviceClient.WatchWorkflows(ctx, req)
if err != nil {
if status.Code(err) == codes.NotFound && ignoreNotFound {
return true
}
errors.CheckError(err)
return false
}
for {
event, err := stream.Recv()
if err == io.EOF {
log.Debug("Re-establishing workflow watch")
stream, err = serviceClient.WatchWorkflows(ctx, req)
errors.CheckError(err)
continue
}
errors.CheckError(err)
if event == nil {
continue
}
wf := event.Object
if !wf.Status.FinishedAt.IsZero() {
if !quiet {
fmt.Printf("%s %s at %v\n", wfName, wf.Status.Phase, wf.Status.FinishedAt)
}
if wf.Status.Phase == wfv1.WorkflowFailed || wf.Status.Phase == wfv1.WorkflowError {
return false
}
return true
}
}
}
watch.go
func WatchWorkflow(ctx context.Context, serviceClient workflowpkg.WorkflowServiceClient, namespace string, workflow string, getArgs getFlags) {
req := &workflowpkg.WatchWorkflowsRequest{
Namespace: namespace,
ListOptions: &metav1.ListOptions{
FieldSelector: util.GenerateFieldSelectorFromWorkflowName(workflow),
ResourceVersion: "0",
},
}
stream, err := serviceClient.WatchWorkflows(ctx, req)
errors.CheckError(err)
wfChan := make(chan *wfv1.Workflow)
go func() {
for {
event, err := stream.Recv()
if err == io.EOF {
log.Debug("Re-establishing workflow watch")
stream, err = serviceClient.WatchWorkflows(ctx, req)
errors.CheckError(err)
continue
}
errors.CheckError(err)
if event == nil {
continue
}
wfChan <- event.Object
}
}()
var wf *wfv1.Workflow
ticker := time.NewTicker(time.Second)
for {
select {
case newWf := <-wfChan:
// If we get a new event, update our workflow
if newWf == nil {
return
}
wf = newWf
case <-ticker.C:
// If we don't, refresh the workflow screen every second
case <-ctx.Done():
// When the context gets canceled
return
}
printWorkflowStatus(wf, getArgs)
if wf != nil && !wf.Status.FinishedAt.IsZero() {
return
}
}
}
func printWorkflowStatus(wf *wfv1.Workflow, getArgs getFlags) {
if wf == nil {
return
}
err := packer.DecompressWorkflow(wf)
errors.CheckError(err)
print("\033[H\033[2J")
print("\033[0;0H")
fmt.Print(PrintWorkflowHelper(wf, getArgs))
}
logs.go
func LogWorkflow(ctx context.Context, serviceClient workflowpkg.WorkflowServiceClient, namespace, workflow, podName, grep, selector string, logOptions *corev1.PodLogOptions) {
// logs
stream, err := serviceClient.WorkflowLogs(ctx, &workflowpkg.WorkflowLogRequest{
Name: workflow,
Namespace: namespace,
PodName: podName,
LogOptions: logOptions,
Selector: selector,
Grep: grep,
})
errors.CheckError(err)
// loop on log lines
for {
event, err := stream.Recv()
if err == io.EOF {
return
}
errors.CheckError(err)
fmt.Println(ansiFormat(fmt.Sprintf("%s: %s", event.PodName, event.Content), ansiColorCode(event.PodName)))
}
}
It would be necessary for get.go
to be included for printWorkflowHelper
and getFlags
struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed with @sarabala1979: will rename package to common
since util
isn't meant for these workflow functions, will also move common.go
into this package
…r archive Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
Head branch was pushed to by a user without write access
Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 🥇 good work!
…rgoproj#8166) Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
archive resubmit
command. Fixes #7910
Fixes #7910
It is currently only possible for an archived workflow to be resubmitted through the CLI by using
kubectl create
thenargo resubmit
. This feature removes the need to do this set of operations by resubmitting workflows directly from the archive with the argo CLI:argo archive resubmit {uid}
. This cli command supports the same field selector, label selector and wait, watch or log flags asargo resubmit
.Example archive with
examples/hello-world.yaml
andexamples/http-hello-world.yaml
:Resubmitting one workflow:
dist/argo archive resubmit 962342ce-a54d-4a71-aff8-a3a4aad85158
Resubmitting multiple workflows:
dist/argo archive resubmit 962342ce-a54d-4a71-aff8-a3a4aad85158 36077313-3c04-4ffc-89ac-eb8ee2aac41f
Resubmitting one workflow with
--watch
:dist/argo archive resubmit 962342ce-a54d-4a71-aff8-a3a4aad85158 --watch
Resubmitting workflows with label selector:
dist/argo archive resubmit -l workflows.argoproj.io/test=true
Resubmitting workflows with field selector:
dist/argo archive resubmit --field-selector metadata.namespace=argo