Add support for config.k8s.io/function annotation

This commit is contained in:
Prachi Pendse
2019-12-23 13:44:42 -08:00
parent 3900166fdf
commit f6320ca379
3 changed files with 24 additions and 1 deletions

View File

@@ -197,6 +197,13 @@ func GetContainerName(n *yaml.RNode) (string, string) {
// path to the function, this will be mounted into the container
path := meta.Annotations[kioutil.PathAnnotation]
functionAnnotation := meta.Annotations["config.k8s.io/function"]
if functionAnnotation != "" {
annotationContent, _ := yaml.Parse(functionAnnotation)
image, _ := annotationContent.Pipe(yaml.Lookup("container", "image"))
return image.YNode().Value, path
}
container := meta.Annotations["config.kubernetes.io/container"]
if container != "" {
return container, path

View File

@@ -316,7 +316,7 @@ metadata:
c, _ := GetContainerName(n)
assert.Equal(t, "gcr.io/foo/bar:something", c)
// container from annotation
// container from config.kubernetes.io/container annotation
n, err = yaml.Parse(`apiVersion: v1
kind: MyThing
metadata:
@@ -329,6 +329,21 @@ metadata:
c, _ = GetContainerName(n)
assert.Equal(t, "gcr.io/foo/bar:something", c)
// container from config.k8s.io/function annotation
n, err = yaml.Parse(`apiVersion: v1
kind: MyThing
metadata:
annotations:
config.k8s.io/function: |
container:
image: gcr.io/foo/bar:something
`)
if !assert.NoError(t, err) {
return
}
c, _ = GetContainerName(n)
assert.Equal(t, "gcr.io/foo/bar:something", c)
// doesn't have a container
n, err = yaml.Parse(`apiVersion: v1
kind: MyThing