From b2d762af48778bf2ec9e273e535da36ce9c35dd4 Mon Sep 17 00:00:00 2001
From: Matt Butcher <technosophos@gmail.com>
Date: Thu, 15 Dec 2016 15:04:36 -0700
Subject: [PATCH] feat(tiller): add .Release.IsInstall

---
 docs/chart_template_guide/builtin_objects.md | 11 ++++++-----
 docs/charts.md                               |  5 +++--
 pkg/chartutil/values.go                      |  2 ++
 pkg/chartutil/values_test.go                 |  4 ++++
 pkg/tiller/release_server.go                 |  1 +
 5 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/docs/chart_template_guide/builtin_objects.md b/docs/chart_template_guide/builtin_objects.md
index 98f091eb0..077b2fc30 100644
--- a/docs/chart_template_guide/builtin_objects.md
+++ b/docs/chart_template_guide/builtin_objects.md
@@ -7,12 +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.
+  - `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 dd4a12253..d6ccc1512 100644
--- a/docs/charts.md
+++ b/docs/charts.md
@@ -292,8 +292,9 @@ 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.
-  It is false for install.
+- `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
diff --git a/pkg/chartutil/values.go b/pkg/chartutil/values.go
index 7c3cb21fb..16e1ae9b4 100644
--- a/pkg/chartutil/values.go
+++ b/pkg/chartutil/values.go
@@ -305,6 +305,7 @@ type ReleaseOptions struct {
 	Time      *timestamp.Timestamp
 	Namespace string
 	IsUpgrade bool
+	IsInstall bool
 	Revision  int
 }
 
@@ -317,6 +318,7 @@ func ToRenderValues(chrt *chart.Chart, chrtVals *chart.Config, options ReleaseOp
 			"Time":      options.Time,
 			"Namespace": options.Namespace,
 			"IsUpgrade": options.IsUpgrade,
+			"IsInstall": options.IsInstall,
 			"Revision":  options.Revision,
 			"Service":   "Tiller",
 		},
diff --git a/pkg/chartutil/values_test.go b/pkg/chartutil/values_test.go
index 41da8efe7..0cb86e6ef 100644
--- a/pkg/chartutil/values_test.go
+++ b/pkg/chartutil/values_test.go
@@ -104,6 +104,7 @@ where:
 		Name:      "Seven Voyages",
 		Time:      timeconv.Now(),
 		Namespace: "al Basrah",
+		IsInstall: true,
 		Revision:  5,
 	}
 
@@ -126,6 +127,9 @@ where:
 	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/tiller/release_server.go b/pkg/tiller/release_server.go
index c3fecc456..51570a9a1 100644
--- a/pkg/tiller/release_server.go
+++ b/pkg/tiller/release_server.go
@@ -659,6 +659,7 @@ func (s *ReleaseServer) prepareRelease(req *services.InstallReleaseRequest) (*re
 		Time:      ts,
 		Namespace: req.Namespace,
 		Revision:  revision,
+		IsInstall: true,
 	}
 	valuesToRender, err := chartutil.ToRenderValues(req.Chart, req.Values, options)
 	if err != nil {
-- 
GitLab