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
Ability to start CronJobs manually #47538
Comments
Another anti-UX feature is if you change the schedule to something like |
We are searching for kinda the same feature, we would like to be able to start a cronjob the first time after creation. no matter when it would be scheduled normally. |
@dennis-bell You could try a helm post-install hook if you're using helm. Run the job once via that hook then also release a cron job at the same time. |
We are also looking for this feature but for different functionality.
|
This would be also very useful for debugging: When I have to test a cronjob, either I change the schedule to be a few minutes from now and apply it, or I create new YAML file for a pod with the same configuration... both ways are pretty inconvenient. |
It would be really useful to trigger a cronjob manually |
Us as well. I'd like to take a hack at this, though I can't assign it to myself. |
What I'd like to do (after talking the issue over a bit with @ant31) is add an AdhocJob resource type that would reference a particular CronJob for immediate execution, irrespective of the schedule provided for that CronJob. |
@erhudy proposed a new field The shortest path I see would be create A job forked from the cronjob. It could be handled on the cli side to begin:
cc @kubernetes/sig-cli-feature-requests |
Another option could be to allow multiple schedules for a cron job. in that case
|
Based on the above discussion, I hacked together a proof-of-concept at https://github.com/bloomberg/kubernetes/tree/feature/create-ad-hoc-job-from-cronjob. You can execute something like
and it will create blah from the JobSpec in some-cronjob. I feel that this is a sufficient solution and it's not necessary to do anything that would result in API changes, because the nature of this problem is inherently oriented around impromptu testing. If you want to do something in an API-driven way, you can already do that right now by getting the CronJob in question and extracting the JobSpec from it. The POC has the following caveats that I'm aware of:
If people agree that this seems like a workable solution for the problem in question, I'll continue to flesh it out. |
Another option if something needs to run once when an app starts is an init container. @erhudy This is the kind of thing that would be good to discuss at a SIG Apps meeting. If you can find my on slack we can try to work out a time to get you on the schedule. |
So just to let everyone interested know. We've talked with @erhudy about it on slack. My most important suggestion is that this will be a sub-resource on a cronjob (invoke, instantiate or something like that), similar to how you get logs from a pod. This way it'll be accessible to CLI and other consumers of our API. He will be working on updating the cronjob proposal and the implementation. Hopefully, by Oct 16th (when this is planned to be discussed during SIG Apps call) we'll have the proposal out there and we can discuss it in more details. |
Restarted development work at https://github.com/erhudy/kubernetes/tree/feature/cronjob-manual-instantiation - currently functional for spawning a Job. Upcoming work will be on:
|
Automatic merge from submit-queue. Add section on manually triggering CronJobs As requested by @soltysh, in relation to kubernetes/kubernetes#47538.
@erhudy very excited about your work on this. One thing to consider -- we implemented a very hacky version of this internally. Our hacky version doesn't respect the cron job's concurrency policy (so if you start the cronjob manually, starting it will succeed even if another instance is already running). Our users have told us that they find this alarming and that they would prefer that the "manual start" feature respect the cron job's concurrency policy. |
That's how my current implementation works - an I'm totally okay with undertaking the work necessary to ensure that the instantiate action creates a new Job in a safe way that gets associated back to the source CronJob, and that it respects the parallelism/concurrency configurations of the CronJob, but I want to bring it up in the scheduled sig-apps meeting to make sure everyone's in agreement first before actually doing it. I think it should be possible to accomplish without too much heartache by refactoring the CronJob controller a bit, and I'll probably play around with a few ideas prior to the meeting. |
Here's the approach I'm taking right now: https://github.com/erhudy/kubernetes/commit/b603ab7ccbecc010f686f8507d6c0155b7246da9 When a Job is created via the Maybe this is sufficient for the general case? |
@erhudy In this mechanism, is there a way to pass parameters when invoking manually? |
What kind of parameters? Right now the action is not parameterized - it looks at the JobSpec embedded in the CronJob and creates a Job from it. |
When invoking manually, parameters will make it 10x more effective.
I am pretty sure there will be lot more use cases community will find with this flexibility. |
CronJobs are for scheduled jobs. This issue and the PR are meant to provide a hook for people to kick the CronJob, mainly for testing purposes. Your use cases don't sound aligned to the goal of this PR. Addressing them individually:
|
I think there is a real need and it can be fulfilled by cronjob. If it needs minimal changes, I would encourage you to add it and fill the gap. |
The PR looks like a good initial implementation. To me- it sounds like in the long run- OUTSIDE the scope of the issue, there needs to be a redesign of CronJobs and Jobs: Though I may be insane and need more coffee. |
I am thinking that we are debating a higher level question, that is, until it is done the right way (whatever the right way may be, to be debated, the implementation of right way being months or years away), will it help if there was at least one way to do it? Maybe deprecate "wrong" way when something better is available? |
Agree with @rapenchukd that CronJobs could be redesigned at some point as they are just a specific type of job, that would likely simplify cases like these. |
That's a separate topic: how to precreate resource in the cluster without 'deploying' them
You have one CronJob to clear the cache, and one Job (not a Cron) to rebuilt it. |
There was a discussion about it early on when I was proposing to combine the two (see #11746) but it was then we decided to split it into two separate entities. CronJob is not a special case of a Job. Job is meant to run once and finish. CronJob add additional level of complexity which we decided to express through a separate controller. This issue and the solution will not provide option to modify cronjob during instantiation. They are meant to kickoff a single instance of a Job defined in a CronJob as is, as @erhudy pointed it out. |
… instance from a CronJob This changeset adds the command `kubectl create job` with the flag `--from-cronjob`, which allows a user to create a Job from a CronJob via the CLI.
It changed to |
At the moment manual start of cron job doesn't respect the cron job's concurrency policy. Is there any trick, passing certain label that I can trick Cron Job Controller with recognizing that the job is its own so it does not start new one when on schedule. |
It would be nice to support manual runs for CronJobs. Today, IIRC, a CronJob misses its schedule for whatever reason and we won't start it until the next time it's scheduled to run. At the very least, this could be a kubectl generator, eventually we may want to support it as part of the CJ API.
@stevekuznetsov since you were asking about it today
@kubernetes/sig-apps-feature-requests
The text was updated successfully, but these errors were encountered: