Openshift Job Trigger

4/28/2019

We have batch job that process flat files which gets triggered using Rest Call

For e.g. https://clustername.com/loader?filname=file1.dat
    https://clustername.com/loader?filname=file2.dat
    https://clustername.com/loader?filname=file3.dat

We want to configure Openshift Job to trigger this batch job.

https://docs.openshift.com/container-platform/3.11/dev_guide/jobs.html

As per the Kubernetes documentation, the job can be triggered using Queue:

https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/

Can the job also be triggered by Rest Call?

-- user3811946
kubernetes
openshift

1 Answer

4/29/2019

As others have mentioned, you can instantiate a job by creating a new one via the API.

IIRC you'll make a POST call to /apis/batch/v1/namespaces/<your-namespace>/jobs
(The endpoint may be slightly different depending on your API versions.)

The payload for your REST call is the JSON formatted manifest for the job you want to run. i.e.

{
    "apiVersion": "batch/v1",
    "kind": "Job",
    "metadata": {
        "name": "example"
    },
    "spec": {
        "selector": {},
        "template": {
            "metadata": {
                "name": "example"
            },
            "spec": {
                "containers": [
                    {
                        "name": "example",
                        "image": "hello-world"
                    }
                ],
                "restartPolicy": "Never"
            }
        }
    }
}
-- switchboard.op
Source: StackOverflow