Annotation support

Provide support for annotations in faasd with namespaced container
labels. Unit tested and confirmed with end to end test via faasd
deployed to multipass VM

Signed-off-by: Alex Tomic <atomic777@gmail.com>
This commit is contained in:
Alex Tomic
2020-06-16 22:32:08 -04:00
committed by Alex Ellis
parent 716ef6f51c
commit ac1cc16f0c
6 changed files with 167 additions and 20 deletions

View File

@ -0,0 +1,63 @@
package handlers
import (
"fmt"
"reflect"
"testing"
"github.com/openfaas/faas-provider/types"
)
func Test_BuildLabels_WithAnnotations(t *testing.T) {
// Test each combination of nil/non-nil annotation + label
tables := []struct {
label map[string]string
annotation map[string]string
result map[string]string
}{
{nil, nil, map[string]string{}},
{map[string]string{"L1": "V1"}, nil, map[string]string{"L1": "V1"}},
{nil, map[string]string{"A1": "V2"}, map[string]string{fmt.Sprintf("%sA1", annotationLabelPrefix): "V2"}},
{
map[string]string{"L1": "V1"}, map[string]string{"A1": "V2"},
map[string]string{"L1": "V1", fmt.Sprintf("%sA1", annotationLabelPrefix): "V2"},
},
}
for _, pair := range tables {
request := &types.FunctionDeployment{
Labels: &pair.label,
Annotations: &pair.annotation,
}
val, err := buildLabels(request)
if err != nil {
t.Fatalf("want: no error got: %v", err)
}
if !reflect.DeepEqual(val, pair.result) {
t.Errorf("Got: %s, expected %s", val, pair.result)
}
}
}
func Test_BuildLabels_WithAnnotationCollision(t *testing.T) {
request := &types.FunctionDeployment{
Labels: &map[string]string{
"function_name": "echo",
fmt.Sprintf("%scurrent-time", annotationLabelPrefix): "Wed 25 Jul 06:41:43 BST 2018",
},
Annotations: &map[string]string{"current-time": "Wed 25 Jul 06:41:43 BST 2018"},
}
val, err := buildLabels(request)
fmt.Printf("%s, %s\n", val, err)
if err == nil {
t.Errorf("Expected an error, got %d values", len(val))
}
}