From d3e97e40dc8fb83d7bd340744c296c02ab4d023b Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Wed, 12 Oct 2016 12:58:19 -0600 Subject: [PATCH] fix(helm): prevent 'helm history' from segfaulting An release that does not contain chart metadata cannot print its chart name/version. This fixes a bug found in the wild where a release did not (for reasons yet unknown) contain a chart. Closes #1348 --- cmd/helm/history.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/helm/history.go b/cmd/helm/history.go index e2c9eef43..da3cd663d 100644 --- a/cmd/helm/history.go +++ b/cmd/helm/history.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/cobra" "k8s.io/helm/pkg/helm" + "k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/timeconv" ) @@ -98,7 +99,7 @@ func formatHistory(rls []*release.Release) string { tbl.AddRow("REVISION", "UPDATED", "STATUS", "CHART") for i := len(rls) - 1; i >= 0; i-- { r := rls[i] - c := fmt.Sprintf("%s-%s", r.Chart.Metadata.Name, r.Chart.Metadata.Version) + c := formatChartname(r.Chart) t := timeconv.String(r.Info.LastDeployed) s := r.Info.Status.Code.String() v := r.Version @@ -106,3 +107,12 @@ func formatHistory(rls []*release.Release) string { } return tbl.String() } + +func formatChartname(c *chart.Chart) string { + if c == nil || c.Metadata == nil { + // This is an edge case that has happened in prod, though we don't + // know how: https://github.com/kubernetes/helm/issues/1347 + return "MISSING" + } + return fmt.Sprintf("%s-%s", c.Metadata.Name, c.Metadata.Version) +}