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

feat(cli): add archive resubmit command. Fixes #7910 #8166

Merged
merged 10 commits into from
Mar 23, 2022
248 changes: 0 additions & 248 deletions cmd/argo/commands/archive/common.go

This file was deleted.

19 changes: 10 additions & 9 deletions cmd/argo/commands/archive/resubmit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"k8s.io/apimachinery/pkg/types"

client "github.com/argoproj/argo-workflows/v3/cmd/argo/commands/client"
"github.com/argoproj/argo-workflows/v3/cmd/argo/commands/common"
workflowpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflow"
workflowarchivepkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflowarchive"
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
Expand All @@ -33,7 +34,7 @@ func (o *resubmitOps) hasSelector() bool {
func NewResubmitCommand() *cobra.Command {
var (
resubmitOpts resubmitOps
cliSubmitOpts cliSubmitOpts
cliSubmitOpts common.CliSubmitOpts
)
command := &cobra.Command{
Use: "resubmit [WORKFLOW...]",
Expand Down Expand Up @@ -68,7 +69,7 @@ func NewResubmitCommand() *cobra.Command {
`,
Run: func(cmd *cobra.Command, args []string) {
if cmd.Flag("priority").Changed {
cliSubmitOpts.priority = &resubmitOpts.priority
cliSubmitOpts.Priority = &resubmitOpts.priority
}

ctx, apiClient := client.NewAPIClient(cmd.Context())
Expand All @@ -82,18 +83,18 @@ func NewResubmitCommand() *cobra.Command {
}

command.Flags().Int32Var(&resubmitOpts.priority, "priority", 0, "workflow priority")
command.Flags().StringVarP(&cliSubmitOpts.output, "output", "o", "", "Output format. One of: name|json|yaml|wide")
command.Flags().BoolVarP(&cliSubmitOpts.wait, "wait", "w", false, "wait for the workflow to complete, only works when a single workflow is resubmitted")
command.Flags().BoolVar(&cliSubmitOpts.watch, "watch", false, "watch the workflow until it completes, only works when a single workflow is resubmitted")
command.Flags().BoolVar(&cliSubmitOpts.log, "log", false, "log the workflow until it completes")
command.Flags().StringVarP(&cliSubmitOpts.Output, "output", "o", "", "Output format. One of: name|json|yaml|wide")
command.Flags().BoolVarP(&cliSubmitOpts.Wait, "wait", "w", false, "wait for the workflow to complete, only works when a single workflow is resubmitted")
command.Flags().BoolVar(&cliSubmitOpts.Watch, "watch", false, "watch the workflow until it completes, only works when a single workflow is resubmitted")
command.Flags().BoolVar(&cliSubmitOpts.Log, "log", false, "log the workflow until it completes")
command.Flags().BoolVar(&resubmitOpts.memoized, "memoized", false, "re-use successful steps & outputs from the previous run")
command.Flags().StringVarP(&resubmitOpts.labelSelector, "selector", "l", "", "Selector (label query) to filter on, not including uninitialized ones, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
command.Flags().StringVar(&resubmitOpts.fieldSelector, "field-selector", "", "Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.")
return command
}

// resubmitWorkflows resubmits workflows by given resubmitOpts or workflow names
func resubmitArchivedWorkflows(ctx context.Context, archiveServiceClient workflowarchivepkg.ArchivedWorkflowServiceClient, serviceClient workflowpkg.WorkflowServiceClient, resubmitOpts resubmitOps, cliSubmitOpts cliSubmitOpts, args []string) error {
func resubmitArchivedWorkflows(ctx context.Context, archiveServiceClient workflowarchivepkg.ArchivedWorkflowServiceClient, serviceClient workflowpkg.WorkflowServiceClient, resubmitOpts resubmitOps, cliSubmitOpts common.CliSubmitOpts, args []string) error {
var (
wfs wfv1.Workflows
err error
Expand Down Expand Up @@ -134,12 +135,12 @@ func resubmitArchivedWorkflows(ctx context.Context, archiveServiceClient workflo
if err != nil {
return err
}
printWorkflow(lastResubmitted, cliSubmitOpts.output)
printWorkflow(lastResubmitted, cliSubmitOpts.Output)
}

if len(resubmittedUids) == 1 {
// watch or wait when there is only one workflow retried
waitWatchOrLog(ctx, serviceClient, lastResubmitted.Namespace, []string{lastResubmitted.Name}, cliSubmitOpts)
common.WaitWatchOrLog(ctx, serviceClient, lastResubmitted.Namespace, []string{lastResubmitted.Name}, cliSubmitOpts)
}
return nil
}
28 changes: 14 additions & 14 deletions cmd/argo/commands/common.go → cmd/argo/commands/common/common.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package common

import (
"fmt"
Expand All @@ -14,11 +14,11 @@ import (

// Global variables
var (
jobStatusIconMap map[wfv1.NodePhase]string
nodeTypeIconMap map[wfv1.NodeType]string
workflowConditionIconMap map[wfv1.ConditionType]string
noColor bool
noUtf8 bool
JobStatusIconMap map[wfv1.NodePhase]string
NodeTypeIconMap map[wfv1.NodeType]string
WorkflowConditionIconMap map[wfv1.ConditionType]string
NoColor bool
NoUtf8 bool
)

func init() {
Expand Down Expand Up @@ -46,35 +46,35 @@ func initializeSession() {
TimestampFormat: "2006-01-02T15:04:05.000Z",
FullTimestamp: true,
})
if noUtf8 {
jobStatusIconMap = map[wfv1.NodePhase]string{
if NoUtf8 {
JobStatusIconMap = map[wfv1.NodePhase]string{
wfv1.NodePending: ansiFormat("Pending", FgYellow),
wfv1.NodeRunning: ansiFormat("Running", FgCyan),
wfv1.NodeSucceeded: ansiFormat("Succeeded", FgGreen),
wfv1.NodeSkipped: ansiFormat("Skipped", FgDefault),
wfv1.NodeFailed: ansiFormat("Failed", FgRed),
wfv1.NodeError: ansiFormat("Error", FgRed),
}
nodeTypeIconMap = map[wfv1.NodeType]string{
NodeTypeIconMap = map[wfv1.NodeType]string{
wfv1.NodeTypeSuspend: ansiFormat("Suspend", FgCyan),
}
workflowConditionIconMap = map[wfv1.ConditionType]string{
WorkflowConditionIconMap = map[wfv1.ConditionType]string{
wfv1.ConditionTypeMetricsError: ansiFormat("Error", FgRed),
wfv1.ConditionTypeSpecWarning: ansiFormat("Warning", FgYellow),
}
} else {
jobStatusIconMap = map[wfv1.NodePhase]string{
JobStatusIconMap = map[wfv1.NodePhase]string{
wfv1.NodePending: ansiFormat("◷", FgYellow),
wfv1.NodeRunning: ansiFormat("●", FgCyan),
wfv1.NodeSucceeded: ansiFormat("✔", FgGreen),
wfv1.NodeSkipped: ansiFormat("○", FgDefault),
wfv1.NodeFailed: ansiFormat("✖", FgRed),
wfv1.NodeError: ansiFormat("⚠", FgRed),
}
nodeTypeIconMap = map[wfv1.NodeType]string{
NodeTypeIconMap = map[wfv1.NodeType]string{
wfv1.NodeTypeSuspend: ansiFormat("ǁ", FgCyan),
}
workflowConditionIconMap = map[wfv1.ConditionType]string{
WorkflowConditionIconMap = map[wfv1.ConditionType]string{
wfv1.ConditionTypeMetricsError: ansiFormat("✖", FgRed),
wfv1.ConditionTypeSpecWarning: ansiFormat("⚠", FgYellow),
}
Expand All @@ -98,7 +98,7 @@ func ansiColorCode(s string) int {
// color, it provides more consistent string lengths so that tabwriter can calculate
// widths correctly.
func ansiFormat(s string, codes ...int) string {
if noColor || os.Getenv("TERM") == "dumb" || len(codes) == 0 {
if NoColor || os.Getenv("TERM") == "dumb" || len(codes) == 0 {
return s
}
codeStrs := make([]string, len(codes))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package common

import (
"testing"
Expand Down
Loading