From e65dfaba10d1f5b9dc85f4de8d8b7892af1fecd9 Mon Sep 17 00:00:00 2001 From: John Norwood Date: Tue, 12 Jan 2021 22:54:37 +0000 Subject: [PATCH] fix: fixes broken comment parsing on values files with dos line endings --- example-charts/dos-line-endings/.helmignore | 23 ++++++++++++++++++ example-charts/dos-line-endings/Chart.yaml | 24 +++++++++++++++++++ .../dos-line-endings/templates/tls.yaml | 10 ++++++++ example-charts/dos-line-endings/values.yaml | 18 ++++++++++++++ pkg/helm/chart_info.go | 4 ++-- 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 example-charts/dos-line-endings/.helmignore create mode 100644 example-charts/dos-line-endings/Chart.yaml create mode 100644 example-charts/dos-line-endings/templates/tls.yaml create mode 100644 example-charts/dos-line-endings/values.yaml diff --git a/example-charts/dos-line-endings/.helmignore b/example-charts/dos-line-endings/.helmignore new file mode 100644 index 0000000..f82e96d --- /dev/null +++ b/example-charts/dos-line-endings/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/example-charts/dos-line-endings/Chart.yaml b/example-charts/dos-line-endings/Chart.yaml new file mode 100644 index 0000000..2533f42 --- /dev/null +++ b/example-charts/dos-line-endings/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: dos-line-endings +description: A chart whose values file has dos line endings rather than unix ones + + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +appVersion: 1.16.0 diff --git a/example-charts/dos-line-endings/templates/tls.yaml b/example-charts/dos-line-endings/templates/tls.yaml new file mode 100644 index 0000000..035cfcc --- /dev/null +++ b/example-charts/dos-line-endings/templates/tls.yaml @@ -0,0 +1,10 @@ +{{- if .Values.createTLS.enabled }} +apiVersion: v1 +kind: Secret +type: kubernetes.io/tls +metadata: + name: {{ .Release.Name }}-tls +data: + tls.crt: {{ .Values.createTLS.tls.cert }} + tls.key: {{ .Values.createTLS.tls.key }} +{{- end }} \ No newline at end of file diff --git a/example-charts/dos-line-endings/values.yaml b/example-charts/dos-line-endings/values.yaml new file mode 100644 index 0000000..3c78f42 --- /dev/null +++ b/example-charts/dos-line-endings/values.yaml @@ -0,0 +1,18 @@ +# Default values for helmdoc-test. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +livenessProbe: + httpGet: + # -- This is the liveness check endpoint + path: /healthz + port: http + +controller: + publishService: + # -- Whether to expose the ingress controller to the public world sdf + enabled: false + + # -- Number of nginx-ingress pods to load balance between sdf. + # Do not set this below 2. + replicas: 2 diff --git a/pkg/helm/chart_info.go b/pkg/helm/chart_info.go index c2dea49..406fc23 100644 --- a/pkg/helm/chart_info.go +++ b/pkg/helm/chart_info.go @@ -8,6 +8,7 @@ import ( "path" "regexp" "sort" + "strings" log "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" @@ -69,12 +70,11 @@ func getYamlFileContents(filename string) ([]byte, error) { } yamlFileContents, err := ioutil.ReadFile(filename) - if err != nil { panic(err) } - return []byte(yamlFileContents), nil + return []byte(strings.Replace(string(yamlFileContents), "\r\n", "\n", -1)), nil } func isErrorInReadingNecessaryFile(filePath string, loadError error) bool {