Skip to content

Commit b556d85

Browse files
committed
Added Helm .Files
1 parent 4b55b9e commit b556d85

File tree

12 files changed

+408
-0
lines changed

12 files changed

+408
-0
lines changed
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v2
2+
name: best-values-example
3+
description: One of the best values parsing example charts here, exhibits several more complicated examples
4+
version: "0.2.0"
5+
home: "https://github.com/norwoodj/helm-docs/tree/master/example-charts/best-values-example"
6+
sources: ["https://github.com/norwoodj/helm-docs/tree/master/example-charts/best-values-example"]
7+
engine: gotpl
8+
type: application
9+
maintainers:
10+
11+
name: John Norwood

example-charts/files-values/README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# best-values-example
2+
3+
One of the best values parsing example charts here, exhibits several more complicated examples
4+
5+
![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)
6+
7+
## Additional Information
8+
9+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
10+
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
11+
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
12+
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
13+
culpa qui officia deserunt mollit anim id est laborum.
14+
15+
## Installing the Chart
16+
17+
To install the chart with the release name `my-release`:
18+
19+
```console
20+
$ helm repo add foo-bar http://charts.foo-bar.com
21+
$ helm install my-release foo-bar/best-values-example
22+
```
23+
24+
Some file contents:
25+
26+
```
27+
some:
28+
data: "test"
29+
```
30+
31+
Glob contents as config map:
32+
33+
```
34+
apiVersion: v1
35+
kind: ConfigMap
36+
metadata:
37+
name: test
38+
data:
39+
resource1.yaml: |-
40+
some:
41+
resource: "blah"
42+
resource2.yaml: |-
43+
some:
44+
resource: "blah2"
45+
```
46+
47+
## Values
48+
49+
| Key | Type | Default | Description |
50+
|-----|------|---------|-------------|
51+
| config.databasesToCreate[0] | string | `"postgresql"` | default database for storage of database metadata |
52+
| config.databasesToCreate[1] | string | `"hashbash"` | database for the [hashbash](https://github.com/norwoodj/hashbash) project |
53+
| config.usersToCreate[0] | object | `{"admin":true,"name":"root"}` | admin user |
54+
| config.usersToCreate[1] | object | `{"name":"hashbash","readwriteDatabases":["hashbash"]}` | user with access to the database with the same name |
55+
| statefulset.extraVolumes | list | `[{"emptyDir":{},"name":"data"}]` | Additional volumes to be mounted into the database container |
56+
| statefulset.image.repository | string | `"jnorwood/postgresq"` | Image to use for deploying, must support an entrypoint which creates users/databases from appropriate config files |
57+
| statefulset.image.tag | string | `"11"` | |
58+
| statefulset.livenessProbe | object | `{"enabled":false}` | Configure the healthcheck for the database |
59+
| statefulset.podLabels | object | `{}` | The labels to be applied to instances of the database |
60+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{{ template "chart.header" . }}
2+
{{ template "chart.description" . }}
3+
4+
{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}
5+
6+
## Additional Information
7+
8+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
9+
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
10+
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
11+
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
12+
culpa qui officia deserunt mollit anim id est laborum.
13+
14+
## Installing the Chart
15+
16+
To install the chart with the release name `my-release`:
17+
18+
```console
19+
$ helm repo add foo-bar http://charts.foo-bar.com
20+
$ helm install my-release foo-bar/{{ template "chart.name" . }}
21+
```
22+
23+
Some file contents:
24+
25+
```
26+
{{ .Files.Get "somefile.yaml" }}
27+
```
28+
29+
Glob contents as config map:
30+
31+
```
32+
apiVersion: v1
33+
kind: ConfigMap
34+
metadata:
35+
name: test
36+
data:
37+
{{ (.Files.Glob "templates/**.yaml").AsConfig | indent 2 }}
38+
```
39+
40+
{{ template "chart.requirementsSection" . }}
41+
42+
{{ template "chart.valuesSection" . }}
43+
44+
{{ template "helm-docs.versionFooter" . }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
some:
2+
data: "test"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
some:
2+
resource: "blah"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
some:
2+
resource: "blah2"
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
statefulset:
2+
image:
3+
# -- Image to use for deploying, must support an entrypoint which creates users/databases from appropriate config files
4+
repository: jnorwood/postgresq
5+
tag: "11"
6+
7+
# -- Additional volumes to be mounted into the database container
8+
extraVolumes:
9+
- name: data
10+
emptyDir: {}
11+
12+
# -- Configure the healthcheck for the database
13+
livenessProbe:
14+
enabled: false
15+
16+
# -- The labels to be applied to instances of the database
17+
podLabels: {}
18+
19+
config:
20+
databasesToCreate:
21+
# -- default database for storage of database metadata
22+
- postgresql
23+
24+
# -- database for the [hashbash](https://github.com/norwoodj/hashbash) project
25+
- hashbash
26+
27+
usersToCreate:
28+
# -- admin user
29+
- {name: root, admin: true}
30+
31+
# -- user with access to the database with the same name
32+
- {name: hashbash, readwriteDatabases: [hashbash]}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.14
44

55
require (
66
github.com/Masterminds/sprig/v3 v3.2.2
7+
github.com/gobwas/glob v0.2.3
78
github.com/sirupsen/logrus v1.2.0
89
github.com/spf13/cobra v0.0.5
910
github.com/spf13/viper v1.4.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
3434
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
3535
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
3636
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
37+
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
38+
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
3739
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
3840
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
3941
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=

pkg/document/files.go

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package document
2+
3+
import (
4+
"encoding/base64"
5+
"io/ioutil"
6+
"os"
7+
"path"
8+
"path/filepath"
9+
"strings"
10+
11+
"github.com/gobwas/glob"
12+
"gopkg.in/yaml.v3"
13+
)
14+
15+
// Near identical to https://github.com/helm/helm/blob/main/pkg/engine/files.go as to preserve the interface.
16+
17+
type files map[string][]byte
18+
19+
func getFiles(dir string) (files, error) {
20+
result := make(files)
21+
22+
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
23+
if err != nil {
24+
return err
25+
}
26+
27+
if info.IsDir() {
28+
return nil
29+
}
30+
31+
data, err := ioutil.ReadFile(path)
32+
if err != nil {
33+
return err
34+
}
35+
36+
result[path] = data
37+
38+
return nil
39+
})
40+
if err != nil {
41+
return map[string][]byte{}, err
42+
}
43+
44+
return result, nil
45+
}
46+
47+
func (f files) GetBytes(name string) []byte {
48+
if v, ok := f[name]; ok {
49+
return v
50+
}
51+
return []byte{}
52+
}
53+
54+
func (f files) Get(name string) string {
55+
return string(f.GetBytes(name))
56+
}
57+
58+
func (f files) Glob(pattern string) files {
59+
g, err := glob.Compile(pattern, '/')
60+
if err != nil {
61+
g, _ = glob.Compile("**")
62+
}
63+
64+
result := make(files)
65+
for name, contents := range f {
66+
if g.Match(name) {
67+
result[name] = contents
68+
}
69+
}
70+
71+
return result
72+
}
73+
74+
func (f files) AsConfig() string {
75+
if f == nil {
76+
return ""
77+
}
78+
79+
m := make(map[string]string)
80+
81+
// Explicitly convert to strings, and file names
82+
for k, v := range f {
83+
m[path.Base(k)] = string(v)
84+
}
85+
86+
return toYAML(m)
87+
}
88+
89+
func (f files) AsSecrets() string {
90+
if f == nil {
91+
return ""
92+
}
93+
94+
m := make(map[string]string)
95+
96+
for k, v := range f {
97+
m[path.Base(k)] = base64.StdEncoding.EncodeToString(v)
98+
}
99+
100+
return toYAML(m)
101+
}
102+
103+
func (f files) Lines(path string) []string {
104+
if f == nil || f[path] == nil {
105+
return []string{}
106+
}
107+
108+
return strings.Split(string(f[path]), "\n")
109+
}
110+
111+
func toYAML(v interface{}) string {
112+
data, err := yaml.Marshal(v)
113+
if err != nil {
114+
// Swallow errors inside a template.
115+
return ""
116+
}
117+
return strings.TrimSuffix(string(data), "\n")
118+
}

0 commit comments

Comments
 (0)