feat(tiller): re-use values during upgrade

When `helm install -f foo.yaml bar` is called, and then the release is
upgraded with `helm upgrade happy-panda bar`, this will now re-use the
values that were submitted with `-f foo.yaml`. The same is true for
values specified with `--set`.

Closes #1227
pull/1278/head
Matt Butcher 8 years ago
parent 96cdbbe6b1
commit 3e3312cea0

@ -325,6 +325,16 @@ func (s *releaseServer) performUpdate(originalRelease, updatedRelease *release.R
return res, nil return res, nil
} }
// reuseValues copies values from the current release to a new release if the new release does not have any values.
//
// If the request already has values, or if there are no values in the current release, this does nothing.
func (s *releaseServer) reuseValues(req *services.UpdateReleaseRequest, current *release.Release) {
if (req.Values == nil || req.Values.Raw == "") && current.Config != nil && current.Config.Raw != "" {
log.Printf("Copying values from %s (v%d) to new release.", current.Name, current.Version)
req.Values = current.Config
}
}
// prepareUpdate builds an updated release for an update operation. // prepareUpdate builds an updated release for an update operation.
func (s *releaseServer) prepareUpdate(req *services.UpdateReleaseRequest) (*release.Release, *release.Release, error) { func (s *releaseServer) prepareUpdate(req *services.UpdateReleaseRequest) (*release.Release, *release.Release, error) {
if req.Name == "" { if req.Name == "" {
@ -341,6 +351,9 @@ func (s *releaseServer) prepareUpdate(req *services.UpdateReleaseRequest) (*rele
return nil, nil, err return nil, nil, err
} }
// If new values were not supplied in the upgrade, re-use the existing values.
s.reuseValues(req, currentRelease)
ts := timeconv.Now() ts := timeconv.Now()
options := chartutil.ReleaseOptions{ options := chartutil.ReleaseOptions{
Name: req.Name, Name: req.Name,

@ -110,7 +110,7 @@ func namedReleaseStub(name string, status release.Status_Code) *release.Release
Status: &release.Status{Code: status}, Status: &release.Status{Code: status},
}, },
Chart: chartStub(), Chart: chartStub(),
Config: &chart.Config{Raw: `name = "value"`}, Config: &chart.Config{Raw: `name: value`},
Version: 1, Version: 1,
Hooks: []*release.Hook{ Hooks: []*release.Hook{
{ {
@ -568,6 +568,12 @@ func TestUpdateRelease(t *testing.T) {
t.Errorf("No manifest returned: %v", res.Release) t.Errorf("No manifest returned: %v", res.Release)
} }
if res.Release.Config == nil {
t.Errorf("Got release without config: %#v", res.Release)
} else if res.Release.Config.Raw != rel.Config.Raw {
t.Errorf("Expected release values %q, got %q", rel.Config.Raw, res.Release.Config.Raw)
}
if len(updated.Manifest) == 0 { if len(updated.Manifest) == 0 {
t.Errorf("Expected manifest in %v", res) t.Errorf("Expected manifest in %v", res)
} }

@ -24,7 +24,9 @@ import (
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
) )
// APIVersionV1 is the API version number for version 1. // ApiVersionV1 is the API version number for version 1.
//
// This is ApiVersionV1 instead of APIVersionV1 to match the protobuf-generated name.
const ApiVersionV1 = "v1" const ApiVersionV1 = "v1"
// UnmarshalChartfile takes raw Chart.yaml data and unmarshals it. // UnmarshalChartfile takes raw Chart.yaml data and unmarshals it.

Loading…
Cancel
Save