openfaas / faas-cli

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

Populate annotations for knative serving definitions #815

Closed Jeff-Lowrey closed 4 years ago

Jeff-Lowrey commented 4 years ago

Current Behaviour

The faas-cli generate function does not carry any annotations from the original function yaml into the knative yaml

Expected Behaviour

If the stack.yaml file contains any annotations (for example istio), they will be included in the output yaml file.

Example stack.yaml:

    version: 1.0
    provider:
      name: openfaas
    functions:
      this-func:
        annotations:
          sidecar.istio.io/inject: "true"

Calling fass-cli generate:

faas-cli generate --api=serving.knative.dev/v1alpha1

Should include the istio annotation in the output yaml

    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    metadata:
      name: this-func
    spec:
      runLatest:
        configuration:
          revisionTemplate:
            metadata:
              annotations:
                sidecar.istio.io/inject: "true"
            spec:
              container:
                image: this-func

Context

I am deploying openfaas functions that require istio - as the examples above show. There may be other annotations for other use-cases or systems that also need to be carried over.

Related issues

641 - Add new 0.6 Knative Serving spec to generate command

640 - Add Rio to faas-cli generate

FaaS-CLI version ( Full output from: faas-cli version ):

faas-cli version
  ___                   _____           ____
 / _ \ _ __   ___ _ __ |  ___|_ _  __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) |  __/ | | |  _| (_| | (_| |___) |
 \___/| .__/ \___|_| |_|_|  \__,_|\__,_|____/
      |_|

CLI:
 commit:  462fd90da687fd3ff3c491823f3cbc1986cfbd6e
 version: 0.12.6
alexellis commented 4 years ago

This does work for OpenFaaS CRD generation, perhaps it's just Knative. Are you wanting to contribute this @Jeff-Lowrey ?

alexellis commented 4 years ago

/set title: Populate annotations for knative serving definitions

alexellis commented 4 years ago

@Jeff-Lowrey are you absolutely sure that you have the correct location for the annotations? They can be added at multiple levels. If you are, I think this is a small patch.

Jeff-Lowrey commented 4 years ago

@alexellis In terms of where I put the annotations, I wasn't able to get an istio sidecar to be deployed in a function pod without putting the annotation under the function definition. And I tried putting it at every other level - top level, at the same level as "functions:" and then inside the specific function def. The only one that worked was putting it where I have it.

alexellis commented 4 years ago

You should be good to go then with https://github.com/openfaas/faas-cli/releases/tag/0.12.8

Just update and remember that your annotation needs to go in the YAML file if you're using one, --annotation k=v is only for the function store (as documented via --help)