adding downward api volume plugin

This commit is contained in:
Salvatore Dario Minonne
2015-02-20 06:36:23 +01:00
parent cfe2bf10f2
commit f4dc0653aa
25 changed files with 1919 additions and 40 deletions

View File

@@ -22,6 +22,15 @@ import (
"k8s.io/kubernetes/pkg/api/meta"
)
// formatMap formats map[string]string to a string.
func formatMap(m map[string]string) string {
var l string
for key, value := range m {
l += key + "=" + fmt.Sprintf("%q", value) + "\n"
}
return l
}
// ExtractFieldPathAsString extracts the field from the given object
// and returns it as a string. The object must be a pointer to an
// API type.
@@ -37,6 +46,10 @@ func ExtractFieldPathAsString(obj interface{}, fieldPath string) (string, error)
}
switch fieldPath {
case "metadata.annotations":
return formatMap(accessor.Annotations()), nil
case "metadata.labels":
return formatMap(accessor.Labels()), nil
case "metadata.name":
return accessor.Name(), nil
case "metadata.namespace":

View File

@@ -57,6 +57,37 @@ func TestExtractFieldPathAsString(t *testing.T) {
},
expectedValue: "object-name",
},
{
name: "ok - labels",
fieldPath: "metadata.labels",
obj: &api.Pod{
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{"key": "value"},
},
},
expectedValue: "key=\"value\"\n",
},
{
name: "ok - labels bslash n",
fieldPath: "metadata.labels",
obj: &api.Pod{
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{"key": "value\n"},
},
},
expectedValue: "key=\"value\\n\"\n",
},
{
name: "ok - annotations",
fieldPath: "metadata.annotations",
obj: &api.Pod{
ObjectMeta: api.ObjectMeta{
Annotations: map[string]string{"builder": "john-doe"},
},
},
expectedValue: "builder=\"john-doe\"\n",
},
{
name: "invalid expression",
fieldPath: "metadata.whoops",