Merge pull request #1687 from technosophos/feat/1654-pretty-version

feat(tiller): Add .Release.Revision and .IsUpgrade
pull/1705/head
Matt Butcher 8 years ago committed by GitHub
commit 9ae9586df0

@ -11,6 +11,9 @@ In the previous section, we use `{{.Release.Name}}` to insert the name of a rele
- `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)

@ -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`.

@ -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,

@ -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))
}

@ -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 {

@ -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

Loading…
Cancel
Save