From 3204fe90630530a8442d0bb95005d2e4d27bd96a Mon Sep 17 00:00:00 2001 From: Afshin Mehrabani Date: Fri, 15 Jun 2018 14:35:10 +0100 Subject: [PATCH] chore(docs): updating the docs of AsConfig and AsSecret methods --- docs/chart_template_guide/accessing_files.md | 4 ++++ pkg/chartutil/files.go | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/chart_template_guide/accessing_files.md b/docs/chart_template_guide/accessing_files.md index 11747d4f0..9beef0c92 100644 --- a/docs/chart_template_guide/accessing_files.md +++ b/docs/chart_template_guide/accessing_files.md @@ -162,6 +162,10 @@ metadata: type: Opaque data: {{ (.Files.Glob "bar/*").AsSecrets | indent 2 }} + +In above example, `AsSecrets` and `AsConfig` convert the files in `foo/` directory to +Kubernetes ConfigMap and Secret definition. Both `AsSecrets` and `AsConfig` methods respect the +path of the file and include the path in the key. For example, `foo/boo.txt` generates a key of `foo_boo.txt`. ``` ## Encoding diff --git a/pkg/chartutil/files.go b/pkg/chartutil/files.go index bf1b6d7b3..aa4afc89b 100644 --- a/pkg/chartutil/files.go +++ b/pkg/chartutil/files.go @@ -19,12 +19,12 @@ import ( "bytes" "encoding/base64" "encoding/json" + "fmt" "path" "strings" "github.com/ghodss/yaml" - "fmt" "github.com/BurntSushi/toml" "github.com/gobwas/glob" "github.com/golang/protobuf/ptypes/any" @@ -96,8 +96,12 @@ func (f Files) Glob(pattern string) Files { // AsConfig turns a Files group and flattens it to a YAML map suitable for // including in the 'data' section of a Kubernetes ConfigMap definition. -// Duplicate keys will be overwritten, so be aware that your file names -// (regardless of path) should be unique. +// Duplicate keys under the same path will be overwritten, so be aware that +// your file names should be unique. +// +// AsConfig respects the path of the file and converts `/` to `_`: +// +// `ship/captain.txt` will be `ship_captain.txt` in the ConfigMap definition. // // This is designed to be called from a template, and will return empty string // (via ToYaml function) if it cannot be serialized to YAML, or if the Files @@ -144,8 +148,12 @@ func AsConfigKey(k string) string { // AsSecrets returns the base64-encoded value of a Files object suitable for // including in the 'data' section of a Kubernetes Secret definition. -// Duplicate keys will be overwritten, so be aware that your file names -// (regardless of path) should be unique. +// Duplicate keys under the same path will be overwritten, so be aware that +// your file names should be unique. +// +// AsSecrets respects the path of the file and converts `/` to `_`: +// +// `ship/captain.txt` will be `ship_captain.txt` in the Secret definition. // // This is designed to be called from a template, and will return empty string // (via ToYaml function) if it cannot be serialized to YAML, or if the Files