Skip to content

Conversation

LucasRoesler
Copy link
Member

Add the function

  • constraints
  • environment variables
  • secrets
  • requests and limits

to the faas-cli describe output.

Motivation and Context

How Has This Been Tested?

Create a test cluster using KinD

kind create cluster --config=cluster.yaml
arkade install openfaas -a=false --function-pull-policy=IfNotPresent --wait

faas-cli store deploy nodeinfo --annotation sample=true --label status=418

Now deploy a sample function

$ faas-cli describe nodeinfo
Name:                nodeinfo
Status:              Ready
Replicas:            1
Available replicas:  1
Invocations:         0
Image:               ghcr.io/openfaas/nodeinfo:latest
Function process:    <default>
URL:                 http://127.0.0.1:8080/function/nodeinfo
Async URL:           http://127.0.0.1:8080/async-function/nodeinfo
Labels               faas_function : nodeinfo
                     status : 418
Annotations          sample : true
                     prometheus.io.scrape : false
Constraints          <none>
Environment          <none>
Secrets              <none>
Requests             <none>
Limits               <none>

Now we add some more interesting values, like a secret and env variables.

$ faas-cli secret create db-password --from-literal=password
Creating secret: db-password.
Created: 202 Accepted

$ faas-cli store deploy nodeinfo --annotation sample=true --label status=418 --secret db-password --env db-user=postgres --env db-host=rds.aws.example.com

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/nodeinfo

$ faas-cli describe nodeinfo
Name:                nodeinfo
Status:              Ready
Replicas:            1
Available replicas:  1
Invocations:         0
Image:               ghcr.io/openfaas/nodeinfo:latest
Function process:    <default>
URL:                 http://127.0.0.1:8080/function/nodeinfo
Async URL:           http://127.0.0.1:8080/async-function/nodeinfo
Labels:              faas_function: nodeinfo
                     status: 418
                     uid: 736815901
Annotations:         prometheus.io.scrape: false
                     sample: true
Constraints:         <none>
Environment:         <none>
Secrets:              - db-password
Requests:            <none>
Limits:              <none>

To see how multiple Secrets and the Requests and Limits are rendered, use

version: 1.0
provider:
  name: openfaas
  gateway: http://127.0.0.1:8080
functions:
  nodeinfo:
    lang: Dockerfile
    image: ghcr.io/openfaas/nodeinfo:latest
    secrets:
      - cache-password
      - db-password
    environment:
      db-host: rds.aws.example.com
      cache-host: redis.aws.example.com
    labels:
      status: 481
    annotations:
      sample: "true"
    requests:
      cpu: 100m
      memory: 128Mi
    limits:
      cpu: 200m
      memory: 256Mi

then

$ faas-cli secret create cache-password --from-literal=password
Creating secret: cache-password.
Created: 202 Accepted
$ faas-cli deploy
Deploying: nodeinfo.

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/nodeinfo

$ faas-cli describe nodeinfo
Name:                nodeinfo
Status:              Ready
Replicas:            1
Available replicas:  1
Invocations:         0
Image:               ghcr.io/openfaas/nodeinfo:latest
Function process:    <default>
URL:                 http://127.0.0.1:8080/function/nodeinfo
Async URL:           http://127.0.0.1:8080/async-function/nodeinfo
Labels:              faas_function: nodeinfo
                     status: 481
                     uid: 679245186
Annotations:         prometheus.io.scrape: false
                     sample: true
Constraints:         <none>
Environment:         <none>
Secrets:             - cache-password
                     - db-password
Requests:            CPU: 100m
                     Memory: 128Mi
Limits:              CPU: 200m
                     Memory: 256Mi

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Add the function
* constraints
* environment variables
* secrets
* requests and limits

This can be tested as follows:

Create a test cluster using KinD

```sh
kind create cluster --config=cluster.yaml
arkade install openfaas -a=false --function-pull-policy=IfNotPresent --wait

faas-cli store deploy nodeinfo --annotation sample=true --label status=418
```

Now deploy a sample function

```sh
$ faas-cli describe nodeinfo
Name:                nodeinfo
Status:              Ready
Replicas:            1
Available replicas:  1
Invocations:         0
Image:               ghcr.io/openfaas/nodeinfo:latest
Function process:    <default>
URL:                 http://127.0.0.1:8080/function/nodeinfo
Async URL:           http://127.0.0.1:8080/async-function/nodeinfo
Labels               faas_function : nodeinfo
                     status : 418
Annotations          sample : true
                     prometheus.io.scrape : false
Constraints          <none>
Environment          <none>
Secrets              <none>
Requests             <none>
Limits               <none>

```

Now we add some more interesting values, like a secret and env variables.

```sh
$ faas-cli secret create db-password --from-literal=password
Creating secret: db-password.
Created: 202 Accepted

$ faas-cli store deploy nodeinfo --annotation sample=true --label status=418 --secret db-password --env db-user=postgres --env db-host=rds.aws.example.com

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/nodeinfo

$ faas-cli describe nodeinfo
Name:                nodeinfo
Status:              Ready
Replicas:            1
Available replicas:  1
Invocations:         0
Image:               ghcr.io/openfaas/nodeinfo:latest
Function process:    <default>
URL:                 http://127.0.0.1:8080/function/nodeinfo
Async URL:           http://127.0.0.1:8080/async-function/nodeinfo
Labels:              faas_function: nodeinfo
                     status: 418
                     uid: 736815901
Annotations:         prometheus.io.scrape: false
                     sample: true
Constraints:         <none>
Environment:         <none>
Secrets:              - db-password
Requests:            <none>
Limits:              <none>
```

