From 9826a541874d82d913052de48799e93d14504f06 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Sun, 21 Apr 2024 16:35:32 +0200 Subject: [PATCH] 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. --- generator/converter.go | 6 +++++- generator/extrafiles/notes.go | 28 ++++++++++++++++++++++---- generator/extrafiles/notes.tpl | 36 ++++++++++++++++++++++------------ generator/helmHelper.tpl | 4 ++-- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/generator/converter.go b/generator/converter.go index d7eb267..71b9bd3 100644 --- a/generator/converter.go +++ b/generator/converter.go @@ -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) diff --git a/generator/extrafiles/notes.go b/generator/extrafiles/notes.go index 373e7ee..c2662e5 100644 --- a/generator/extrafiles/notes.go +++ b/generator/extrafiles/notes.go @@ -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") } diff --git a/generator/extrafiles/notes.tpl b/generator/extrafiles/notes.tpl index 3121a00..3c527d8 100644 --- a/generator/extrafiles/notes.tpl +++ b/generator/extrafiles/notes.tpl @@ -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! diff --git a/generator/helmHelper.tpl b/generator/helmHelper.tpl index 8d40010..f1b2515 100644 --- a/generator/helmHelper.tpl +++ b/generator/helmHelper.tpl @@ -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 -}}