Go to Katenary V3
This is the next-gen of Katenary
This commit is contained in:
2
generator/extrafiles/doc.go
Normal file
2
generator/extrafiles/doc.go
Normal file
@@ -0,0 +1,2 @@
|
||||
/* extrafiles package provides function to generate the Chart files that are not objects. Like README.md and notes.txt... */
|
||||
package extrafiles
|
11
generator/extrafiles/notes.go
Normal file
11
generator/extrafiles/notes.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package extrafiles
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed notes.tpl
|
||||
var notesTemplate string
|
||||
|
||||
// NoteTXTFile returns the content of the note.txt file.
|
||||
func NotesFile() string {
|
||||
return notesTemplate
|
||||
}
|
27
generator/extrafiles/notes.tpl
Normal file
27
generator/extrafiles/notes.tpl
Normal file
@@ -0,0 +1,27 @@
|
||||
Your release is named {{ .Release.Name }}.
|
||||
|
||||
To learn more about the release, try:
|
||||
|
||||
$ helm -n {{ .Release.Namespace }} status {{ .Release.Name }}
|
||||
$ helm -n {{ .Release.Namespace }} get all {{ .Release.Name }}
|
||||
|
||||
To delete the release, run:
|
||||
|
||||
$ helm -n {{ .Release.Namespace }} delete {{ .Release.Name }}
|
||||
|
||||
You can see this notes again by running:
|
||||
|
||||
$ helm -n {{ .Release.Namespace }} get notes {{ .Release.Name }}
|
||||
|
||||
{{- $count := 0 -}}
|
||||
{{- range $s, $v := .Values -}}
|
||||
{{- if and $v $v.ingress -}}
|
||||
{{- $count = add $count 1 -}}
|
||||
{{- if eq $count 1 }}
|
||||
|
||||
The ingress list is:
|
||||
{{ end }}
|
||||
- {{ $s }}: http://{{ $v.ingress.host }}{{ $v.ingress.path }}
|
||||
{{- end -}}
|
||||
{{ end -}}
|
||||
|
99
generator/extrafiles/readme.go
Normal file
99
generator/extrafiles/readme.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package extrafiles
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
_ "embed"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type chart struct {
|
||||
Name string
|
||||
Description string
|
||||
Values []string
|
||||
}
|
||||
|
||||
//go:embed readme.tpl
|
||||
var readmeTemplate string
|
||||
|
||||
// ReadMeFile returns the content of the README.md file.
|
||||
func ReadMeFile(charname, description string, values map[string]any) string {
|
||||
|
||||
// values is a yaml structure with keys and structured values...
|
||||
// we want to make list of dot separated keys and their values
|
||||
|
||||
vv := map[string]any{}
|
||||
out, _ := yaml.Marshal(values)
|
||||
yaml.Unmarshal(out, &vv)
|
||||
|
||||
result := make(map[string]string)
|
||||
parseValues("", vv, result)
|
||||
|
||||
funcMap := template.FuncMap{
|
||||
"repeat": func(s string, count int) string {
|
||||
return strings.Repeat(s, count)
|
||||
},
|
||||
}
|
||||
tpl, err := template.New("readme").Funcs(funcMap).Parse(readmeTemplate)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
valuesLines := []string{}
|
||||
maxParamLen := 0
|
||||
maxDefaultLen := 0
|
||||
for key, value := range result {
|
||||
if len(key) > maxParamLen {
|
||||
maxParamLen = len(key)
|
||||
}
|
||||
if len(value) > maxDefaultLen {
|
||||
maxDefaultLen = len(value)
|
||||
}
|
||||
}
|
||||
for key, value := range result {
|
||||
valuesLines = append(valuesLines, fmt.Sprintf("| %-*s | %-*s |", maxParamLen, key, maxDefaultLen, value))
|
||||
}
|
||||
sort.Strings(valuesLines)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
err = tpl.Execute(buf, map[string]any{
|
||||
"DescrptionPadding": maxParamLen,
|
||||
"DefaultPadding": maxDefaultLen,
|
||||
"Chart": chart{
|
||||
Name: charname,
|
||||
Description: description,
|
||||
Values: valuesLines,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func parseValues(prefix string, values map[string]interface{}, result map[string]string) {
|
||||
for key, value := range values {
|
||||
path := key
|
||||
if prefix != "" {
|
||||
path = prefix + "." + key
|
||||
}
|
||||
|
||||
switch v := value.(type) {
|
||||
case []interface{}:
|
||||
for i, u := range v {
|
||||
parseValues(fmt.Sprintf("%s[%d]", path, i), map[string]interface{}{"value": u}, result)
|
||||
}
|
||||
case map[string]interface{}:
|
||||
parseValues(path, v, result)
|
||||
default:
|
||||
strValue := fmt.Sprintf("`%v`", value)
|
||||
result["`"+path+"`"] = strValue
|
||||
}
|
||||
}
|
||||
}
|
32
generator/extrafiles/readme.tpl
Normal file
32
generator/extrafiles/readme.tpl
Normal file
@@ -0,0 +1,32 @@
|
||||
# {{ .Chart.Name }}
|
||||
|
||||
{{ .Chart.Description }}
|
||||
|
||||
## Installing the Chart
|
||||
|
||||
To install the chart with the release name `my-release`:
|
||||
|
||||
```bash
|
||||
# Standard Helm install
|
||||
$ helm install my-release {{ .Chart.Name }}
|
||||
|
||||
# To use a custom namespace and force the creation of the namespace
|
||||
$ helm install my-release --namespace my-namespace --create-namespace {{ .Chart.Name }}
|
||||
|
||||
# To use a custom values file
|
||||
$ helm install my-release -f my-values.yaml {{ .Chart.Name }}
|
||||
```
|
||||
|
||||
See the [Helm documentation](https://helm.sh/docs/intro/using_helm/) for more information on installing and managing the chart.
|
||||
|
||||
## Configuration
|
||||
|
||||
The following table lists the configurable parameters of the {{ .Chart.Name }} chart and their default values.
|
||||
|
||||
| {{ printf "%-*s" .DescrptionPadding "Parameter" }} | {{ printf "%-*s" .DefaultPadding "Default" }} |
|
||||
| {{ repeat "-" .DescrptionPadding }} | {{ repeat "-" .DefaultPadding }} |
|
||||
{{- range .Chart.Values }}
|
||||
{{ . }}
|
||||
{{- end }}
|
||||
|
||||
|
Reference in New Issue
Block a user