To see how multiple Secrets and the Requests and Limits are rendered, use

```yaml
version: 1.0
provider:
  name: openfaas
  gateway: http://127.0.0.1:8080
functions:
  nodeinfo:
    lang: Dockerfile
    image: ghcr.io/openfaas/nodeinfo:latest
    secrets:
      - cache-password
      - db-password
    environment:
      db-host: rds.aws.example.com
      cache-host: redis.aws.example.com
    labels:
      status: 481
    annotations:
      sample: "true"
    requests:
      cpu: 100m
      memory: 128Mi
    limits:
      cpu: 200m
      memory: 256Mi
```
then

```sh
$ faas-cli secret create cache-password --from-literal=password
Creating secret: cache-password.
Created: 202 Accepted
$ faas-cli deploy
Deploying: nodeinfo.

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/nodeinfo

$ faas-cli describe nodeinfo
Name:                nodeinfo
Status:              Ready
Replicas:            1
Available replicas:  1
Invocations:         0
Image:               ghcr.io/openfaas/nodeinfo:latest
Function process:    <default>
URL:                 http://127.0.0.1:8080/function/nodeinfo
Async URL:           http://127.0.0.1:8080/async-function/nodeinfo
Labels:              faas_function: nodeinfo
                     status: 481
                     uid: 679245186
Annotations:         prometheus.io.scrape: false
                     sample: true
Constraints:         <none>
Environment:         <none>
Secrets:             - cache-password
                     - db-password
Requests:            CPU: 100m
                     Memory: 128Mi
Limits:              CPU: 200m
                     Memory: 256Mi
```

Signed-off-by: Lucas Roesler <[email protected]>
@@ -103,20 +104,11 @@ func runDescribe(cmd *cobra.Command, args []string) error {
url, asyncURL := getFunctionURLs(gatewayAddress, functionName, functionNamespace)

funcDesc := schema.FunctionDescription{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these fields deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because i just embed the FunctionStatus now instead of copying each field one-at-a-time. This will ensure that the FunctionDescription always has access to the FunctionStatus fields

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining.

fmt.Fprintln(w, "URL:\t "+funcDesc.URL)
fmt.Fprintln(w, "Async URL:\t "+funcDesc.AsyncURL)
printMap(w, "Labels", *funcDesc.Labels)
printMap(w, "Annotations", *funcDesc.Annotations)
printList(w, "Constraints", funcDesc.Constraints)
printMap(w, "Environment", funcDesc.EnvVars)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Environment Variables"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra length is going to force the content even wider and add a lot of empty space to the other rows, which will make it harder to read.

It is always env or environment in yaml specs, so I think it is pretty clear what it means here.

Environment also aligns with the output from kubectl describe

@alexellis
Copy link
Member

Looks good, but we now have quite a long output.

Could you update to make these only print text if there are values?

Constraints          <none>
Environment Variables          <none>
Secrets              <none>
Requests             <none>
Limits               <none>

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Just want to iterate on the experience when most of the fields are empty.

@LucasRoesler
Copy link
Member Author

Looks good, but we now have quite a long output.

Could you update to make these only print text if there are values?

Constraints          <none>
Environment Variables          <none>
Secrets              <none>
Requests             <none>
Limits               <none>

This is certainly possible, but I copied the behavior from the existing implementation. There must have been a good reason for including the fields using <none> instead of omitting it. I assumed that including it makes the output more deterministic and explicit, so it, for example, if someone is copy/pasting this output and a field is missing it is then clear that the copy was incorrect.

@alexellis
Copy link
Member

I think you're right, can we add a --verbose flag, and hide some of the other fields like limits / requests / constraints when that's set to false?

The printer object accepts a parameter to control how verbose it is.
When verbose is false, empty values will be omitted from the describe
output.

Signed-off-by: Lucas Roesler <[email protected]>
Status: "Ready",
},
verbose: false,
expectedOutput: "Name:\tfiglet\nStatus:\tReady\nReplicas:\t0\nAvailable Replicas: 0\nInvocations:\t0\nImage:\topenfaas/figlet:latest\nFunction Process:\t<default>\n",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexellis what do you think of this? these two test cases demonstrate the kind of minimal and maximal cases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done. The only thing I might suggest is making this a block quote to make it easier to read, but there are pros and cons to that too. We can merge as is, thanks for adding the tests.

return
}

if usage == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably not print this message, since for anyone who's not on openfaas pro, they will see this all the time, so we could just omit printing it.

@alexellis
Copy link
Member

Trying this locally, I am seeing a whitespace difference on the first few fields then on the next few after that?
image

Ensure that the values for maps and slices are aligned with the string
values.

Signed-off-by: Lucas Roesler <[email protected]>
@alexellis
Copy link
Member

alexellis commented Mar 17, 2022

Function Process:   ./derek
URL:                https://derek.openfaas.com/function/derek-0114
Async URL:          https://derek.openfaas.com/async-function/derek-0114
Environment:         debug: true
 read_timeout: 20s
 validate_customers: true
 combine_output: true

With the latest change, I am seeing a bit of an inconsistency with the environment variable printing

I'd expect it to look more like:

Environment:
 debug: true
 read_timeout: 20s
 validate_customers: true

I'm seeing the same on secrets:

Secrets:             - derek-secret-key
 - derek-private-key

Add the header `Usage:` for the usage data to help it fit with the other
fields better

Signed-off-by: Lucas Roesler <[email protected]>
@LucasRoesler LucasRoesler requested a review from alexellis March 17, 2022 13:32
Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexellis alexellis merged commit 17baca4 into openfaas:master Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could we list secret names for functions on faas-cli describe?
2 participants