Skip to content

Commit

Permalink
feat: add stopStrategy to cron workflows (#12305)
Browse files Browse the repository at this point in the history
Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
  • Loading branch information
eduardodbr committed Jan 16, 2024
1 parent 3931e59 commit 4f4d315
Show file tree
Hide file tree
Showing 24 changed files with 1,772 additions and 754 deletions.
34 changes: 33 additions & 1 deletion api/jsonschema/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,7 @@ CronWorkflowSpec is the specification of a CronWorkflow
|`failedJobsHistoryLimit`|`integer`|FailedJobsHistoryLimit is the number of failed jobs to be kept at a time|
|`schedule`|`string`|Schedule is a schedule to run the Workflow in Cron format|
|`startingDeadlineSeconds`|`integer`|StartingDeadlineSeconds is the K8s-style deadline that will limit the time a CronWorkflow will be run after its original scheduled time if it is missed.|
|`stopStrategy`|[`StopStrategy`](#stopstrategy)|StopStrategy defines if the cron workflow will stop being triggered once a certain condition has been reached, involving a number of runs of the workflow|
|`successfulJobsHistoryLimit`|`integer`|SuccessfulJobsHistoryLimit is the number of successful jobs to be kept at a time|
|`suspend`|`boolean`|Suspend is a flag that will stop new CronWorkflows from running if set to true|
|`timezone`|`string`|Timezone is the timezone against which the cron schedule will be calculated, e.g. "Asia/Tokyo". Default is machine's local time.|
Expand All @@ -1245,7 +1246,10 @@ CronWorkflowStatus is the status of a CronWorkflow
|:----------:|:----------:|---------------|
|`active`|`Array<`[`ObjectReference`](#objectreference)`>`|Active is a list of active workflows stemming from this CronWorkflow|
|`conditions`|`Array<`[`Condition`](#condition)`>`|Conditions is a list of conditions the CronWorkflow may have|
|`failed`|`integer`|Failed is a counter of how many times a child workflow terminated in failed or errored state|
|`lastScheduledTime`|[`Time`](#time)|LastScheduleTime is the last time the CronWorkflow was scheduled|
|`phase`|`string`|Phase defines the cron workflow phase. It is changed to Stopped when the stopping condition is achieved which stops new CronWorkflows from running|
|`succeeded`|`integer`|Succeeded is a counter of how many times the child workflows had success|

## Arguments

Expand Down Expand Up @@ -1930,6 +1934,15 @@ SynchronizationStatus stores the status of semaphore and mutex.
|`mutex`|[`MutexStatus`](#mutexstatus)|Mutex stores this workflow's mutex holder details|
|`semaphore`|[`SemaphoreStatus`](#semaphorestatus)|Semaphore stores this workflow's Semaphore holder details|

## StopStrategy

StopStrategy defines if the cron workflow will stop being triggered once a certain condition has been reached, involving a number of runs of the workflow

### Fields
| Field Name | Field Type | Description |
|:----------:|:----------:|---------------|
|`condition`|`string`|Condition defines a condition that stops scheduling workflows when evaluates to true. Use the keywords `failed` or `succeeded` to access the number of failed or successful child workflows.|

## Artifact

Artifact indicates an artifact to place at a specified path
Expand Down
18 changes: 18 additions & 0 deletions manifests/base/crds/full/argoproj.io_cronworkflows.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions pkg/apis/workflow/v1alpha1/cron_workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ type CronWorkflowSpec struct {
Timezone string `json:"timezone,omitempty" protobuf:"bytes,8,opt,name=timezone"`
// WorkflowMetadata contains some metadata of the workflow to be run
WorkflowMetadata *metav1.ObjectMeta `json:"workflowMetadata,omitempty" protobuf:"bytes,9,opt,name=workflowMeta"`
// StopStrategy defines if the cron workflow will stop being triggered once a certain condition has been reached, involving a number of runs of the workflow
StopStrategy *StopStrategy `json:"stopStrategy,omitempty" protobuf:"bytes,10,opt,name=stopStrategy"`
}

// StopStrategy defines if the cron workflow will stop being triggered once a certain condition has been reached, involving a number of runs of the workflow
type StopStrategy struct {
// Condition defines a condition that stops scheduling workflows when evaluates to true. Use the
// keywords `failed` or `succeeded` to access the number of failed or successful child workflows.
Condition string `json:"condition" protobuf:"bytes,1,opt,name=condition"`
}

// CronWorkflowStatus is the status of a CronWorkflow
Expand All @@ -69,8 +78,21 @@ type CronWorkflowStatus struct {
LastScheduledTime *metav1.Time `json:"lastScheduledTime" protobuf:"bytes,2,opt,name=lastScheduledTime"`
// Conditions is a list of conditions the CronWorkflow may have
Conditions Conditions `json:"conditions" protobuf:"bytes,3,rep,name=conditions"`
// Succeeded is a counter of how many times the child workflows had success
Succeeded int64 `json:"succeeded" protobuf:"varint,4,rep,name=succeeded"`
// Failed is a counter of how many times a child workflow terminated in failed or errored state
Failed int64 `json:"failed" protobuf:"varint,5,rep,name=failed"`
// Phase defines the cron workflow phase. It is changed to Stopped when the stopping condition is achieved which stops new CronWorkflows from running
Phase CronWorkflowPhase `json:"phase" protobuf:"varint,6,rep,name=phase"`
}

type CronWorkflowPhase string

const (
ActivePhase CronWorkflowPhase = "Active"
StoppedPhase CronWorkflowPhase = "Stopped"
)

func (c *CronWorkflow) IsUsingNewSchedule() bool {
lastUsedSchedule, exists := c.Annotations[annotationKeyLatestSchedule]
// If last-used-schedule does not exist, or if it does not match the current schedule then the CronWorkflow schedule
Expand Down
Loading

0 comments on commit 4f4d315

Please sign in to comment.