Add annotations to revisionTemplate for knative
* Adds metadata to the knative spec in the generation command * Fixes: #815 Tested by running locally and verifying it matched the request from @Jeff-Lowrey faas-cli generate \ --api=serving.knative.dev/v1alpha1 \ --annotation sidecar.istio.io/inject=true This also works when bringing in annotations from the YAML file. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
462fd90da6
commit
defd7e46b3
@@ -5,6 +5,7 @@ package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
v2 "github.com/openfaas/faas-cli/schema/store/v2"
|
||||
|
||||
"github.com/openfaas/faas-cli/builder"
|
||||
@@ -29,6 +30,7 @@ var (
|
||||
functionNamespace string
|
||||
fromStore string
|
||||
desiredArch string
|
||||
annotationArgs []string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -40,6 +42,8 @@ func init() {
|
||||
generateCmd.Flags().Var(&tagFormat, "tag", "Override latest tag on function Docker image, accepts 'latest', 'sha', 'branch', 'describe'")
|
||||
generateCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
|
||||
generateCmd.Flags().StringVar(&desiredArch, "arch", "x86_64", "Desired image arch. (Default x86_64)")
|
||||
generateCmd.Flags().StringArrayVar(&annotationArgs, "annotation", []string{}, "Any annotations you want to add")
|
||||
|
||||
faasCmd.AddCommand(generateCmd)
|
||||
}
|
||||
|
||||
@@ -114,11 +118,20 @@ func runGenerate(cmd *cobra.Command, args []string) error {
|
||||
return errors.New(fmt.Sprintf("image for %s not found in store. \noptions: %s", desiredArch, keys))
|
||||
}
|
||||
|
||||
var annotations map[string]string
|
||||
|
||||
annotations, annotationErr := parseMap(annotationArgs, "annotation")
|
||||
if annotationErr != nil {
|
||||
return fmt.Errorf("error parsing annotations: %v", annotationErr)
|
||||
}
|
||||
|
||||
allAnnotations := mergeMap(item.Annotations, annotations)
|
||||
|
||||
services.Functions[item.Name] = stack.Function{
|
||||
Name: item.Name,
|
||||
Image: item.Images[desiredArch],
|
||||
Labels: &item.Labels,
|
||||
Annotations: &item.Annotations,
|
||||
Annotations: &allAnnotations,
|
||||
Environment: item.Environment,
|
||||
FProcess: item.Fprocess,
|
||||
}
|
||||
@@ -235,11 +248,15 @@ func generateknativev1alpha1ServingCRDYAML(services stack.Services, format schem
|
||||
},
|
||||
APIVersion: apiVersion,
|
||||
Kind: "Service",
|
||||
|
||||
Spec: knativev1alpha1.ServingSpec{
|
||||
RunLatest: knativev1alpha1.ServingSpecRunLatest{
|
||||
|
||||
Configuration: knativev1alpha1.ServingSpecRunLatestConfiguration{
|
||||
RevisionTemplate: knativev1alpha1.ServingSpecRunLatestConfigurationRevisionTemplate{
|
||||
Metadata: schema.Metadata{
|
||||
Annotations: *function.Annotations,
|
||||
},
|
||||
Spec: knativev1alpha1.ServingSpecRunLatestConfigurationRevisionTemplateSpec{
|
||||
Container: knativev1alpha1.ServingSpecRunLatestConfigurationRevisionTemplateSpecContainer{
|
||||
Image: function.Image,
|
||||
|
||||
@@ -20,7 +20,12 @@ type ServingSpecRunLatestConfiguration struct {
|
||||
}
|
||||
|
||||
type ServingSpecRunLatestConfigurationRevisionTemplate struct {
|
||||
Spec ServingSpecRunLatestConfigurationRevisionTemplateSpec `yaml:"spec"`
|
||||
Metadata schema.Metadata `yaml:"metadata"`
|
||||
Spec ServingSpecRunLatestConfigurationRevisionTemplateSpec `yaml:"spec"`
|
||||
}
|
||||
|
||||
type ServingSpecRunLatestConfigurationRevisionTemplateMetadata struct {
|
||||
Annotations map[string]string `yaml:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
type ServingSpecRunLatestConfigurationRevisionTemplateSpec struct {
|
||||
|
||||
@@ -5,6 +5,7 @@ package schema
|
||||
|
||||
// Metadata metadata of the object
|
||||
type Metadata struct {
|
||||
Name string `yaml:"name"`
|
||||
Namespace string `yaml:"namespace,omitempty"`
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Namespace string `yaml:"namespace,omitempty"`
|
||||
Annotations map[string]string `yaml:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user