You can add Kubernetes annotations to a deployed Serverless function. This is done in the annotations section of the func.yaml configuration file.
There are two limitations of the function annotation feature:
-
After a function annotation propagates to the corresponding Knative service on the cluster, it cannot be removed from the service by deleting it from the
func.yamlfile. You must remove the annotation from the Knative service by modifying the YAML file of the service directly, or by using the {product-title} web console. -
You cannot set annotations that are set by Knative, for example, the
autoscalingannotations.
Adding annotations to a function
You can use the following procedure to add annotations to a function.
-
The OpenShift Serverless Operator and Knative Serving are installed on the cluster.
-
You have installed the
knCLI. -
You have created a function.
-
Open the
func.yamlfile for your function. -
For every annotation that you want to add, add the following YAML to the
annotationssection:name: test namespace: "" runtime: go ... annotations: <annotation_name>: "<annotation_value>"Substitute <annotation_name>: "<annotation_value>"with your annotation.For example, to indicate that a function was authored by Alice, you might include the following annotation:
name: test namespace: "" runtime: go ... annotations: author: "alice@example.com" -
Save the configuration.
The next time you deploy your function to the cluster, the annotations are added to the corresponding Knative service.