Fix notes.txt problems

We were using a bad method to read the ingress values. It's not ensured
by using the service names + checking the "ingress" key.
This commit is contained in:
2024-04-21 16:35:32 +02:00
parent d48fd2f911
commit 9826a54187
4 changed files with 55 additions and 19 deletions

View File

@@ -242,7 +242,11 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) {
f.Write([]byte(readme))
f.Close()
notes := extrafiles.NotesFile()
services := make([]string, 0)
for _, service := range project.Services {
services = append(services, service.Name)
}
notes := extrafiles.NotesFile(services)
f, err = os.Create(notesPath)
if err != nil {
fmt.Println(utils.IconFailure, err)

View File

@@ -1,11 +1,31 @@
package extrafiles
import _ "embed"
import (
_ "embed"
"fmt"
"strings"
)
//go:embed notes.tpl
var notesTemplate string
// NoteTXTFile returns the content of the note.txt file.
func NotesFile() string {
return notesTemplate
// NotesFile returns the content of the note.txt file.
func NotesFile(services []string) string {
// build a list of ingress URLs if there are any
ingresses := make([]string, len(services))
for i, service := range services {
condition := fmt.Sprintf(`{{- if and .Values.%[1]s.ingress .Values.%[1]s.ingress.enabled }}`, service)
line := fmt.Sprintf(`{{- $count = add1 $count -}}{{- $listOfURL = printf "%%s\n- http://%%s" $listOfURL .Values.%s.ingress.host -}}`, service)
ingresses[i] = fmt.Sprintf("%s\n%s\n{{- end }}", condition, line)
}
// inject the list of ingress URLs into the notes template
notes := strings.Split(notesTemplate, "\n")
for i, line := range notes {
if strings.Contains(line, "ingress_list") {
notes[i] = strings.Join(ingresses, "\n")
}
}
return strings.Join(notes, "\n")
}

View File

@@ -1,27 +1,39 @@
Your release is named {{ .Release.Name }}.
Thanks to have installed {{ .Chart.Name }} {{ .Chart.Version }} as {{ .Release.Name }} ({{.Chart.AppVersion }}).
# Get release information
To learn more about the release, try:
$ helm -n {{ .Release.Namespace }} status {{ .Release.Name }}
$ helm -n {{ .Release.Namespace }} get values {{ .Release.Name }}
$ helm -n {{ .Release.Namespace }} get all {{ .Release.Name }}
To delete the release, run:
# To delete the release
$ helm -n {{ .Release.Namespace }} delete {{ .Release.Name }}
Use helm uninstall command to delete the release.
$ helm -n {{ .Release.Namespace }} uninstall {{ .Release.Name }}
Note that some resources may still be in use after a release is deleted. For exemple, PersistentVolumeClaims are not deleted by default for some storage classes or if some annotations are set.
# More information
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 }}
{{- $listOfURL := "" -}}
{{* DO NOT REMOVE, replaced by notes.go: ingress_list *}}
{{- if gt $count 0 }}
The ingress list is:
{{ end }}
- {{ $s }}: http://{{ $v.ingress.host }}{{ $v.ingress.path }}
{{- end -}}
{{ end -}}
# List of activated ingresses URL:
{{ $listOfURL }}
You can get these urls with kubectl:
kubeclt get ingress -n {{ .Release.Namespace }}
{{- end }}
Thanks for using Helm!

View File

@@ -22,10 +22,10 @@
{{- define "__APP__.labels" -}}
{{ include "__APP__.selectorLabels" .}}
{{ if .Chart.Version -}}
{{ printf "__PREFIX__chart-version: %s" .Chart.Version }}
{{ printf "__PREFIX__chart-version: '%s'" .Chart.Version }}
{{- end }}
{{ if .Chart.AppVersion -}}
{{ printf "__PREFIX__app-version: %s" .Chart.AppVersion }}
{{ printf "__PREFIX__app-version: '%s'" .Chart.AppVersion }}
{{- end }}
{{- end -}}