Skip to content

Commit

Permalink
chore: Pass cron schedule to workflow (#5138)
Browse files Browse the repository at this point in the history
Signed-off-by: Saravanan Balasubramanian <sarabala1979@gmail.com>
  • Loading branch information
sarabala1979 committed Mar 1, 2021
1 parent e6fa41a commit b59c8eb
Show file tree
Hide file tree
Showing 20 changed files with 684 additions and 494 deletions.
4 changes: 4 additions & 0 deletions api/jsonschema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,10 @@
"io.argoproj.workflow.v1alpha1.SubmitOpts": {
"description": "SubmitOpts are workflow submission options",
"properties": {
"annotations": {
"description": "Annotations adds to metadata.labels",
"type": "string"
},
"dryRun": {
"description": "DryRun validates the workflow on the client-side without creating it. This option is not supported in API",
"type": "boolean"
Expand Down
4 changes: 4 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7954,6 +7954,10 @@
"description": "SubmitOpts are workflow submission options",
"type": "object",
"properties": {
"annotations": {
"description": "Annotations adds to metadata.labels",
"type": "string"
},
"dryRun": {
"description": "DryRun validates the workflow on the client-side without creating it. This option is not supported in API",
"type": "boolean"
Expand Down
28 changes: 20 additions & 8 deletions cmd/argo/commands/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package commands

import (
"context"
"fmt"
"os"
"strings"
"time"

"github.com/argoproj/pkg/errors"
argoJson "github.com/argoproj/pkg/json"
Expand All @@ -21,14 +23,15 @@ import (

// cliSubmitOpts holds submission options specific to CLI submission (e.g. controlling output)
type cliSubmitOpts struct {
output string // --output
wait bool // --wait
watch bool // --watch
verify bool // --verify
log bool // --log
strict bool // --strict
priority *int32 // --priority
getArgs getFlags
output string // --output
wait bool // --wait
watch bool // --watch
verify bool // --verify
log bool // --log
strict bool // --strict
priority *int32 // --priority
getArgs getFlags
scheduledTime string // --scheduled-time
}

func NewSubmitCommand() *cobra.Command {
Expand Down Expand Up @@ -96,6 +99,8 @@ func NewSubmitCommand() *cobra.Command {
command.Flags().StringVar(&from, "from", "", "Submit from an existing `kind/name` E.g., --from=cronwf/hello-world-cwf")
command.Flags().StringVar(&cliSubmitOpts.getArgs.status, "status", "", "Filter by status (Pending, Running, Succeeded, Skipped, Failed, Error). Should only be used with --watch.")
command.Flags().StringVar(&cliSubmitOpts.getArgs.nodeFieldSelectorString, "node-field-selector", "", "selector of node to display, eg: --node-field-selector phase=abc")
command.Flags().StringVar(&cliSubmitOpts.scheduledTime, "scheduled-time", "", "Override the workflow's scheduledTime parameter (useful for backfilling). The time must be RFC3339")

// Only complete files with appropriate extension.
err := command.Flags().SetAnnotation("parameter-file", cobra.BashCompFilenameExt, []string{"json", "yaml", "yml"})
if err != nil {
Expand Down Expand Up @@ -169,6 +174,13 @@ func submitWorkflowFromResource(ctx context.Context, serviceClient workflowpkg.W
tempwf := wfv1.Workflow{}

validateOptions([]wfv1.Workflow{tempwf}, submitOpts, cliOpts)
if cliOpts.scheduledTime != "" {
_, err := time.Parse(time.RFC3339, cliOpts.scheduledTime)
if err != nil {
log.Fatalf("scheduled-time contains invalid time.RFC3339 format. (e.g.: `2006-01-02T15:04:05-07:00`)")
}
submitOpts.Annotations = fmt.Sprintf("%s=%s", common.AnnotationKeyCronWfScheduledTime, cliOpts.scheduledTime)
}

created, err := serviceClient.SubmitWorkflow(ctx, &workflowpkg.WorkflowSubmitRequest{
Namespace: namespace,
Expand Down
1 change: 1 addition & 0 deletions docs/cli/argo_submit.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ argo submit [FILE... | --from `kind/name] [flags]
-p, --parameter stringArray pass an input parameter
-f, --parameter-file string pass a file containing all input parameters
--priority int32 workflow priority
--scheduled-time string Override the workflow's scheduledTime parameter (useful for backfilling). The time must be RFC3339
--server-dry-run send request to server with dry-run flag which will modify the workflow without creating it
--serviceaccount string run all pods in the workflow using specified serviceaccount
--status string Filter by status (Pending, Running, Succeeded, Skipped, Failed, Error). Should only be used with --watch.
Expand Down
1 change: 1 addition & 0 deletions docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ For `Template`-level metrics:
| `workflow.creationTimestamp.<STRFTIMECHAR>` | Creation timestamp formatted with a [strftime](http://strftime.org) format character |
| `workflow.priority` | Workflow priority |
| `workflow.duration` | Workflow duration estimate, may differ from actual duration by a couple of seconds |
| `workflow.scheduledTime` | Scheduled runtime formatted in RFC 3339 (only available for CronWorkflows) |

### Exit Handler

Expand Down
2 changes: 1 addition & 1 deletion examples/cron-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ spec:
container:
image: docker/whalesay:latest
command: [cowsay]
args: ["🕓 hello world"]
args: ["🕓 hello world. Scheduled on: {{workflow.scheduledTime}}"]
2 changes: 2 additions & 0 deletions pkg/apis/workflow/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ type SubmitOpts struct {
Labels string `json:"labels,omitempty" protobuf:"bytes,10,opt,name=labels"`
// OwnerReference creates a metadata.ownerReference
OwnerReference *metav1.OwnerReference `json:"ownerReference,omitempty" protobuf:"bytes,11,opt,name=ownerReference"`
// Annotations adds to metadata.labels
Annotations string `json:"annotations,omitempty" protobuf:"bytes,12,opt,name=annotations"`
}
Loading

0 comments on commit b59c8eb

Please sign in to comment.