From 2b33bf6ba719e602c026d07ae483327d84da6b7c Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Mon, 10 Sep 2018 15:39:55 +0000 Subject: [PATCH] Fix for checking helm version slice bounds out of range (#4609) * fix(helm): Use env to locate bash Leverage '/usr/bin/env bash` for find bash instead of hardcoding '/bin/bash' since some *nix OSes have it installed elsewhere. Signed-off-by: Robert James Hernandez * test(helm): Adding case for versions short flag When git sha is empty if being built from tarball running 'helm version --short' should just ignore '--short' since sha is empty. Adding test to ensure this is the case. Signed-off-by: Robert James Hernandez * fix(helm): ignore short flag when sha is empty Signed-off-by: Robert James Hernandez --- Makefile | 2 +- cmd/helm/version.go | 2 +- cmd/helm/version_test.go | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9b8588712..f824481ca 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ BINDIR := $(CURDIR)/bin BINARIES := helm tiller # Required for globs to work correctly -SHELL=/bin/bash +SHELL=/usr/bin/env bash .PHONY: all all: build diff --git a/cmd/helm/version.go b/cmd/helm/version.go index e0d9e5e73..1c292e19d 100644 --- a/cmd/helm/version.go +++ b/cmd/helm/version.go @@ -145,7 +145,7 @@ func getK8sVersion() (*apiVersion.Info, error) { } func formatVersion(v *pb.Version, short bool) string { - if short { + if short && v.GitCommit != "" { return fmt.Sprintf("%s+g%s", v.SemVer, v.GitCommit[:7]) } return fmt.Sprintf("%#v", v) diff --git a/cmd/helm/version_test.go b/cmd/helm/version_test.go index 5519131c2..c1223ef91 100644 --- a/cmd/helm/version_test.go +++ b/cmd/helm/version_test.go @@ -57,6 +57,12 @@ func TestVersion(t *testing.T) { flags: []string{"--template", "{{ .Client.SemVer }} {{ .Server.SemVer }}"}, expected: lver + " " + sver, }, + { + name: "client short empty git", + args: []string{}, + flags: []string{"-c", "--short"}, + expected: lver, + }, } settings.TillerHost = "fake-localhost" runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {