From 0cae0feb9bc51cdcd59b1f661d5b3bd44113bf1f Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Tue, 7 Jan 2020 11:11:59 -0800 Subject: [PATCH] rename config.k8s.io/function to config.kubernetes.io/function --- cmd/config/docs/commands/run-fns.md | 6 +++--- .../internal/generateddocs/commands/docs.go | 6 +++--- .../examples/injection-tshirt-sizes/README.md | 2 +- .../local-resource/example-use.yaml | 2 +- .../examples/template-go-nginx/README.md | 2 +- .../local-resource/example-use.yaml | 2 +- .../template-heredoc-cockroachdb/README.md | 2 +- .../local-resource/example-use.yaml | 2 +- .../examples/validator-kubeval/README.md | 2 +- .../local-resource/example-use.yaml | 2 +- .../validator-resource-requests/README.md | 2 +- .../local-resource/example-use.yaml | 2 +- kyaml/kio/filters/container.go | 20 ++++++++++++++----- kyaml/kio/filters/container_test.go | 4 ++-- 14 files changed, 33 insertions(+), 23 deletions(-) diff --git a/cmd/config/docs/commands/run-fns.md b/cmd/config/docs/commands/run-fns.md index 48e934d8f..08b8f6020 100644 --- a/cmd/config/docs/commands/run-fns.md +++ b/cmd/config/docs/commands/run-fns.md @@ -22,7 +22,7 @@ order they appear in the file). #### Config Functions: - Config functions are specified as Kubernetes types containing a metadata.annotations.[config.k8s.io/function] + Config functions are specified as Kubernetes types containing a metadata.annotations.[config.kubernetes.io/function] field specifying an image for the container to run. This image tells run how to invoke the container. Example config function: @@ -32,7 +32,7 @@ order they appear in the file). kind: ExampleFunctionKind metadata: annotations: - config.k8s.io/function: | + config.kubernetes.io/function: | container: # function is invoked as a container running this image image: gcr.io/example/examplefunction:v1.0.1 @@ -41,7 +41,7 @@ order they appear in the file). configField: configValue In the preceding example, 'kustomize config run example/' would identify the function by - the metadata.annotations.[config.k8s.io/function] field. It would then write all Resources in the directory to + the metadata.annotations.[config.kubernetes.io/function] field. It would then write all Resources in the directory to a container stdin (running the gcr.io/example/examplefunction:v1.0.1 image). It would then write the container stdout back to example/, replacing the directory file contents. diff --git a/cmd/config/internal/generateddocs/commands/docs.go b/cmd/config/internal/generateddocs/commands/docs.go index d638549b7..039e3fbf4 100644 --- a/cmd/config/internal/generateddocs/commands/docs.go +++ b/cmd/config/internal/generateddocs/commands/docs.go @@ -220,7 +220,7 @@ order they appear in the file). #### Config Functions: - Config functions are specified as Kubernetes types containing a metadata.annotations.[config.k8s.io/function] + Config functions are specified as Kubernetes types containing a metadata.annotations.[config.kubernetes.io/function] field specifying an image for the container to run. This image tells run how to invoke the container. Example config function: @@ -230,7 +230,7 @@ order they appear in the file). kind: ExampleFunctionKind metadata: annotations: - config.k8s.io/function: | + config.kubernetes.io/function: | container: # function is invoked as a container running this image image: gcr.io/example/examplefunction:v1.0.1 @@ -239,7 +239,7 @@ order they appear in the file). configField: configValue In the preceding example, 'kustomize config run example/' would identify the function by - the metadata.annotations.[config.k8s.io/function] field. It would then write all Resources in the directory to + the metadata.annotations.[config.kubernetes.io/function] field. It would then write all Resources in the directory to a container stdin (running the gcr.io/example/examplefunction:v1.0.1 image). It would then write the container stdout back to example/, replacing the directory file contents. diff --git a/functions/examples/injection-tshirt-sizes/README.md b/functions/examples/injection-tshirt-sizes/README.md index 204ea11d8..1da48c642 100644 --- a/functions/examples/injection-tshirt-sizes/README.md +++ b/functions/examples/injection-tshirt-sizes/README.md @@ -15,7 +15,7 @@ Resource configuration, and looks for invalid configuration. ## Function invocation The function is invoked by authoring a [local Resource](local-resource) -with `metadata.annotations.[config.k8s.io/function]` and running: +with `metadata.annotations.[config.kubernetes.io/function]` and running: kustomize config run local-resource/ diff --git a/functions/examples/injection-tshirt-sizes/local-resource/example-use.yaml b/functions/examples/injection-tshirt-sizes/local-resource/example-use.yaml index 71f3d8878..8a4c4bd10 100644 --- a/functions/examples/injection-tshirt-sizes/local-resource/example-use.yaml +++ b/functions/examples/injection-tshirt-sizes/local-resource/example-use.yaml @@ -5,7 +5,7 @@ apiVersion: examples.config.kubernetes.io/v1beta1 kind: Validator metadata: annotations: - config.k8s.io/function: | + config.kubernetes.io/function: | container: image: gcr.io/kustomize-functions/example-tshirt:v0.1.0 --- diff --git a/functions/examples/template-go-nginx/README.md b/functions/examples/template-go-nginx/README.md index f90913b28..44a677ae2 100644 --- a/functions/examples/template-go-nginx/README.md +++ b/functions/examples/template-go-nginx/README.md @@ -25,7 +25,7 @@ function input, and writing the function output. ## Function invocation The function is invoked by authoring a [local Resource](local-resource) -with `metadata.annotations.[config.k8s.io/function]` and running: +with `metadata.annotations.[config.kubernetes.io/function]` and running: kustomize config run local-resource/ diff --git a/functions/examples/template-go-nginx/local-resource/example-use.yaml b/functions/examples/template-go-nginx/local-resource/example-use.yaml index f0de94576..972e34996 100644 --- a/functions/examples/template-go-nginx/local-resource/example-use.yaml +++ b/functions/examples/template-go-nginx/local-resource/example-use.yaml @@ -6,7 +6,7 @@ kind: Nginx metadata: name: demo annotations: - config.k8s.io/function: | + config.kubernetes.io/function: | container: image: gcr.io/kustomize-functions/example-nginx:v0.1.0 spec: diff --git a/functions/examples/template-heredoc-cockroachdb/README.md b/functions/examples/template-heredoc-cockroachdb/README.md index 68bb23bf3..96be73e02 100644 --- a/functions/examples/template-heredoc-cockroachdb/README.md +++ b/functions/examples/template-heredoc-cockroachdb/README.md @@ -20,7 +20,7 @@ heavy lifting of implementing the function interface. ## Function invocation The function is invoked by authoring a [local Resource](local-resource) -with `metadata.annotations.[config.k8s.io/function]` and running: +with `metadata.annotations.[config.kubernetes.io/function]` and running: kustomize config run local-resource/ diff --git a/functions/examples/template-heredoc-cockroachdb/local-resource/example-use.yaml b/functions/examples/template-heredoc-cockroachdb/local-resource/example-use.yaml index fa598b488..37c48f040 100644 --- a/functions/examples/template-heredoc-cockroachdb/local-resource/example-use.yaml +++ b/functions/examples/template-heredoc-cockroachdb/local-resource/example-use.yaml @@ -7,7 +7,7 @@ kind: CockroachDB metadata: name: demo annotations: - config.k8s.io/function: | + config.kubernetes.io/function: | container: image: gcr.io/kustomize-functions/example-cockroachdb:v0.1.0 spec: diff --git a/functions/examples/validator-kubeval/README.md b/functions/examples/validator-kubeval/README.md index ffbc98608..85ca92b38 100644 --- a/functions/examples/validator-kubeval/README.md +++ b/functions/examples/validator-kubeval/README.md @@ -18,7 +18,7 @@ the `API` struct definition in [main.go](image/main.go) for documentation. ## Function invocation The function is invoked by authoring a [local Resource](local-resource) -with `metadata.annotations.[config.k8s.io/function]` and running: +with `metadata.annotations.[config.kubernetes.io/function]` and running: kustomize config run local-resource/ diff --git a/functions/examples/validator-kubeval/local-resource/example-use.yaml b/functions/examples/validator-kubeval/local-resource/example-use.yaml index 96fdb80f7..d18722b62 100644 --- a/functions/examples/validator-kubeval/local-resource/example-use.yaml +++ b/functions/examples/validator-kubeval/local-resource/example-use.yaml @@ -5,7 +5,7 @@ apiVersion: examples.config.kubernetes.io/v1beta1 kind: Kubeval metadata: annotations: - config.k8s.io/function: | + config.kubernetes.io/function: | container: image: gcr.io/kustomize-functions/example-validator-kubeval:v0.1.0 spec: diff --git a/functions/examples/validator-resource-requests/README.md b/functions/examples/validator-resource-requests/README.md index 9689a0b69..03e4685f8 100644 --- a/functions/examples/validator-resource-requests/README.md +++ b/functions/examples/validator-resource-requests/README.md @@ -15,7 +15,7 @@ Resource configuration, and looks for invalid configuration. ## Function invocation The function is invoked by authoring a [local Resource](local-resource) -with `metadata.annotations.[config.k8s.io/function]` and running: +with `metadata.annotations.[config.kubernetes.io/function]` and running: kustomize config run local-resource/ diff --git a/functions/examples/validator-resource-requests/local-resource/example-use.yaml b/functions/examples/validator-resource-requests/local-resource/example-use.yaml index 39f537f79..0aa371e6f 100644 --- a/functions/examples/validator-resource-requests/local-resource/example-use.yaml +++ b/functions/examples/validator-resource-requests/local-resource/example-use.yaml @@ -5,7 +5,7 @@ apiVersion: examples.config.kubernetes.io/v1beta1 kind: Validator metadata: annotations: - config.k8s.io/function: | + config.kubernetes.io/function: | container: image: gcr.io/kustomize-functions/example-validator:v0.1.0 --- diff --git a/kyaml/kio/filters/container.go b/kyaml/kio/filters/container.go index cdc01293e..2af93e7ab 100644 --- a/kyaml/kio/filters/container.go +++ b/kyaml/kio/filters/container.go @@ -194,6 +194,13 @@ func (c *IsReconcilerFilter) Filter(inputs []*yaml.RNode) ([]*yaml.RNode, error) return out, nil } +const ( + FunctionAnnotationKey = "config.kubernetes.io/function" + oldFunctionAnnotationKey = "config.k8s.io/function" +) + +var functionAnnotationKeys = []string{FunctionAnnotationKey, oldFunctionAnnotationKey} + // GetContainerName returns the container image for an API if one exists func GetContainerName(n *yaml.RNode) (string, string) { meta, _ := n.GetMeta() @@ -201,11 +208,14 @@ 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 + // check previous keys for backwards compatibility + for _, s := range functionAnnotationKeys { + functionAnnotation := meta.Annotations[s] + 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"] diff --git a/kyaml/kio/filters/container_test.go b/kyaml/kio/filters/container_test.go index 314400e6f..5a573a8f1 100644 --- a/kyaml/kio/filters/container_test.go +++ b/kyaml/kio/filters/container_test.go @@ -333,12 +333,12 @@ metadata: c, _ = GetContainerName(n) assert.Equal(t, "gcr.io/foo/bar:something", c) - // container from config.k8s.io/function annotation + // container from config.kubernetes.io/function annotation n, err = yaml.Parse(`apiVersion: v1 kind: MyThing metadata: annotations: - config.k8s.io/function: | + config.kubernetes.io/function: | container: image: gcr.io/foo/bar:something `)