openfaas / faas-cli

Official CLI for OpenFaaS
https://www.openfaas.com/
Other
798 stars 224 forks source link

Support request for faas-cli docker image #818

Closed joshuasprow closed 4 years ago

joshuasprow commented 4 years ago

I have a function deployed to OpenFaas on a Rancher Kubernetes cluster and started seeing cron jobs fail when using image 0.12.6 and later. I'm using basically the same yaml from the docs and haven't changed my function code, so faas-cli is the most likely culprit.

Expected Behaviour

The cron workload triggers the OpenFaas function, as expected.

Current Behaviour

When the job fails, it emits an error: Unknown command "/bin/sh" for "faas-cli" from the cron workload. Also, the function itself is not triggered.

Possible Solution

Lock the faas-cli version to 0.12.4. It's probably a good idea to lock the version regardless, right? I'm pretty new to Kubernetes, so I could use a hand.

Steps to Reproduce (for bugs)

  1. Deploy the function to OpenFaas. Here's a semi-redacted version of my stack.yml:
    version: 1.0
    provider:
    name: openfaas
    gateway: http://127.0.0.1:31112
    functions:
    function:
    lang: node12
    handler: ./function
    image: {{ image-url }}
    annotations:
      topic: cron-function
      schedule: "*/30 * * * *"
    environment:
      exec_timeout: 120s
      read_timeout: 120s
      upstream_timeout: 120s
      write_timeout: 120s
      write_debug: true
    secrets:
      - function-secrets
  2. Apply a manifest to create the cron workload:
    apiVersion: batch/v1beta1
    kind: CronJob
    metadata:
    name: function
    namespace: openfaas
    spec:
    schedule: "*/30 * * * *"
    concurrencyPolicy: Forbid
    successfulJobsHistoryLimit: 5
    failedJobsHistoryLimit: 10
    jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: openfaas-cli
              image: openfaas/faas-cli:0.12.6
              args:
                - /bin/sh
                - -c
                - echo "verbose" | faas-cli invoke function -g http://gateway.openfaas:8080
          restartPolicy: OnFailure
  3. Check cron workload logs for error.

Context

Just trying to schedule my OpenFaas functions.

Your Environment

alexellis commented 4 years ago

We changed the image so that the CLI itself is the entry point. That's probably why. Cc @utsavanand2 @LucasRoesler

alexellis commented 4 years ago

/set title: Support request for faas-cli docker image

utsavanand2 commented 4 years ago

Hii @joshuasprow ! You might want to make some changes to your CronJob by adding a command field with value ["/bin/sh", "-c"] and hence remove /bin/sh and -c from the args. The final YAML of your CronJob should look something like this.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: function
  namespace: openfaas
spec:
  schedule: "*/30 * * * *"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 5
  failedJobsHistoryLimit: 10
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: openfaas-cli
              image: openfaas/faas-cli:0.12.6
              command: ["/bin/sh", "-c"]
              args:
                - echo "verbose" | faas-cli invoke function -g http://gateway.openfaas:8080
          restartPolicy: OnFailure

Let us know if it works out for you!

alexellis commented 4 years ago

You'll need to try different things out, but this is the reason the docs you followed didn't work. You can always look at the changelog and pin to the version before the change was merged.

One you do figure it out, we'd appreciate a PR

joshuasprow commented 4 years ago

Moving those args into a command did the trick. Thanks @utsavanand2 !!

If I understand correctly, this happened because changing the CLI to be the entry point meant that the arguments were out of order. I was trying to pass /bin/sh as an argument to faas-cli and that's not a thing.

I'd be happy to make a PR to update the docs if that's the case.

utsavanand2 commented 4 years ago

@joshuasprow Yes you're right 😉. Glad it worked out for you

utsavanand2 commented 4 years ago

/close