openfaas / faasd

A lightweight & portable faas engine
https://store.openfaas.com/l/serverless-for-everyone-else
Other
3.01k stars 214 forks source link

Labels and annotations not correctly fetched every time #128

Closed Waterdrips closed 3 years ago

Waterdrips commented 3 years ago

I have a setup in faasd (On Rpi3) . Installed by cloning faasd (master) and running the install script in ./hack directory

it has 2x functions, one has annotations, the other does not:

faas-cli store deploy nodeinfo --annotation schedule="*/1 * * * *" --annotation topic=cron-function --platform armhf
faas-cli store deploy nodeinfo --name nodeinfo2 --platform armhf

When i curl /system/functions sometimes they both have the annotations set on nodeinfo

[
  {
    "name": "nodeinfo2",
    "image": "docker.io/functions/nodeinfo-http:latest-armhf",
    "invocationCount": 1,
    "replicas": 1,
    "envProcess": "",
    "availableReplicas": 0,
    "labels": null,
    "annotations": {
      "schedule": "*/1 * * * *",
      "topic": "cron-function"
    },
    "namespace": "openfaas-fn"
  },
  {
    "name": "nodeinfo",
    "image": "docker.io/functions/nodeinfo-http:latest-armhf",
    "invocationCount": 0,
    "replicas": 1,
    "envProcess": "",
    "availableReplicas": 0,
    "labels": null,
    "annotations": {
      "schedule": "*/1 * * * *",
      "topic": "cron-function"
    },
    "namespace": "openfaas-fn"
  }
]

sometimes neither have the annotation

[
  {
    "name": "nodeinfo",
    "image": "docker.io/functions/nodeinfo-http:latest-armhf",
    "invocationCount": 0,
    "replicas": 1,
    "envProcess": "",
    "availableReplicas": 0,
    "labels": null,
    "annotations": null,
    "namespace": "openfaas-fn"
  },
  {
    "name": "nodeinfo2",
    "image": "docker.io/functions/nodeinfo-http:latest-armhf",
    "invocationCount": 1,
    "replicas": 1,
    "envProcess": "",
    "availableReplicas": 0,
    "labels": null,
    "annotations": null,
    "namespace": "openfaas-fn"
  }
]

Expected Behaviour

We always get the correct annotations for a function returned by this call

Current Behaviour

sometimes we get both functions showing an annotation, sometimes neither

Possible Solution

Looks like the faasd provider code is the place to start looking

Steps to Reproduce (for bugs)

  1. install faasd (using the HEAD commit, with the install script)
  2. login
  3. create the 2 functions as shown in the readme
  4. curl the /system/fucntions endpoint a few times, you should see neither, then both having the annotations

Context

The cron-connector calls /system/functions and then builds the schedules based on the results, so we see it invoking both, or neither.

alexellis commented 3 years ago

@AkihiroSuda do you have any suggestions? I visually inspected the code and it looked to be as expected.

Alistair perhaps we are not using a reference in a loop somewhere?

alexellis commented 3 years ago

Here is an example of it happening for me:

curl -s http://admin:$(sudo cat /var/lib/faasd/secrets/basic-auth-password)@localhost:8081/system/functions|jq
[
  {
    "name": "f2",
    "image": "docker.io/functions/figlet:0.13.0",
    "invocationCount": 0,
    "replicas": 1,
    "envProcess": "",
    "availableReplicas": 0,
    "labels": {},
    "annotations": {
      "f1": "1"
    },
    "namespace": "openfaas-fn"
  },
  {
    "name": "f1",
    "image": "docker.io/functions/figlet:0.13.0",
    "invocationCount": 0,
    "replicas": 1,
    "envProcess": "",
    "availableReplicas": 0,
    "labels": {},
    "annotations": {
      "f1": "1"
    },
    "namespace": "openfaas-fn"
  }
]

The /system/function/NAME endpoint appears to be stable in its output:

alex@alexx:~$ curl -s http://admin:$(sudo cat /var/lib/faasd/secrets/basic-auth-password)@localhost:8081/system/function/f1|jq
{
  "name": "f1",
  "image": "",
  "invocationCount": 0,
  "replicas": 1,
  "envProcess": "",
  "availableReplicas": 1,
  "labels": {},
  "annotations": {
    "f1": "1"
  },
  "namespace": "openfaas-fn"
}
alex@alexx:~$ curl -s http://admin:$(sudo cat /var/lib/faasd/secrets/basic-auth-password)@localhost:8081/system/function/f1|jq
{
  "name": "f1",
  "image": "",
  "invocationCount": 0,
  "replicas": 1,
  "envProcess": "",
  "availableReplicas": 1,
  "labels": {},
  "annotations": {
    "f1": "1"
  },
  "namespace": "openfaas-fn"
}
alex@alexx:~$ curl -s http://admin:$(sudo cat /var/lib/faasd/secrets/basic-auth-password)@localhost:8081/system/function/f1|jq
{
  "name": "f1",
  "image": "",
  "invocationCount": 0,
  "replicas": 1,
  "envProcess": "",
  "availableReplicas": 1,
  "labels": {},
  "annotations": {
    "f1": "1"
  },
  "namespace": "openfaas-fn"
}
alex@alexx:~$ curl -s http://admin:$(sudo cat /var/lib/faasd/secrets/basic-auth-password)@localhost:8081/system/function/f1|jq
{
  "name": "f1",
  "image": "",
  "invocationCount": 0,
  "replicas": 1,
  "envProcess": "",
  "availableReplicas": 1,
  "labels": {},
  "annotations": {
    "f1": "1"
  },
  "namespace": "openfaas-fn"
}
alex@alexx:~$ 
Waterdrips commented 3 years ago

/close