0

I want to create a cronjob that interacts with my API. First, I need to send a request to authentificate, then send a GET request

Here is the yaml of my cronjob:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: verification-pointage
  namespace: isi-incubator
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: verification-pointage
              image: curlimages/curl:7.77.0
              imagePullPolicy: IfNotPresent
              command: ["/bin/sh","-c"]
              args: ["curl -c session -H \"Content-Type:application/json\" -d '{\"username\":\"johndoe\",\"password\":\"johndoe123\"}' http://odoo-api/authentication  && curl -b session http://odoo-api/timesheets/verification"]
          restartPolicy: OnFailure

When I do the two curl commands in local, I have no problem, but when the commands are executed in the cronjob, the session doesn't seem to have been created. So the second command cannot use the cookie stored in the session file.

Couldosh
  • 371
  • 3
  • 17
  • Since you mentioned about "When I do the two curl commands in local, ", did you try those commands in docker/kubernetes jobs? or just executed them in shell? Also regarding your fix, it is related to a readonly filesystem? If you can share more info that will help the next user. – Rajan Panneer Selvam Jul 21 '21 at 03:46
  • I just executed the two curl commands in local shell. I imagine that the default folder is in read-only, so I moved the session file to the `tmp` folder, which seems to allow write – Couldosh Jul 21 '21 at 04:36

1 Answers1

1

Ok, so I change the path to the cookie file from session to tmp/session and it works

Couldosh
  • 371
  • 3
  • 17