fix chart nil issue

Signed-off-by: yxxhero <aiopsclub@163.com>
pull/9924/head
yxxhero 4 years ago
parent 21251378b4
commit e7d00d7537

@ -153,15 +153,22 @@ func newReleaseListWriter(releases []*release.Release, timeFormat string) *relea
elements := make([]releaseElement, 0, len(releases)) elements := make([]releaseElement, 0, len(releases))
for _, r := range releases { for _, r := range releases {
element := releaseElement{ element := releaseElement{
Name: r.Name, Name: r.Name,
Namespace: r.Namespace, Namespace: r.Namespace,
Revision: strconv.Itoa(r.Version), Revision: strconv.Itoa(r.Version),
Status: r.Info.Status.String(), Status: r.Info.Status.String(),
Chart: fmt.Sprintf("%s-%s", r.Chart.Metadata.Name, r.Chart.Metadata.Version),
AppVersion: r.Chart.Metadata.AppVersion,
} }
t := "-" t := "-"
if r.Chart != nil {
element.Chart = fmt.Sprintf("%s-%s", r.Chart.Metadata.Name, r.Chart.Metadata.Version)
element.AppVersion = r.Chart.Metadata.AppVersion
} else {
element.Chart = t
element.AppVersion = t
}
if tspb := r.Info.LastDeployed; !tspb.IsZero() { if tspb := r.Info.LastDeployed; !tspb.IsZero() {
if timeFormat != "" { if timeFormat != "" {
t = tspb.Format(timeFormat) t = tspb.Format(timeFormat)

@ -51,6 +51,15 @@ func TestListCmd(t *testing.T) {
}, },
Chart: chartInfo, Chart: chartInfo,
}, },
{
Name: "nochartinfo",
Version: 1,
Namespace: defaultNamespace,
Info: &release.Info{
LastDeployed: timestamp1,
Status: release.StatusSuperseded,
},
},
{ {
Name: "starlord", Name: "starlord",
Version: 2, Version: 2,

@ -17,6 +17,7 @@ limitations under the License.
package chartutil package chartutil
import ( import (
"fmt"
"log" "log"
"github.com/mitchellh/copystructure" "github.com/mitchellh/copystructure"
@ -35,6 +36,9 @@ import (
// - A chart has access to all of the variables for it, as well as all of // - A chart has access to all of the variables for it, as well as all of
// the values destined for its dependencies. // the values destined for its dependencies.
func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) { func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) {
if chrt == nil {
return nil, fmt.Errorf("the chart is nil")
}
v, err := copystructure.Copy(vals) v, err := copystructure.Copy(vals)
if err != nil { if err != nil {
return vals, err return vals, err

@ -116,6 +116,11 @@ func TestCoalesceValues(t *testing.T) {
valsCopy[key] = value valsCopy[key] = value
} }
_, err = CoalesceValues(nil, vals)
if err == nil {
t.Errorf("Excepted errors when chart is nil")
}
v, err := CoalesceValues(c, vals) v, err := CoalesceValues(c, vals)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

Loading…
Cancel
Save