-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add option to create one-off job from cron job #4116
Comments
This isn't currently possible with the current action feature, which only manipulates the resource that you are performing the action on. However I do see the value in generating new resources as part of an action. This would need to be a new feature and potentially affect RBAC. |
This would be an interesting feature standalone to be able to provide the ability to perform manual, but defined cluster actions via the ArgoCD UI/API |
bump here, there is a real desire to run things like seed data migrations as one-off jobs in real environments from the UI. This unblocks regular deployment pipelines and allows better management of multiple environments. Any updates? |
Hello, also very interested in that feature that would simplify a LOT our processes |
If anyone's willing to put up a PR, I'd be happy to help w/ dev setup and review! My rough idea of the way this could work is that the custom action could produce a list of manifests (strings of JSON or YAML) and actions (for now just I'm hazy on the exact mechanic behind "send the manifests to the controller." The API server currently has the ability to trigger and "override" sync, where manifests are sent to the controller to be applied once, ignoring the usual application source of truth. But I'm not sure the override mechanism currently has a "just add this one thing (or these few things)" option. The developer would probably have to build this new sync mechanism. @jessesuen does that line up with how you'd envision this feature being built? |
So upon a new "create-from" action, performed on the
resource, which is part of some Application, a new
resource (which is not part of that Application) has to be created? |
@reggie-k yep, something like that is what I'd imagine! |
sorry guys, I don't understand the status of this new feature :) |
Can i make this button with Lua ? |
@SergeyLadutko very good question! I'm looking into it, but I don't have Lua expertise at the moment :( |
@bygui86 |
You created a button to restart deploymenta, but did not create a cronjob to launch ((( |
I am working on the issue, but it it will take time, not a trivial one. If
anyone wants to join me, it can be a team work.
There are tasks at 3 different levels here.
…On Thu, Dec 1, 2022, 13:23 SergeyLadutko ***@***.***> wrote:
You created a button to restart deploymenta, but did not create a cronjob
to launch (((
—
Reply to this email directly, view it on GitHub
<#4116 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEVDWBHGN52UEFEBXP2755DWLCDBRANCNFSM4QDK6PPA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@SergeyLadutko it would be a very useful feature for us as well, so I prepared a prototype in Lua script and I will test it in the next days. @reggie-k Maybe I can open a MR adding it to the |
@bygui86 This is very good news, thank you!!! |
@bygui86 I'd be interested to see the PoC. How are you getting the Lua script to create a new resource? iirc, those can only modify the existing resource. |
@crenshaw-dev It's only a PoC for now, will test it in the next days 🤞🏼 and let you know |
@crenshaw-dev I was able to test it in minikube and unfortunately it doesn't work :( I tried to simply create a new Job object starting from CronJob definition (obj in Lua), but of course I was wrong! |
ArgoCD error in logs:
|
@bygui86
I can take the first part, unless you have progressed with that, in that case, I will take the second one. |
@reggie-k actually I have a Lua script to generate a Job from a CronJob :) local os = require("os")
job = {}
job.apiVersion = "batch/v1"
job.kind = "Job"
job.metadata = {}
job.metadata.name = cronjob.spec.jobTemplate.metadata.name .. os.date("!%Y%m%d%H%M")
job.spec = {}
job.spec = cronjob.spec.jobTemplate.spec
-- optional
job.metadata.annotations = {}
job.metadata.annotations["kubectl.kubernetes.io/createdAt"] = os.date("!%Y-%m-%dT%XZ")
return job do you think you can use it? |
Hi @bygui86, I added this code to the configmap , but I didn't see the cronjob restart button (((Maybe I'm doing something wrong?
|
Thanks!
I think it would be better to have a template file and just fill it with
values. A template file is more readable, easier to test with and easier to change if k8s api changes.
Going on a vacation, will continue working on filling the template file
next week.
…On Sat, Dec 10, 2022, 16:49 Matteo Baiguini ***@***.***> wrote:
@reggie-k <https://github.com/reggie-k> actually I have a Lua script to
generate a Job from a CronJob :)
here the code:
local os = require("os")
job = {}
job.apiVersion = "batch/v1"
job.kind = "Job"
job.metadata = {}
job.metadata.name = cronjob.spec.jobTemplate.metadata.name .. os.date("!%Y%m%d%H%M")
job.spec = {}
job.spec = cronjob.spec.jobTemplate.spec-- optional
job.metadata.annotations = {}
job.metadata.annotations["kubectl.kubernetes.io/createdAt"] = os.date("!%Y-%m-%dT%XZ")return job
do you think you can use it?
—
Reply to this email directly, view it on GitHub
<#4116 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEVDWBERNGDILU27LIKMCL3WMSJ7TANCNFSM4QDK6PPA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
It depends how you would like to implement this feature. |
@jessesuen @crenshaw-dev a question for after the holidays :) Another option would be returning the new object from the custom action and then saving it as a temp file from the code that invokes lua, but not sure how would this align with the vision of lua scripts returning only the object they act upon? Another workaround (not a pretty one) might be in lua putting the newly created manifest yaml string in the annotation on the original object, returning the original object as usual and then dealing with the new manifest creation outside of lua. Or in lua annotating the original cronjob object with something like "create-job-from-cron-job", and then the code that invokes the action will create the k8s resource imperatively by invoking k8s api, without going through ArgoCD sync at all. |
@muenchdo @genslein My suggestion: handling the imperative "kubectl create" result as a declarative representation of this one-time job resource and dealing with it in a regular GitOps way. Can the following work for you:
This worked for me, attaching the original CronJob and the Job manifest which I copied from the cluster and cleaned up:
|
I was about to create a ticket This is not a complicated ask and should be prioritized |
I think #12174 is what is needed first. Is there any progress on this? |
I tried that but I'm getting:
I assume it's because it can't create new resources, right? |
Hi guys, the development seems to be going well, can anyone tell me when it will be released ? |
Barring anything wild going wrong, we'll release this with 2.8-rc1 next Monday (June 26). It will also include the ability to create Workflows from CronWorkflows and WorkflowTemplates. |
* Kind wildcard support in health customizations Signed-off-by: reggie <reginakagan@gmail.com> * Updated health customizations docs to using the correct field with a / Signed-off-by: reggie <reginakagan@gmail.com> * Updated health customizations docs to using the correct field with a / Signed-off-by: reggie <reginakagan@gmail.com> * Document resource kind wildcard for custom health check Signed-off-by: reggie <reginakagan@gmail.com> * Implemented wildcard * support in API Group and Resource Kind and updated docs Signed-off-by: reggie <reginakagan@gmail.com> * Implemented wildcard * support in API Group and Resource Kind and updated docs Signed-off-by: reggie <reginakagan@gmail.com> * Implemented wildcard * support in API Group and Resource Kind and updated docs Signed-off-by: reggie <reginakagan@gmail.com> * Added a custom create-from CronJob action Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * added a ns in the action.lua and fixed tests Signed-off-by: reggie <reginakagan@gmail.com> * create-job Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * more changes Signed-off-by: reggie <reginakagan@gmail.com> * full unit tests and action returning an array Signed-off-by: reggie <reginakagan@gmail.com> * cleanup Signed-off-by: reggie <reginakagan@gmail.com> * fix the custom tests Signed-off-by: reggie <reginakagan@gmail.com> * e2e tests Signed-off-by: reggie <reginakagan@gmail.com> * json marshaling annotations ImpactedResource, e2e tests and docs Signed-off-by: reggie <reginakagan@gmail.com> * more docs and tests Signed-off-by: reggie <reginakagan@gmail.com> * upstream sync Signed-off-by: reggie <reginakagan@gmail.com> * fix wrong return upon going over the impacted resources + docs + fixing e2e tests Signed-off-by: reggie <reginakagan@gmail.com> * docs Signed-off-by: reggie <reginakagan@gmail.com> * better error handling Signed-off-by: reggie <reginakagan@gmail.com> * K8SOperation as an enum Signed-off-by: reggie <reginakagan@gmail.com> * added dry-run for create operation Signed-off-by: reggie <reginakagan@gmail.com> * small changes Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * gitops engine dependency and test fixes Signed-off-by: reggie <reginakagan@gmail.com> * add workflows action Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * cronworkflow and workflowtemplate actions Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * update gitops-engine Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> --------- Signed-off-by: reggie <reginakagan@gmail.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Round of applause for @reggie-k for knocking out this feature and closing the 3rd highest 👍'd issue in the repo! |
That is great news! Thank you @reggie-k (and @crenshaw-dev for getting this merged)! Looking forward to testing this! |
I had to try out the new release as soon as I saw it 😄 Unfortunately, I found a small bug with it 🐞 We rely on an annotation apiVersion: batch/v1
kind: CronJob
metadata:
name: testjob
namespace: test
spec:
jobTemplate:
spec:
template:
metadata:
annotations:
pod.kubernetes.io/sidecars: cloud-sql-proxy
spec:
containers:
... Unfortunately, when creating a |
@otherguy good catch! We copy over the spec but not the metadata.
Would you mind opening an issue? Also, if you're up for a PR, I'd be happy to review. :-) |
Of course: #14232 I don't think I will have time for a PR because it should also have test coverage and probably not copy all metadata. I did mention these concerns in the issue so I hope it's a quick fix and maybe can even go into 2.8.0 final! |
…12925) * Kind wildcard support in health customizations Signed-off-by: reggie <reginakagan@gmail.com> * Updated health customizations docs to using the correct field with a / Signed-off-by: reggie <reginakagan@gmail.com> * Updated health customizations docs to using the correct field with a / Signed-off-by: reggie <reginakagan@gmail.com> * Document resource kind wildcard for custom health check Signed-off-by: reggie <reginakagan@gmail.com> * Implemented wildcard * support in API Group and Resource Kind and updated docs Signed-off-by: reggie <reginakagan@gmail.com> * Implemented wildcard * support in API Group and Resource Kind and updated docs Signed-off-by: reggie <reginakagan@gmail.com> * Implemented wildcard * support in API Group and Resource Kind and updated docs Signed-off-by: reggie <reginakagan@gmail.com> * Added a custom create-from CronJob action Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * added a ns in the action.lua and fixed tests Signed-off-by: reggie <reginakagan@gmail.com> * create-job Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * more changes Signed-off-by: reggie <reginakagan@gmail.com> * full unit tests and action returning an array Signed-off-by: reggie <reginakagan@gmail.com> * cleanup Signed-off-by: reggie <reginakagan@gmail.com> * fix the custom tests Signed-off-by: reggie <reginakagan@gmail.com> * e2e tests Signed-off-by: reggie <reginakagan@gmail.com> * json marshaling annotations ImpactedResource, e2e tests and docs Signed-off-by: reggie <reginakagan@gmail.com> * more docs and tests Signed-off-by: reggie <reginakagan@gmail.com> * upstream sync Signed-off-by: reggie <reginakagan@gmail.com> * fix wrong return upon going over the impacted resources + docs + fixing e2e tests Signed-off-by: reggie <reginakagan@gmail.com> * docs Signed-off-by: reggie <reginakagan@gmail.com> * better error handling Signed-off-by: reggie <reginakagan@gmail.com> * K8SOperation as an enum Signed-off-by: reggie <reginakagan@gmail.com> * added dry-run for create operation Signed-off-by: reggie <reginakagan@gmail.com> * small changes Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * gitops engine dependency and test fixes Signed-off-by: reggie <reginakagan@gmail.com> * add workflows action Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * cronworkflow and workflowtemplate actions Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * update gitops-engine Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> --------- Signed-off-by: reggie <reginakagan@gmail.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
what would be the argocd policy rbac equivalent to:
my motivation here is to create a policy that the only thing it allows a user/group to do is to be able to use the |
Hi @ArieLevs, if I understand you correctly, you should add: To policy rulles in argoCD |
@SergeyLadutko thanks a lot! this totally did the trick 👍 btw, I'm controlling roles via the argocd helm chart, so I added
then attached this role to the relevant group, but I do not see this role in argocd UI similar (under the |
argoproj#516) * separating kubectl and resource ops mocks Signed-off-by: reggie <reginakagan@gmail.com> * separating kubectl and resource ops mocks Signed-off-by: reggie <reginakagan@gmail.com> * separating kubectl and resource ops mocks Signed-off-by: reggie <reginakagan@gmail.com> * server dry-run for MockKubectlCmd Signed-off-by: reggie <reginakagan@gmail.com> * server dry-run for MockKubectlCmd Signed-off-by: reggie <reginakagan@gmail.com> * server dry-run for MockKubectlCmd Signed-off-by: reggie <reginakagan@gmail.com> * mock create noop Signed-off-by: reggie <reginakagan@gmail.com> * ctl create resource with createOptions Signed-off-by: reggie <reginakagan@gmail.com> --------- Signed-off-by: reggie <reginakagan@gmail.com>
@ArieLevs Did you manage to solve this? I'm hitting the same issue. |
@vyrwu I'm not doing any updates via the UI to keep on a GitOps approach, |
RBAC configured in argocd-rbac-cm, even if it references a particular project, will not appear in the project interface. Only RBAC configured directly on the AppProject resource will appear in the |
@crenshaw-dev thanks, was not even aware of that, thought its a bug 😅 |
It worked 🥳 Thx so much for support @ArieLevs and @crenshaw-dev. Really wish the RBAC set via |
…12925) * Kind wildcard support in health customizations Signed-off-by: reggie <reginakagan@gmail.com> * Updated health customizations docs to using the correct field with a / Signed-off-by: reggie <reginakagan@gmail.com> * Updated health customizations docs to using the correct field with a / Signed-off-by: reggie <reginakagan@gmail.com> * Document resource kind wildcard for custom health check Signed-off-by: reggie <reginakagan@gmail.com> * Implemented wildcard * support in API Group and Resource Kind and updated docs Signed-off-by: reggie <reginakagan@gmail.com> * Implemented wildcard * support in API Group and Resource Kind and updated docs Signed-off-by: reggie <reginakagan@gmail.com> * Implemented wildcard * support in API Group and Resource Kind and updated docs Signed-off-by: reggie <reginakagan@gmail.com> * Added a custom create-from CronJob action Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * added a ns in the action.lua and fixed tests Signed-off-by: reggie <reginakagan@gmail.com> * create-job Signed-off-by: reggie <reginakagan@gmail.com> * in progress Signed-off-by: reggie <reginakagan@gmail.com> * more changes Signed-off-by: reggie <reginakagan@gmail.com> * full unit tests and action returning an array Signed-off-by: reggie <reginakagan@gmail.com> * cleanup Signed-off-by: reggie <reginakagan@gmail.com> * fix the custom tests Signed-off-by: reggie <reginakagan@gmail.com> * e2e tests Signed-off-by: reggie <reginakagan@gmail.com> * json marshaling annotations ImpactedResource, e2e tests and docs Signed-off-by: reggie <reginakagan@gmail.com> * more docs and tests Signed-off-by: reggie <reginakagan@gmail.com> * upstream sync Signed-off-by: reggie <reginakagan@gmail.com> * fix wrong return upon going over the impacted resources + docs + fixing e2e tests Signed-off-by: reggie <reginakagan@gmail.com> * docs Signed-off-by: reggie <reginakagan@gmail.com> * better error handling Signed-off-by: reggie <reginakagan@gmail.com> * K8SOperation as an enum Signed-off-by: reggie <reginakagan@gmail.com> * added dry-run for create operation Signed-off-by: reggie <reginakagan@gmail.com> * small changes Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * ref to my gitops-engine fork out Signed-off-by: reggie <reginakagan@gmail.com> * gitops engine dependency and test fixes Signed-off-by: reggie <reginakagan@gmail.com> * add workflows action Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * cronworkflow and workflowtemplate actions Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * update gitops-engine Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> --------- Signed-off-by: reggie <reginakagan@gmail.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Summary
Add a button to create a one-off job from a cron job.
Motivation
We often deploy cron jobs using Argo CD, but want to do test run of the job after deployment. Using
kubectl
you can easily create a job from a cron job usingkubectl create job --from=cronjob/foo foo
. As most of our engineers don't actually have cluster access using kubectl, integrating this into Argo CD (including RBAC, easily browsable logs, etc.) would be tremendously useful.Proposal
Similar to the Restart option for deployments, this could be included in the dropdown when clicking a cron job object in the resource tree.
The text was updated successfully, but these errors were encountered: