diff --git a/docs/chart_template_guide/builtin_objects.md b/docs/chart_template_guide/builtin_objects.md index 661cf0a2696c69c6a652327ed07a58a65715ad66..077b2fc304c3edff27f3f0f22d6e8e143f3152bd 100644 --- a/docs/chart_template_guide/builtin_objects.md +++ b/docs/chart_template_guide/builtin_objects.md @@ -7,10 +7,13 @@ Objects can be simple, and have just one value. Or they can contain other object In the previous section, we use `{{.Release.Name}}` to insert the name of a release into a template. `Release` is one of four top-level objects that you can access in your templates. - `Release`: This object describes the release itself. It has several objects inside of it: - - `Release.Name`: The release name - - `Release.Time`: The time of the release - - `Release.Namespace`: The namespace to be released into (if the manifest doesn't override) - - `Release.Service`: The name of the releasing service (always `Tiller`). + - `Release.Name`: The release name + - `Release.Time`: The time of the release + - `Release.Namespace`: The namespace to be released into (if the manifest doesn't override) + - `Release.Service`: The name of the releasing service (always `Tiller`). + - `Release.Revision`: The revision number of this release. It begins at 1 and is incremented for each `helm upgrade`. + - `Release.IsUpgrade`: This is set to `true` if the current operation is an upgrade or rollback. + - `Release.IsInstall`: This is set to `true` if the current operation is an install. - `Values`: Values passed into the template from the `values.yaml` file and from user-supplied files. By default, `Values` is empty. - `Chart`: The contents of the `Chart.yaml` file. Any data in `Chart.yaml` will be accessible here. For example `{{.Chart.Name}}-{{.Chart.Version}}` will print out the `mychart-0.1.0`. - The available fields are listed in the [Charts Guide](charts.md) diff --git a/docs/charts.md b/docs/charts.md index 1e7b9a79fe827ee539062eda14b9139fe1ed6177..d6ccc151232114b83e8495e39f7fb2a47483b6c6 100644 --- a/docs/charts.md +++ b/docs/charts.md @@ -292,6 +292,11 @@ sensitive_. - `Release.Namespace`: The namespace the chart was released to. - `Release.Service`: The service that conducted the release. Usually this is `Tiller`. +- `Release.IsUpgrade`: This is set to true if the current operation is an upgrade or rollback. +- `Release.IsInstall`: This is set to true if the current operation is an + install. +- `Release.Revision`: The revision number. It begins at 1, and increments with + each `helm upgrade`. - `Chart`: The contents of the `Chart.yaml`. Thus, the chart version is obtainable as `Chart.Version` and the maintainers are in `Chart.Maintainers`. diff --git a/pkg/chartutil/values.go b/pkg/chartutil/values.go index c431454a7674433e2bc3e3db7175e9597e49a804..16e1ae9b4dd9f95f8f9b95b0208f389387a0e9f7 100644 --- a/pkg/chartutil/values.go +++ b/pkg/chartutil/values.go @@ -304,6 +304,9 @@ type ReleaseOptions struct { Name string Time *timestamp.Timestamp Namespace string + IsUpgrade bool + IsInstall bool + Revision int } // ToRenderValues composes the struct from the data coming from the Releases, Charts and Values files @@ -314,6 +317,9 @@ func ToRenderValues(chrt *chart.Chart, chrtVals *chart.Config, options ReleaseOp "Name": options.Name, "Time": options.Time, "Namespace": options.Namespace, + "IsUpgrade": options.IsUpgrade, + "IsInstall": options.IsInstall, + "Revision": options.Revision, "Service": "Tiller", }, "Chart": chrt.Metadata, diff --git a/pkg/chartutil/values_test.go b/pkg/chartutil/values_test.go index b48d4e94313f441a52ace3091ff8a236cfd0fe2e..0cb86e6efbd138e629c4bd576b4a37d099d2a112 100644 --- a/pkg/chartutil/values_test.go +++ b/pkg/chartutil/values_test.go @@ -104,6 +104,8 @@ where: Name: "Seven Voyages", Time: timeconv.Now(), Namespace: "al Basrah", + IsInstall: true, + Revision: 5, } res, err := ToRenderValues(c, v, o) @@ -115,9 +117,19 @@ where: if name := res["Chart"].(*chart.Metadata).Name; name != "test" { t.Errorf("Expected chart name 'test', got %q", name) } - if name := res["Release"].(map[string]interface{})["Name"]; fmt.Sprint(name) != "Seven Voyages" { + relmap := res["Release"].(map[string]interface{}) + if name := relmap["Name"]; name.(string) != "Seven Voyages" { t.Errorf("Expected release name 'Seven Voyages', got %q", name) } + if rev := relmap["Revision"]; rev.(int) != 5 { + t.Errorf("Expected release revision %d, got %q", 5, rev) + } + if relmap["IsUpgrade"].(bool) { + t.Errorf("Expected upgrade to be false.") + } + if !relmap["IsInstall"].(bool) { + t.Errorf("Expected install to be true.") + } if data := res["Files"].(Files)["scheherazade/shahryar.txt"]; string(data) != "1,001 Nights" { t.Errorf("Expected file '1,001 Nights', got %q", string(data)) } diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 88fcd255f254b4fdb83c6b4a08fc08e4bcab6d1e..a10f377da7e62030b4e571389406272d5b65528e 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -139,6 +139,7 @@ func (s *Storage) History(name string) ([]*rspb.Release, error) { return l, nil } +// Last fetches the last revision of the named release. func (s *Storage) Last(name string) (*rspb.Release, error) { h, err := s.History(name) if err != nil { diff --git a/pkg/tiller/release_server.go b/pkg/tiller/release_server.go index e5266c5093a36e8030d0e44b3fa7bf37dc60a8e8..51570a9a1926846bab001025c15a15edbbe627b5 100644 --- a/pkg/tiller/release_server.go +++ b/pkg/tiller/release_server.go @@ -393,11 +393,17 @@ func (s *ReleaseServer) prepareUpdate(req *services.UpdateReleaseRequest) (*rele // If new values were not supplied in the upgrade, re-use the existing values. s.reuseValues(req, currentRelease) + // Increment revision count. This is passed to templates, and also stored on + // the release object. + revision := currentRelease.Version + 1 + ts := timeconv.Now() options := chartutil.ReleaseOptions{ Name: req.Name, Time: ts, Namespace: currentRelease.Namespace, + IsUpgrade: true, + Revision: int(revision), } valuesToRender, err := chartutil.ToRenderValues(req.Chart, req.Values, options) @@ -421,7 +427,7 @@ func (s *ReleaseServer) prepareUpdate(req *services.UpdateReleaseRequest) (*rele LastDeployed: ts, Status: &release.Status{Code: release.Status_UNKNOWN}, }, - Version: currentRelease.Version + 1, + Version: revision, Manifest: manifestDoc.String(), Hooks: hooks, } @@ -646,8 +652,15 @@ func (s *ReleaseServer) prepareRelease(req *services.InstallReleaseRequest) (*re return nil, err } + revision := 1 ts := timeconv.Now() - options := chartutil.ReleaseOptions{Name: name, Time: ts, Namespace: req.Namespace} + options := chartutil.ReleaseOptions{ + Name: name, + Time: ts, + Namespace: req.Namespace, + Revision: revision, + IsInstall: true, + } valuesToRender, err := chartutil.ToRenderValues(req.Chart, req.Values, options) if err != nil { return nil, err @@ -688,7 +701,7 @@ func (s *ReleaseServer) prepareRelease(req *services.InstallReleaseRequest) (*re }, Manifest: manifestDoc.String(), Hooks: hooks, - Version: 1, + Version: int32(revision), } if len(notesTxt) > 0 { rel.Info.Status.Notes = notesTxt