-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from terrycain/107-files
Added Helm .Files
- Loading branch information
Showing
12 changed files
with
433 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v2 | ||
name: best-values-example | ||
description: One of the best values parsing example charts here, exhibits several more complicated examples | ||
version: "0.2.0" | ||
home: "https://github.com/norwoodj/helm-docs/tree/master/example-charts/best-values-example" | ||
sources: ["https://github.com/norwoodj/helm-docs/tree/master/example-charts/best-values-example"] | ||
engine: gotpl | ||
type: application | ||
maintainers: | ||
- email: norwood.john.m@gmail.com | ||
name: John Norwood |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# best-values-example | ||
|
||
One of the best values parsing example charts here, exhibits several more complicated examples | ||
|
||
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) | ||
|
||
## Additional Information | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore | ||
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut | ||
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse | ||
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in | ||
culpa qui officia deserunt mollit anim id est laborum. | ||
|
||
## Installing the Chart | ||
|
||
To install the chart with the release name `my-release`: | ||
|
||
```console | ||
$ helm repo add foo-bar http://charts.foo-bar.com | ||
$ helm install my-release foo-bar/best-values-example | ||
``` | ||
|
||
Some file contents: | ||
|
||
``` | ||
some: | ||
data: "test" | ||
``` | ||
|
||
Glob contents as config map: | ||
|
||
``` | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: test | ||
data: | ||
resource1.yaml: |- | ||
some: | ||
resource: "blah" | ||
resource2.yaml: |- | ||
some: | ||
resource: "blah2" | ||
``` | ||
|
||
## Values | ||
|
||
| Key | Type | Default | Description | | ||
|-----|------|---------|-------------| | ||
| config.databasesToCreate[0] | string | `"postgresql"` | default database for storage of database metadata | | ||
| config.databasesToCreate[1] | string | `"hashbash"` | database for the [hashbash](https://github.com/norwoodj/hashbash) project | | ||
| config.usersToCreate[0] | object | `{"admin":true,"name":"root"}` | admin user | | ||
| config.usersToCreate[1] | object | `{"name":"hashbash","readwriteDatabases":["hashbash"]}` | user with access to the database with the same name | | ||
| statefulset.extraVolumes | list | `[{"emptyDir":{},"name":"data"}]` | Additional volumes to be mounted into the database container | | ||
| statefulset.image.repository | string | `"jnorwood/postgresq"` | Image to use for deploying, must support an entrypoint which creates users/databases from appropriate config files | | ||
| statefulset.image.tag | string | `"11"` | | | ||
| statefulset.livenessProbe | object | `{"enabled":false}` | Configure the healthcheck for the database | | ||
| statefulset.podLabels | object | `{}` | The labels to be applied to instances of the database | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{{ template "chart.header" . }} | ||
{{ template "chart.description" . }} | ||
|
||
{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }} | ||
|
||
## Additional Information | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore | ||
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut | ||
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse | ||
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in | ||
culpa qui officia deserunt mollit anim id est laborum. | ||
|
||
## Installing the Chart | ||
|
||
To install the chart with the release name `my-release`: | ||
|
||
```console | ||
$ helm repo add foo-bar http://charts.foo-bar.com | ||
$ helm install my-release foo-bar/{{ template "chart.name" . }} | ||
``` | ||
|
||
Some file contents: | ||
|
||
``` | ||
{{ .Files.Get "somefile.yaml" }} | ||
``` | ||
|
||
Glob contents as config map: | ||
|
||
``` | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: test | ||
data: | ||
{{ (.Files.Glob "templates/**.yaml").AsConfig | indent 2 }} | ||
``` | ||
|
||
{{ template "chart.requirementsSection" . }} | ||
|
||
{{ template "chart.valuesSection" . }} | ||
|
||
{{ template "helm-docs.versionFooter" . }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
some: | ||
data: "test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
some: | ||
resource: "blah" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
some: | ||
resource: "blah2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
statefulset: | ||
image: | ||
# -- Image to use for deploying, must support an entrypoint which creates users/databases from appropriate config files | ||
repository: jnorwood/postgresq | ||
tag: "11" | ||
|
||
# -- Additional volumes to be mounted into the database container | ||
extraVolumes: | ||
- name: data | ||
emptyDir: {} | ||
|
||
# -- Configure the healthcheck for the database | ||
livenessProbe: | ||
enabled: false | ||
|
||
# -- The labels to be applied to instances of the database | ||
podLabels: {} | ||
|
||
config: | ||
databasesToCreate: | ||
# -- default database for storage of database metadata | ||
- postgresql | ||
|
||
# -- database for the [hashbash](https://github.com/norwoodj/hashbash) project | ||
- hashbash | ||
|
||
usersToCreate: | ||
# -- admin user | ||
- {name: root, admin: true} | ||
|
||
# -- user with access to the database with the same name | ||
- {name: hashbash, readwriteDatabases: [hashbash]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package document | ||
|
||
import ( | ||
"encoding/base64" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/gobwas/glob" | ||
log "github.com/sirupsen/logrus" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// Near identical to https://github.com/helm/helm/blob/main/pkg/engine/files.go as to preserve the interface. | ||
|
||
type fileEntry struct { | ||
Path string | ||
data []byte | ||
} | ||
|
||
func (f *fileEntry) GetData() []byte { | ||
if f.data == nil { | ||
data, err := ioutil.ReadFile(f.Path) | ||
if err != nil { | ||
log.Warnf("Error reading file contents for %s: %s", f.Path, err.Error()) | ||
return []byte{} | ||
} | ||
f.data = data | ||
} | ||
|
||
return f.data | ||
} | ||
|
||
type files map[string]*fileEntry | ||
|
||
func getFiles(dir string) (files, error) { | ||
result := make(files) | ||
|
||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if info.IsDir() { | ||
return nil | ||
} | ||
|
||
result[path] = &fileEntry{Path: path} | ||
return nil | ||
}) | ||
if err != nil { | ||
return map[string]*fileEntry{}, err | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func (f files) GetBytes(name string) []byte { | ||
if v, ok := f[name]; ok { | ||
return v.GetData() | ||
} | ||
return []byte{} | ||
} | ||
|
||
func (f files) Get(name string) string { | ||
return string(f.GetBytes(name)) | ||
} | ||
|
||
func (f files) Glob(pattern string) files { | ||
result := make(files) | ||
g, err := glob.Compile(pattern, '/') | ||
if err != nil { | ||
log.Warnf("Error compiling Glob patten %s: %s", pattern, err.Error()) | ||
return result | ||
} | ||
|
||
for filePath, entry := range f { | ||
if g.Match(filePath) { | ||
result[filePath] = entry | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
func (f files) AsConfig() string { | ||
if f == nil { | ||
return "" | ||
} | ||
|
||
m := make(map[string]string) | ||
|
||
// Explicitly convert to strings, and file names | ||
for k, v := range f { | ||
m[path.Base(k)] = string(v.GetData()) | ||
} | ||
|
||
return toYAML(m) | ||
} | ||
|
||
func (f files) AsSecrets() string { | ||
if f == nil { | ||
return "" | ||
} | ||
|
||
m := make(map[string]string) | ||
|
||
for k, v := range f { | ||
m[path.Base(k)] = base64.StdEncoding.EncodeToString(v.GetData()) | ||
} | ||
|
||
return toYAML(m) | ||
} | ||
|
||
func (f files) Lines(path string) []string { | ||
if f == nil { | ||
return []string{} | ||
} | ||
entry, exists := f[path] | ||
if !exists { | ||
return []string{} | ||
} | ||
|
||
return strings.Split(string(entry.GetData()), "\n") | ||
} | ||
|
||
func toYAML(v interface{}) string { | ||
data, err := yaml.Marshal(v) | ||
if err != nil { | ||
// Swallow errors inside a template. | ||
return "" | ||
} | ||
return strings.TrimSuffix(string(data), "\n") | ||
} |
Oops, something went wrong.