-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Create a Job from existing Cronjob #991
Comments
/cc @fabianvf |
The from kubernetes import client, config
job_name = 'from-cron-job'
cron_job_name = 'example'
namespace = 'default'
config.load_kube_config()
batch_v1 = client.BatchV1Api()
batch_v1beta1 = client.BatchV1beta1Api()
cron_job = batch_v1beta1.read_namespaced_cron_job(cron_job_name, namespace)
job = client.V1Job(
api_version='batch/v1',
kind='Job',
metadata=client.models.V1ObjectMeta(
name=job_name,
# This annotation is added by kubectl, probably best to add it ourselves as well
annotations={"cronjob.kubernetes.io/instantiate": "manual"}
),
spec=cron_job.spec.job_template.spec
)
result = batch_v1.create_namespaced_job(namespace, job)
print(result) |
@fabianvf great, thank you! I've seen the source code for |
I'll defer to @roycaihw , but my impression is that this sort of higher-level functionality isn't necessarily in scope, this client occupies a space closer to client-go than to kubectl. It would be nice to have a place for these sorts of helpful functions though, I'm not sure if there is one at the moment. |
https://github.com/kubernetes-client/python/tree/master/kubernetes/utils is where we put some helpful high-level functions. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
For creating a fresh new cronjob on GKE cluster using bearer token for authentication you can refer to this: https://techhub.go1percent.com/dashboard/projects/devops/62a1e1d8f20000af4db0c0cd |
how can i add th
how can i add time to live for this job created. after this job is finished. it should not be listed in job let say after 1 min |
When working with
kubectl
I can easily create aJob
from existingCronjob
like this:How can I do the same using
kubernetes-client
?The text was updated successfully, but these errors were encountered: