Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
javascript/examples/in-cluster-create-job-from-cronjob.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (30 sloc)
956 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const k8s = require('@kubernetes/client-node'); | |
const kc = new k8s.KubeConfig(); | |
kc.loadFromCluster(); | |
const batchV1Api = kc.makeApiClient(k8s.BatchV1Api); | |
const batchV1beta1Api = kc.makeApiClient(k8s.BatchV1beta1Api); | |
const cronJobName = 'myCronJob'; | |
const jobName = 'myJob'; | |
const job = new k8s.V1Job(); | |
const metadata = new k8s.V1ObjectMeta(); | |
job.apiVersion = 'batch/v1'; | |
job.kind = 'Job'; | |
metadata.name = jobName; | |
metadata.annotations = { | |
'cronjob.kubernetes.io/instantiate': 'manual', | |
}; | |
job.metadata = metadata; | |
batchV1beta1Api.readNamespacedCronJob(cronJobName, 'default') | |
.then((cronJobRes) => { | |
job.spec = cronJobRes.body.spec.jobTemplate.spec; | |
batchV1Api.createNamespacedJob('default', job) | |
.then((res) => { | |
console.log(res.body); | |
}) | |
.catch((err) => { | |
console.log(err); | |
}); | |
}) | |
.catch((err) => { | |
console.log(err); | |
}); |