Commit 3e3312ce authored by Matt Butcher's avatar Matt Butcher

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
parent 96cdbbe6
......@@ -325,6 +325,16 @@ func (s *releaseServer) performUpdate(originalRelease, updatedRelease *release.R
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.
func (s *releaseServer) prepareUpdate(req *services.UpdateReleaseRequest) (*release.Release, *release.Release, error) {
if req.Name == "" {
......@@ -341,6 +351,9 @@ func (s *releaseServer) prepareUpdate(req *services.UpdateReleaseRequest) (*rele
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()
options := chartutil.ReleaseOptions{
Name: req.Name,
......
......@@ -110,7 +110,7 @@ func namedReleaseStub(name string, status release.Status_Code) *release.Release
Status: &release.Status{Code: status},
},
Chart: chartStub(),
Config: &chart.Config{Raw: `name = "value"`},
Config: &chart.Config{Raw: `name: value`},
Version: 1,
Hooks: []*release.Hook{
{
......@@ -568,6 +568,12 @@ func TestUpdateRelease(t *testing.T) {
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 {
t.Errorf("Expected manifest in %v", res)
}
......
......@@ -24,7 +24,9 @@ import (
"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"
// UnmarshalChartfile takes raw Chart.yaml data and unmarshals it.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment