From dd5640ca11fd2a7a2f77a202b06f680ece880949 Mon Sep 17 00:00:00 2001 From: John Norwood Date: Sat, 24 Feb 2024 12:32:21 +0000 Subject: [PATCH] fix: Solves #217 where helm-docs would segfault due in charts with certain comment format The issue was that if a user had a comment which started with the old comment format "# field.name -- description", but then underneath had a comment of the new format "# -- description", the tool would mark the field as having an old style comment, with the key pulled from the latter comment "". This meant that we'd try to document the root-level mapping node, however the key is `nil` at this point. --- example-charts/best-values-example/README.md | 2 -- example-charts/custom-template/README.md | 2 -- example-charts/custom-value-notation-type/README.md | 2 -- example-charts/dos-line-endings/README.md | 2 -- example-charts/files-values/README.md | 2 -- example-charts/full-template/README.md | 2 -- example-charts/fully-documented/README.md | 2 -- example-charts/funky-version/README.md | 2 -- example-charts/helm-3/README.md | 2 -- example-charts/ignored-values-example/README.md | 2 -- example-charts/most-empty/README.md | 2 -- example-charts/nginx-ingress-but-auto-comments/README.md | 2 -- example-charts/nginx-ingress/README.md | 2 -- example-charts/no-requirements/README.md | 2 -- example-charts/no-values/README.md | 2 -- .../special-characters-but-auto-comments/README.md | 2 -- example-charts/special-characters/README.md | 2 -- example-charts/umbrella/README.md | 2 -- example-charts/umbrella/charts/sub-a/README.md | 2 -- example-charts/umbrella/charts/sub-b/README.md | 2 -- example-charts/umbrella/charts/sub-c/README.md | 2 -- pkg/helm/chart_info.go | 5 ++++- 22 files changed, 4 insertions(+), 43 deletions(-) diff --git a/example-charts/best-values-example/README.md b/example-charts/best-values-example/README.md index 6c1a34d..08c5103 100644 --- a/example-charts/best-values-example/README.md +++ b/example-charts/best-values-example/README.md @@ -30,5 +30,3 @@ One of the best values parsing example charts here, exhibits several more compli | statefulset.livenessProbe | object | `{"enabled":false}` | Configure the healthcheck for the database | | statefulset.podLabels | object | `{}` | The labels to be applied to instances of the database | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/custom-template/README.md b/example-charts/custom-template/README.md index 0ef4c46..2b50aba 100644 --- a/example-charts/custom-template/README.md +++ b/example-charts/custom-template/README.md @@ -58,5 +58,3 @@ $ helm install my-release foo-bar/custom-template | controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service | | controller.service.type | string | `"LoadBalancer"` | | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/custom-value-notation-type/README.md b/example-charts/custom-value-notation-type/README.md index 0b547ac..6c9b7bd 100644 --- a/example-charts/custom-value-notation-type/README.md +++ b/example-charts/custom-value-notation-type/README.md @@ -1104,5 +1104,3 @@ string ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/dos-line-endings/README.md b/example-charts/dos-line-endings/README.md index 0ad1cd1..e0701c4 100644 --- a/example-charts/dos-line-endings/README.md +++ b/example-charts/dos-line-endings/README.md @@ -13,5 +13,3 @@ A chart whose values file has dos line endings rather than unix ones | livenessProbe.httpGet.path | string | `"/healthz"` | This is the liveness check endpoint | | livenessProbe.httpGet.port | string | `"http"` | | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/files-values/README.md b/example-charts/files-values/README.md index a78d1fd..582317d 100644 --- a/example-charts/files-values/README.md +++ b/example-charts/files-values/README.md @@ -67,5 +67,3 @@ File: example-charts/files-values/values.yaml | statefulset.livenessProbe | object | `{"enabled":false}` | Configure the healthcheck for the database | | statefulset.podLabels | object | `{}` | The labels to be applied to instances of the database | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/full-template/README.md b/example-charts/full-template/README.md index 99876f9..f11a153 100644 --- a/example-charts/full-template/README.md +++ b/example-charts/full-template/README.md @@ -162,5 +162,3 @@ Kubernetes: `<=1.18` | controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service | | controller.service.type | string | `"LoadBalancer"` | | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/fully-documented/README.md b/example-charts/fully-documented/README.md index 615d726..3011937 100644 --- a/example-charts/fully-documented/README.md +++ b/example-charts/fully-documented/README.md @@ -32,5 +32,3 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co | controller.image.tag | string | `"18.0831"` | The tag of the image of the controller | | controller.name | string | `"controller"` | The name of the controller | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/funky-version/README.md b/example-charts/funky-version/README.md index 09a2534..6d7c960 100644 --- a/example-charts/funky-version/README.md +++ b/example-charts/funky-version/README.md @@ -16,5 +16,3 @@ A very simple chart with a funky version * ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/helm-3/README.md b/example-charts/helm-3/README.md index bb07006..0defcc9 100644 --- a/example-charts/helm-3/README.md +++ b/example-charts/helm-3/README.md @@ -40,5 +40,3 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co | controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service | | controller.service.type | string | `"LoadBalancer"` | | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/ignored-values-example/README.md b/example-charts/ignored-values-example/README.md index f5ed81f..c2f75c3 100644 --- a/example-charts/ignored-values-example/README.md +++ b/example-charts/ignored-values-example/README.md @@ -31,5 +31,3 @@ Based on best-values-example | statefulset.livenessProbe | object | `{"enabled":false}` | Configure the healthcheck for the database | | statefulset.podLabels | object | `{}` | The labels to be applied to instances of the database | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/most-empty/README.md b/example-charts/most-empty/README.md index ca41e7e..3e7c948 100644 --- a/example-charts/most-empty/README.md +++ b/example-charts/most-empty/README.md @@ -20,5 +20,3 @@ There is a flower though: __|_____________ ``` ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/nginx-ingress-but-auto-comments/README.md b/example-charts/nginx-ingress-but-auto-comments/README.md index 63ebdbf..e4f70d9 100644 --- a/example-charts/nginx-ingress-but-auto-comments/README.md +++ b/example-charts/nginx-ingress-but-auto-comments/README.md @@ -40,5 +40,3 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co | controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service | | controller.service.type | string | `"LoadBalancer"` | | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/nginx-ingress/README.md b/example-charts/nginx-ingress/README.md index 1e75384..4c77e9f 100644 --- a/example-charts/nginx-ingress/README.md +++ b/example-charts/nginx-ingress/README.md @@ -40,5 +40,3 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co | controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service | | controller.service.type | string | `"LoadBalancer"` | | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/no-requirements/README.md b/example-charts/no-requirements/README.md index 9c84997..4ef8502 100644 --- a/example-charts/no-requirements/README.md +++ b/example-charts/no-requirements/README.md @@ -25,5 +25,3 @@ A simple chart that installs, let's say PrometheusRules, that needs no sub-chart | rules.statusCodes.codes.5xx.duration | string | `"5m"` | Duration for which the percent of 5xx responses must be above the threshold to alert | | rules.statusCodes.codes.5xx.threshold | float | `1.5` | Threshold percentage of 5xx responses above which the alert will fire | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/no-values/README.md b/example-charts/no-values/README.md index 2204a7b..582f2d9 100644 --- a/example-charts/no-values/README.md +++ b/example-charts/no-values/README.md @@ -16,5 +16,3 @@ A very simple chart that doesn't even need any values for customization * ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/special-characters-but-auto-comments/README.md b/example-charts/special-characters-but-auto-comments/README.md index 6b37050..354f736 100644 --- a/example-charts/special-characters-but-auto-comments/README.md +++ b/example-charts/special-characters-but-auto-comments/README.md @@ -26,5 +26,3 @@ A chart demonstrating handling of special characters in values files | htmlSnippets.three | string | `""` | Another description | | htmlSnippets.two | string | `""` | Let's put it in the description | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/special-characters/README.md b/example-charts/special-characters/README.md index 6b37050..354f736 100644 --- a/example-charts/special-characters/README.md +++ b/example-charts/special-characters/README.md @@ -26,5 +26,3 @@ A chart demonstrating handling of special characters in values files | htmlSnippets.three | string | `""` | Another description | | htmlSnippets.two | string | `""` | Let's put it in the description | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/umbrella/README.md b/example-charts/umbrella/README.md index b14a950..8976820 100644 --- a/example-charts/umbrella/README.md +++ b/example-charts/umbrella/README.md @@ -24,5 +24,3 @@ A chart demonstrating that values documentation from child charts are aggregated | sub-a.mySubKeyA | string | `"my-sub-value-a"` | Value for sub-chart A | | sub-b.mySubKeyB | string | `"my-sub-value-b"` | Value for sub-chart B | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/umbrella/charts/sub-a/README.md b/example-charts/umbrella/charts/sub-a/README.md index f18ac9f..a04f1be 100644 --- a/example-charts/umbrella/charts/sub-a/README.md +++ b/example-charts/umbrella/charts/sub-a/README.md @@ -18,5 +18,3 @@ A sub-chart. | global.myGlobalSubChartKey | string | `"my-global-sub-chart-value"` | A global key defined in a sub chart | | mySubKeyA | string | `"my-sub-value-a"` | Value for sub-chart A | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/umbrella/charts/sub-b/README.md b/example-charts/umbrella/charts/sub-b/README.md index 0d37870..383e1a0 100644 --- a/example-charts/umbrella/charts/sub-b/README.md +++ b/example-charts/umbrella/charts/sub-b/README.md @@ -17,5 +17,3 @@ A sub-chart. | global.myGlobalKey | string | `"my-global-value"` | A global key | | mySubKeyB | string | `"my-sub-value-b"` | Value for sub-chart B | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/example-charts/umbrella/charts/sub-c/README.md b/example-charts/umbrella/charts/sub-c/README.md index b0463ae..d5167fc 100644 --- a/example-charts/umbrella/charts/sub-c/README.md +++ b/example-charts/umbrella/charts/sub-c/README.md @@ -16,5 +16,3 @@ A sub-chart. |-----|------|---------|-------------| | global | object | `{}` | | ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/pkg/helm/chart_info.go b/pkg/helm/chart_info.go index 7c4e2a7..424afb4 100644 --- a/pkg/helm/chart_info.go +++ b/pkg/helm/chart_info.go @@ -286,7 +286,10 @@ func parseChartValuesFileComments(chartDirectory string, values *yaml.Node, lint // If we haven't continued by this point, we didn't match any of the comment formats we want, so we need to add // the in progress value to the map, and reset to looking for a new key key, description := ParseComment(commentLines) - keyToDescriptions[key] = description + if key != "" { + keyToDescriptions[key] = description + } + commentLines = make([]string, 0) foundValuesComment = false }