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(cron): allow multiple schedules #12616

Merged
merged 9 commits into from
Feb 19, 2024

Conversation

eduardodbr
Copy link
Member

@eduardodbr eduardodbr commented Feb 4, 2024

Fixes: #12493
Fixes: #9734

Motivation

This PR introduces a new CronWorkflow spec field Schedules, a list of cron schedules for a workflow to execute. It maintains backward compatibility with Spec.Schedule and adds a validation that ensures that both fields cannot be configured simultaneously.

Modifications

Controller

1 - This implementation tries to maintain the same behavior for the controller and operator. This biggest change was made to the cronFacadewhere a key can hold multiple cron entries instead of only one. This involved changing the signature for the method Load to return an array of cronWfOperationCtx since a key can hold multiple entries:

 func (f *cronFacade) Load(key string) ([]*cronWfOperationCtx, error). 

This method doesn't seem to be used anywhere and cronFacede is not exposed so I don't think there is any issue with this change. Let me know if you think otherwise.

2 - The controller is currently using the label cronworkflows.argoproj.io/last-used-schedule to store the current cron expression. This label is only used to check whether the cron expression has been updated since the last time the WF ran, so this PR changes it to be a comma-separated list of the schedules (if applicable). Whenever any of the schedules is updated the label will be changed.

Possible Issues

If two cron expressions overlap (for example the expressions */2 * * * * and */3 * * * * will overlap at minute 6,12,18,etc) only one WF will be executed because the second will be seen as a duplicate submission. I don't think there is an issue with this, but let me know if you think otherwise. This makes it a bit harder to create an E2E test that is deterministic. Because of that, I decided to not add an E2E test for this feature.

CLI

argo cron list was updated to show all schedules:

image

argo cron get was updated:

image

UI

NOTE: this is my first time ever doing react /typescript it is expected that the code lacks quality. Please suggest changes.

Cron Workflow list was updated to show all schedules:
image

Cron Workflow status viewer was also updated:

image

Cron Spec editor:

image

Verification

This change can be tested with the following cron workflow:

apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
  name: test-cron
spec:
  schedules:
  - "*/2 * * * *"
  - "*/3 * * * *"
  concurrencyPolicy: "Allow"
  startingDeadlineSeconds: 0
  workflowSpec:
    entrypoint: whalesay
    templates:
    - name: whalesay
      container:
        image: alpine:3.6
        command: [sh, -c]
        args: ["date; sleep 1"]

Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
@eduardodbr
Copy link
Member Author

CI is failing because of #12596

Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
@isubasinghe isubasinghe self-assigned this Feb 8, 2024
@tooptoop4
Copy link
Contributor

:shipit:

Copy link
Member

@terrytangyuan terrytangyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
Copy link
Member

@terrytangyuan terrytangyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once conflicts are resolved

Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
@terrytangyuan terrytangyuan merged commit 986b069 into argoproj:main Feb 19, 2024
27 checks passed
Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: this is my first time ever doing react /typescript it is expected that the code lacks quality. Please suggest changes.

This seems to have not gotten a UI SME before merge. It's mostly good, but I left a few comments on improvements below. In particular, the possible unnecessary new line when schedules contains only a single schedule is something to check

Comment on lines +171 to +174
<>
<PrettySchedule schedule={schedule} />
<br />
</>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that most of these instances can be simplified with a <p> paragraph element instead of a <> fragment + a <br /> line break

Suggested change
<>
<PrettySchedule schedule={schedule} />
<br />
</>
<p><PrettySchedule schedule={schedule} /></p>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also how does this look when schedules only contains a single schedule? It seems like there may be an unnecessary new line in that case since it is currently treated differently from schedule

Copy link
Member Author

@eduardodbr eduardodbr Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this suggestion and it seems that replacing <> <br /> </> with:

  <p>
      <PrettySchedule schedule={schedule} />
  </p>

seems to be adding an unnecessary new line after the last schedule, as you can see here:

image

while the current behavior is shown as:

image

no new line

Copy link
Member

@agilgur5 agilgur5 Feb 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm we use <p> elements in the new markdown title & description feature. Might need to add similar CSS here (line-height, display, and vertical-align). That and it might not work properly if one column uses <p> while the other uses <br />.

Try that; if it doesn't work, I can take a look on my side

ui/src/models/cron-workflows.ts Show resolved Hide resolved
Comment on lines +159 to +162
<>
{schedule}
<br />
</>
Copy link
Member

@agilgur5 agilgur5 Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<>
{schedule}
<br />
</>
<p>{schedule}</p>

same as above

Comment on lines +28 to +31
<>
<code>{schedule}</code> <PrettySchedule schedule={schedule} />
<br />
</>
Copy link
Member

@agilgur5 agilgur5 Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<>
<code>{schedule}</code> <PrettySchedule schedule={schedule} />
<br />
</>
<p><code>{schedule}</code> <PrettySchedule schedule={schedule} /><p/>

same as above

Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also clients (CLI and UI) should probably have updated labels: Schedule -> Schedules.

Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CronWorkflows docs also need updating around multiple schedules, with version specifiers (see #12581 for examples)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants