Generate annotations in OpenFaaS CR output

The faas-cli generate command was missing support for
annotations. Fixes: #890

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2021-06-02 20:18:46 +01:00
committed by Alex Ellis
parent 047e2803de
commit 77ad215bcc
4 changed files with 42 additions and 4 deletions

View File

@@ -204,6 +204,7 @@ func generateCRDYAML(services stack.Services, format schema.BuildFormat, apiVers
Image: imageName,
Environment: allEnvironment,
Labels: function.Labels,
Annotations: function.Annotations,
Limits: function.Limits,
Requests: function.Requests,
Constraints: function.Constraints,

View File

@@ -50,7 +50,38 @@ spec:
Branch: "",
Version: "",
},
{
Name: "Annotation present",
Input: `
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
url-ping:
lang: python
handler: ./sample/url-ping
image: alexellis/faas-url-ping:0.2
annotations:
com.scale.zero: 1
`,
Output: []string{`---
apiVersion: openfaas.com/v1
kind: Function
metadata:
name: url-ping
namespace: openfaas-fn
spec:
name: url-ping
image: alexellis/faas-url-ping:0.2
annotations:
com.scale.zero: "1"
`},
Format: schema.DefaultFormat,
APIVersion: "openfaas.com/v1",
Namespace: "openfaas-fn",
Branch: "",
Version: "",
},
{
Name: "Blank namespace",
Input: `
@@ -179,7 +210,7 @@ func Test_generateCRDYAML(t *testing.T) {
parsedServices, err := stack.ParseYAMLData([]byte(testcase.Input), "", "", true)
if err != nil {
t.Fatalf("%s failed: error while parsing the input data.", testcase.Name)
t.Fatalf("%s failed: error while parsing the input data", testcase.Name)
}
if parsedServices == nil {
@@ -189,11 +220,11 @@ func Test_generateCRDYAML(t *testing.T) {
generatedYAML, err := generateCRDYAML(services, testcase.Format, testcase.APIVersion, testcase.Namespace, testcase.Branch, testcase.Version)
if err != nil {
t.Fatalf("%s failed: error while generating CRD YAML.", testcase.Name)
t.Fatalf("%s failed: error while generating CRD YAML", testcase.Name)
}
if !stringInSlice(generatedYAML, testcase.Output) {
t.Fatalf("%s failed: ouput is not as expected: %s", testcase.Name, generatedYAML)
t.Fatalf("%s failed: want:\n%q, but got:\n%q", testcase.Name, testcase.Output, generatedYAML)
}
}

View File

@@ -22,6 +22,8 @@ type Spec struct {
Labels *map[string]string `yaml:"labels,omitempty"`
Annotations *map[string]string `yaml:"annotations,omitempty"`
//Limits for the function
Limits *stack.FunctionResources `yaml:"limits,omitempty"`

View File

@@ -7,6 +7,10 @@ provider:
functions:
url-ping:
annotations:
test: true
labels:
com.openfaas: 1
lang: python
handler: ./sample/url-ping
image: ${DOCKER_USER:-alexellis}/faas-url-ping:0.2