3

I am trying to make a cron job in Openshift but I got this error:

error: unable to parse "openshift/cronJob-template.yml", not a valid Template but *batch.CronJob

I ran this command:

oc process -f openshift/cronJob-template.yml -p namespace=test-project | oc apply -f -

My yml looks like:

apiVersion: batch/v2alpha1
kind: CronJob
metadata:
  name: demo
spec:
  schedule: "*/30 2 * * *"
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            parent: "demo"
        spec:
          containers:
          - name: demo
            image: demo
            command: ["java",  "-jar", "test.jar"]
          restartPolicy: OnFailure

I did have my schedule looking like the following but I am not sure if it is correct in a yml file schedule: "*/30 2 * * * /tmp/logs"

This is my first time creating a cron job via ymland on Openshift so I apologise.

Mike3355
  • 11,305
  • 24
  • 96
  • 184

1 Answers1

2

The template looks ok. Try run oc create -f openshift/cronJob-template.yml -n test-project instead.

PhilipGough
  • 1,709
  • 1
  • 13
  • 18
  • I can accept this answer in 5 min. What about the logs? Is there a way I can set them in this yaml file? – Mike3355 Jul 06 '18 at 15:34
  • Yeah, after the job has been scheduled at least once, running `oc get pods` should show a completed job. At that point, run `oc logs `. The yaml file is the definition of the resource. It will never contain the logs. – PhilipGough Jul 06 '18 at 15:38
  • That is confusing. Yeah and then you say it will never contain logs? – Mike3355 Jul 06 '18 at 17:01
  • Sorry. Meant logs are viewable but yaml is not related in any way to the logs – PhilipGough Jul 06 '18 at 18:43