-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat: Support for scheduled Workflows with CronWorkflow CRD #1758
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
Merged
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
93390b1
WIP: Informer working
simster7 8e63ce2
WIP: Working on cron infra
simster7 8fd042d
WIP: Won't work
simster7 66ab628
WIP: Toy now working
simster7 5d98393
WIP: Object deletion
simster7 c6d65fc
WIP: Trying to make API call
simster7 eb5a0f5
WIP: Can now run WFs
simster7 30b6acf
WIP: Concurrency policy
simster7 5febabd
Merge branch 'master' into cron
simster7 4358994
WIP
simster7 96790cd
Minor
simster7 29165bf
WIP: StartingDeadlineSeconds now works
simster7 8ef1f61
WIP: Fixed startingDeadlineSeconds
simster7 61df6fc
WIP: Minor rework
simster7 0ee7573
WIP: Working on WF informer
simster7 3af4e0e
WIP: Informer working
simster7 2b65ae9
WIP: Major refactor, should be way cleaner now
simster7 5cc826b
Merge branch 'master' into cron
simster7 c1bfe83
WIP: Lint
simster7 67f4ab8
WIP: First CLI commands
simster7 acb4188
WIP: Almost done with CLI
simster7 0d2dce0
Done with CLI
simster7 d129c99
WIP
simster7 b55b6a1
Merge branch 'master' into cron
simster7 2e7b2ab
WIP: Reworked parent/child relationship
simster7 497a168
WIP: Lint
simster7 82c692c
WIP: Removing from Active now works
simster7 9c26d27
WIP: Remove runtimeGenerateName
simster7 9ac51b4
MVP Done
simster7 220f2eb
Lint
simster7 6f52a21
Merge branch 'master' into cron
simster7 bcc35e8
Move Options under Spec and Spec under WorkflowSpec
simster7 d45902c
Merge branch 'master' into cron
simster7 4c4d618
WIP: History limit
simster7 e89b4bb
{successful,failed}JobsHistoryLimit
simster7 35bc731
Fix validation bug
simster7 f6513c6
Merge branch 'master' into cron
alexec 71d073b
make codegen manifests
alexec 134f573
Alex's comments
simster7 aabdc66
Merge branch 'master' into cron
simster7 16789f3
WIP
simster7 ec1d26c
Added tests
simster7 192ac2d
Enhanced test
simster7 6c43791
Test fixes
simster7 98d7905
Rename function
simster7 cc7af61
Merge branch 'master' into cron
simster7 c4ec587
Run CronWorkflow test
simster7 898f6dd
Run tests in parallel
simster7 b3f244a
No parallel tests
simster7 25a035f
Potential fix to test
simster7 2f6bec2
Increase e2e timeout
simster7 2c4c7a6
Increase e2e timeout
simster7 43ba51f
Merge branch 'master' into cron
simster7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package cron | ||
|
|
||
| import ( | ||
| wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1" | ||
| "github.com/argoproj/argo/workflow/templateresolution" | ||
| "log" | ||
|
|
||
| "github.com/argoproj/argo/pkg/client/clientset/versioned" | ||
| "github.com/argoproj/argo/pkg/client/clientset/versioned/typed/workflow/v1alpha1" | ||
| "k8s.io/client-go/kubernetes" | ||
| "k8s.io/client-go/rest" | ||
| "k8s.io/client-go/tools/clientcmd" | ||
| ) | ||
|
|
||
| // Global variables | ||
| var ( | ||
| restConfig *rest.Config | ||
| clientConfig clientcmd.ClientConfig | ||
| clientset *kubernetes.Clientset | ||
| wfClientset *versioned.Clientset | ||
| cronWfClient v1alpha1.CronWorkflowInterface | ||
| wftmplClient v1alpha1.WorkflowTemplateInterface | ||
| namespace string | ||
| ) | ||
|
|
||
| func initKubeClient() *kubernetes.Clientset { | ||
| if clientset != nil { | ||
| return clientset | ||
| } | ||
| var err error | ||
| restConfig, err = clientConfig.ClientConfig() | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| // create the clientset | ||
| clientset, err = kubernetes.NewForConfig(restConfig) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| return clientset | ||
| } | ||
|
|
||
| // InitCronWorkflowClient creates a new client for the Kubernetes WorkflowTemplate CRD. | ||
| func InitCronWorkflowClient(ns ...string) v1alpha1.CronWorkflowInterface { | ||
| if cronWfClient != nil { | ||
| return cronWfClient | ||
| } | ||
| initKubeClient() | ||
| var err error | ||
| if len(ns) > 0 { | ||
| namespace = ns[0] | ||
| } else { | ||
| namespace, _, err = clientConfig.Namespace() | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| } | ||
| wfClientset = versioned.NewForConfigOrDie(restConfig) | ||
| cronWfClient = wfClientset.ArgoprojV1alpha1().CronWorkflows(namespace) | ||
| wftmplClient = wfClientset.ArgoprojV1alpha1().WorkflowTemplates(namespace) | ||
| return cronWfClient | ||
| } | ||
|
|
||
| // LazyWorkflowTemplateGetter is a wrapper of v1alpha1.WorkflowTemplateInterface which | ||
| // supports lazy initialization. | ||
| type LazyWorkflowTemplateGetter struct{} | ||
|
|
||
| // Get initializes it just before it's actually used and returns a retrieved workflow template. | ||
| func (c LazyWorkflowTemplateGetter) Get(name string) (*wfv1.WorkflowTemplate, error) { | ||
| if wftmplClient == nil { | ||
| _ = InitCronWorkflowClient() | ||
| } | ||
| return templateresolution.WrapWorkflowTemplateInterface(wftmplClient).Get(name) | ||
| } | ||
|
|
||
| var _ templateresolution.WorkflowTemplateNamespacedGetter = &LazyWorkflowTemplateGetter{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package cron | ||
|
|
||
| import ( | ||
| "github.com/argoproj/argo/workflow/templateresolution" | ||
| "log" | ||
| "os" | ||
|
|
||
| "github.com/argoproj/pkg/json" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1" | ||
| "github.com/argoproj/argo/workflow/common" | ||
| "github.com/argoproj/argo/workflow/util" | ||
| "github.com/argoproj/argo/workflow/validate" | ||
| ) | ||
|
|
||
| type cliCreateOpts struct { | ||
| output string // --output | ||
| strict bool // --strict | ||
| } | ||
|
|
||
| func NewCreateCommand() *cobra.Command { | ||
| var ( | ||
| cliCreateOpts cliCreateOpts | ||
| ) | ||
| var command = &cobra.Command{ | ||
| Use: "create FILE1 FILE2...", | ||
| Short: "create a cron workflow", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| if len(args) == 0 { | ||
| cmd.HelpFunc()(cmd, args) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| CreateCronWorkflows(args, &cliCreateOpts) | ||
| }, | ||
| } | ||
| command.Flags().StringVarP(&cliCreateOpts.output, "output", "o", "", "Output format. One of: name|json|yaml|wide") | ||
| command.Flags().BoolVar(&cliCreateOpts.strict, "strict", true, "perform strict workflow validation") | ||
| return command | ||
| } | ||
|
|
||
| func CreateCronWorkflows(filePaths []string, cliOpts *cliCreateOpts) { | ||
| defaultCronWfClient := InitCronWorkflowClient() | ||
|
|
||
| fileContents, err := util.ReadManifest(filePaths...) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| var cronWorkflows []wfv1.CronWorkflow | ||
| for _, body := range fileContents { | ||
| cronWfs := unmarshalCronWorkflows(body, cliOpts.strict) | ||
| cronWorkflows = append(cronWorkflows, cronWfs...) | ||
| } | ||
|
|
||
| if len(cronWorkflows) == 0 { | ||
| log.Println("No CronWorkflows found in given files") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| for _, cronWf := range cronWorkflows { | ||
| wftmplGetter := templateresolution.WrapWorkflowTemplateInterface(wftmplClient) | ||
| err := validate.ValidateCronWorkflow(wftmplGetter, &cronWf) | ||
| if err != nil { | ||
| log.Fatalf("Failed to validate cron workflow: %v", err) | ||
| } | ||
| cronWfClient := defaultCronWfClient | ||
| if cronWf.Namespace != "" { | ||
| cronWfClient = InitCronWorkflowClient(cronWf.Namespace) | ||
| } | ||
| created, err := cronWfClient.Create(&cronWf) | ||
| if err != nil { | ||
| log.Fatalf("Failed to create workflow template: %v", err) | ||
| } | ||
| printCronWorkflowTemplate(created, cliOpts.output) | ||
| } | ||
| } | ||
|
|
||
| // unmarshalCronWorkflows unmarshals the input bytes as either json or yaml | ||
| func unmarshalCronWorkflows(wfBytes []byte, strict bool) []wfv1.CronWorkflow { | ||
| var cronWf wfv1.CronWorkflow | ||
| var jsonOpts []json.JSONOpt | ||
| if strict { | ||
| jsonOpts = append(jsonOpts, json.DisallowUnknownFields) | ||
| } | ||
| err := json.Unmarshal(wfBytes, &cronWf, jsonOpts...) | ||
| if err == nil { | ||
| return []wfv1.CronWorkflow{cronWf} | ||
| } | ||
| yamlWfs, err := common.SplitCronWorkflowYAMLFile(wfBytes, strict) | ||
| if err == nil { | ||
| return yamlWfs | ||
| } | ||
| log.Fatalf("Failed to parse workflow template: %v", err) | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package cron | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| "github.com/argoproj/argo/pkg/client/clientset/versioned/typed/workflow/v1alpha1" | ||
| ) | ||
|
|
||
| // NewDeleteCommand returns a new instance of an `argo delete` command | ||
| func NewDeleteCommand() *cobra.Command { | ||
| var ( | ||
| all bool | ||
| ) | ||
|
|
||
| var command = &cobra.Command{ | ||
| Use: "delete CRON_WORKFLOW", | ||
| Short: "delete a cron workflow", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| cronWfClient := InitCronWorkflowClient() | ||
| if all { | ||
| deleteCronWorkflows(cronWfClient, metav1.ListOptions{}) | ||
| } else { | ||
| if len(args) == 0 { | ||
| cmd.HelpFunc()(cmd, args) | ||
| os.Exit(1) | ||
| } | ||
| for _, wftmplName := range args { | ||
| deleCronWorkflow(cronWfClient, wftmplName) | ||
| } | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| command.Flags().BoolVar(&all, "all", false, "Delete all workflow templates") | ||
| return command | ||
| } | ||
|
|
||
| func deleCronWorkflow(cronWfClient v1alpha1.CronWorkflowInterface, cronWf string) { | ||
| err := cronWfClient.Delete(cronWf, &metav1.DeleteOptions{}) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| fmt.Printf("CronWorkflow '%s' deleted\n", cronWf) | ||
| } | ||
|
|
||
| func deleteCronWorkflows(cronWfClient v1alpha1.CronWorkflowInterface, options metav1.ListOptions) { | ||
| cronWfList, err := cronWfClient.List(options) | ||
| if err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| for _, cronWf := range cronWfList.Items { | ||
| deleCronWorkflow(cronWfClient, cronWf.ObjectMeta.Name) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.