Merge pull request #4091 from adamreese/dev-v3-releaseoptions

feat(*): remove Time, Namespace, and Revision from template functions
pull/4122/head
Adam Reese 7 years ago committed by GitHub
commit 647ffaf7d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -165,9 +165,7 @@ func (o *templateOptions) run(out io.Writer) error {
return errors.Wrap(err, "cannot load requirements") return errors.Wrap(err, "cannot load requirements")
} }
options := chartutil.ReleaseOptions{ options := chartutil.ReleaseOptions{
Name: o.releaseName, Name: o.releaseName,
Time: time.Now(),
Namespace: getNamespace(),
} }
if err := chartutil.ProcessRequirementsEnabled(c, config); err != nil { if err := chartutil.ProcessRequirementsEnabled(c, config); err != nil {

@ -6,7 +6,6 @@ metadata:
name: subchart1 name: subchart1
labels: labels:
chart: "subchart1-0.1.0" chart: "subchart1-0.1.0"
namespace: "default"
release-name: "RELEASE-NAME" release-name: "RELEASE-NAME"
kube-version/major: "1" kube-version/major: "1"
kube-version/minor: "9" kube-version/minor: "9"

@ -42,7 +42,6 @@ metadata:
name: subchart1 name: subchart1
labels: labels:
chart: "subchart1-0.1.0" chart: "subchart1-0.1.0"
namespace: "default"
release-name: "RELEASE-NAME" release-name: "RELEASE-NAME"
kube-version/major: "1" kube-version/major: "1"
kube-version/minor: "6" kube-version/minor: "6"

@ -42,7 +42,6 @@ metadata:
name: subchart1 name: subchart1
labels: labels:
chart: "subchart1-0.1.0" chart: "subchart1-0.1.0"
namespace: "default"
release-name: "foobar-YWJj-baz" release-name: "foobar-YWJj-baz"
kube-version/major: "1" kube-version/major: "1"
kube-version/minor: "9" kube-version/minor: "9"

@ -42,7 +42,6 @@ metadata:
name: subchart1 name: subchart1
labels: labels:
chart: "subchart1-0.1.0" chart: "subchart1-0.1.0"
namespace: "default"
release-name: "test" release-name: "test"
kube-version/major: "1" kube-version/major: "1"
kube-version/minor: "9" kube-version/minor: "9"

@ -42,7 +42,6 @@ metadata:
name: subchart1 name: subchart1
labels: labels:
chart: "subchart1-0.1.0" chart: "subchart1-0.1.0"
namespace: "default"
release-name: "RELEASE-NAME" release-name: "RELEASE-NAME"
kube-version/major: "1" kube-version/major: "1"
kube-version/minor: "9" kube-version/minor: "9"

@ -6,7 +6,6 @@ metadata:
name: subchart1 name: subchart1
labels: labels:
chart: "subchart1-0.1.0" chart: "subchart1-0.1.0"
namespace: "default"
release-name: "RELEASE-NAME" release-name: "RELEASE-NAME"
kube-version/major: "1" kube-version/major: "1"
kube-version/minor: "9" kube-version/minor: "9"

@ -42,7 +42,6 @@ metadata:
name: subchart1 name: subchart1
labels: labels:
chart: "subchart1-0.1.0" chart: "subchart1-0.1.0"
namespace: "default"
release-name: "RELEASE-NAME" release-name: "RELEASE-NAME"
kube-version/major: "1" kube-version/major: "1"
kube-version/minor: "9" kube-version/minor: "9"

@ -42,7 +42,6 @@ metadata:
name: subchart1 name: subchart1
labels: labels:
chart: "subchart1-0.1.0" chart: "subchart1-0.1.0"
namespace: "default"
release-name: "RELEASE-NAME" release-name: "RELEASE-NAME"
kube-version/major: "1" kube-version/major: "1"
kube-version/minor: "9" kube-version/minor: "9"

@ -13,8 +13,6 @@ metadata:
# This makes it easy to audit chart usage. # This makes it easy to audit chart usage.
chart: "{{.Chart.Name}}-{{.Chart.Version}}" chart: "{{.Chart.Name}}-{{.Chart.Version}}"
values: {{.Values.test.Name}} values: {{.Values.test.Name}}
annotations:
"helm.sh/created": {{.Release.Time.Seconds | quote }}
spec: spec:
# This shows how to use a simple value. This will look for a passed-in value # This shows how to use a simple value. This will look for a passed-in value
# called restartPolicy. If it is not found, it will use the default value. # called restartPolicy. If it is not found, it will use the default value.

@ -12,8 +12,6 @@ metadata:
release: {{.Release.Name | quote }} release: {{.Release.Name | quote }}
# This makes it easy to audit chart usage. # This makes it easy to audit chart usage.
chart: "{{.Chart.Name}}-{{.Chart.Version}}" chart: "{{.Chart.Name}}-{{.Chart.Version}}"
annotations:
"helm.sh/created": {{.Release.Time.Seconds | quote }}
spec: spec:
# This shows how to use a simple value. This will look for a passed-in value # This shows how to use a simple value. This will look for a passed-in value
# called restartPolicy. If it is not found, it will use the default value. # called restartPolicy. If it is not found, it will use the default value.

@ -6,8 +6,6 @@ metadata:
heritage: {{.Release.Service}} heritage: {{.Release.Service}}
chartName: {{.Chart.Name}} chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}} chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec: spec:
restartPolicy: {{default "Never" .restart_policy}} restartPolicy: {{default "Never" .restart_policy}}
containers: containers:

@ -8,10 +8,7 @@ In the previous section, we use `{{.Release.Name}}` to insert the name of a rele
- `Release`: This object describes the release itself. It has several objects inside of it: - `Release`: This object describes the release itself. It has several objects inside of it:
- `Release.Name`: The release name - `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.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.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.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. - `Values`: Values passed into the template from the `values.yaml` file and from user-supplied files. By default, `Values` is empty.

@ -179,7 +179,7 @@ Say we've defined a simple template that looks like this:
```yaml ```yaml
{{- define "mychart.app" -}} {{- define "mychart.app" -}}
app_name: {{ .Chart.Name }} app_name: {{ .Chart.Name }}
app_version: "{{ .Chart.Version }}+{{ .Release.Time.Seconds }}" app_version: "{{ .Chart.Version }}"
{{- end -}} {{- end -}}
``` ```

@ -574,16 +574,11 @@ cannot be overridden. As with all values, the names are _case
sensitive_. sensitive_.
- `Release.Name`: The name of the release (not the chart) - `Release.Name`: The name of the release (not the chart)
- `Release.Time`: The time the chart release was last updated. This will
match the `Last Released` time on a Release object.
- `Release.Namespace`: The namespace the chart was released to.
- `Release.Service`: The service that conducted the release. Usually - `Release.Service`: The service that conducted the release. Usually
this is `Tiller`. this is `Tiller`.
- `Release.IsUpgrade`: This is set to true if the current operation is an upgrade or rollback. - `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 - `Release.IsInstall`: This is set to true if the current operation is an
install. 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 - `Chart`: The contents of the `Chart.yaml`. Thus, the chart version is
obtainable as `Chart.Version` and the maintainers are in obtainable as `Chart.Version` and the maintainers are in
`Chart.Maintainers`. `Chart.Maintainers`.

@ -243,16 +243,16 @@ const defaultNotes = `1. Get the application URL by running these commands:
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }} http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
{{- end }} {{- end }}
{{- else if contains "NodePort" .Values.service.type }} {{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "<CHARTNAME>.fullname" . }}) export NODE_PORT=$(kubectl get -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "<CHARTNAME>.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") export NODE_IP=$(kubectl get nodes -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }} {{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available. NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "<CHARTNAME>.fullname" . }}' You can watch the status of by running 'kubectl get svc -w {{ template "<CHARTNAME>.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "<CHARTNAME>.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') export SERVICE_IP=$(kubectl get svc {{ template "<CHARTNAME>.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }} echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }} {{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "<CHARTNAME>.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") export POD_NAME=$(kubectl get pods -l "app={{ template "<CHARTNAME>.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application" echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80 kubectl port-forward $POD_NAME 8080:80
{{- end }} {{- end }}

@ -6,8 +6,6 @@ metadata:
heritage: {{.Release.Service}} heritage: {{.Release.Service}}
chartName: {{.Chart.Name}} chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}} chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec: spec:
restartPolicy: {{default "Never" .restart_policy}} restartPolicy: {{default "Never" .restart_policy}}
containers: containers:

@ -6,8 +6,6 @@ metadata:
heritage: {{.Release.Service}} heritage: {{.Release.Service}}
chartName: {{.Chart.Name}} chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}} chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec: spec:
restartPolicy: {{default "Never" .restart_policy}} restartPolicy: {{default "Never" .restart_policy}}
containers: containers:

@ -6,8 +6,6 @@ metadata:
heritage: {{.Release.Service}} heritage: {{.Release.Service}}
chartName: {{.Chart.Name}} chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}} chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec: spec:
restartPolicy: {{default "Never" .restart_policy}} restartPolicy: {{default "Never" .restart_policy}}
containers: containers:

@ -6,8 +6,6 @@ metadata:
heritage: {{.Release.Service}} heritage: {{.Release.Service}}
chartName: {{.Chart.Name}} chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}} chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec: spec:
restartPolicy: {{default "Never" .restart_policy}} restartPolicy: {{default "Never" .restart_policy}}
containers: containers:

@ -6,8 +6,6 @@ metadata:
heritage: {{.Release.Service}} heritage: {{.Release.Service}}
chartName: {{.Chart.Name}} chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}} chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec: spec:
restartPolicy: {{default "Never" .restart_policy}} restartPolicy: {{default "Never" .restart_policy}}
containers: containers:

@ -6,8 +6,6 @@ metadata:
heritage: {{.Release.Service}} heritage: {{.Release.Service}}
chartName: {{.Chart.Name}} chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}} chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec: spec:
restartPolicy: {{default "Never" .restart_policy}} restartPolicy: {{default "Never" .restart_policy}}
containers: containers:

@ -6,8 +6,6 @@ metadata:
heritage: {{.Release.Service}} heritage: {{.Release.Service}}
chartName: {{.Chart.Name}} chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}} chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec: spec:
restartPolicy: {{default "Never" .restart_policy}} restartPolicy: {{default "Never" .restart_policy}}
containers: containers:

@ -4,7 +4,6 @@ metadata:
name: {{ .Chart.Name }} name: {{ .Chart.Name }}
labels: labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
namespace: "{{ .Release.Namespace }}"
release-name: "{{ .Release.Name }}" release-name: "{{ .Release.Name }}"
kube-version/major: "{{ .Capabilities.KubeVersion.Major }}" kube-version/major: "{{ .Capabilities.KubeVersion.Major }}"
kube-version/minor: "{{ .Capabilities.KubeVersion.Minor }}" kube-version/minor: "{{ .Capabilities.KubeVersion.Minor }}"

@ -21,7 +21,6 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"strings" "strings"
"time"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -335,11 +334,8 @@ func coalesceTables(dst, src map[string]interface{}) map[string]interface{} {
// for the composition of the final values struct // for the composition of the final values struct
type ReleaseOptions struct { type ReleaseOptions struct {
Name string Name string
Time time.Time
Namespace string
IsUpgrade bool IsUpgrade bool
IsInstall bool IsInstall bool
Revision int
} }
// ToRenderValues composes the struct from the data coming from the Releases, Charts and Values files // ToRenderValues composes the struct from the data coming from the Releases, Charts and Values files
@ -361,11 +357,8 @@ func ToRenderValuesCaps(chrt *chart.Chart, chrtVals []byte, options ReleaseOptio
top := map[string]interface{}{ top := map[string]interface{}{
"Release": map[string]interface{}{ "Release": map[string]interface{}{
"Name": options.Name, "Name": options.Name,
"Time": options.Time,
"Namespace": options.Namespace,
"IsUpgrade": options.IsUpgrade, "IsUpgrade": options.IsUpgrade,
"IsInstall": options.IsInstall, "IsInstall": options.IsInstall,
"Revision": options.Revision,
"Service": "Helm", "Service": "Helm",
}, },
"Chart": chrt.Metadata, "Chart": chrt.Metadata,

@ -22,7 +22,6 @@ import (
"fmt" "fmt"
"testing" "testing"
"text/template" "text/template"
"time"
kversion "k8s.io/apimachinery/pkg/version" kversion "k8s.io/apimachinery/pkg/version"
@ -104,10 +103,7 @@ where:
o := ReleaseOptions{ o := ReleaseOptions{
Name: "Seven Voyages", Name: "Seven Voyages",
Time: time.Now(),
Namespace: "al Basrah",
IsInstall: true, IsInstall: true,
Revision: 5,
} }
caps := &Capabilities{ caps := &Capabilities{
@ -129,9 +125,6 @@ where:
if name := relmap["Name"]; name.(string) != "Seven Voyages" { if name := relmap["Name"]; name.(string) != "Seven Voyages" {
t.Errorf("Expected release name 'Seven Voyages', got %q", name) 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) { if relmap["IsUpgrade"].(bool) {
t.Error("Expected upgrade to be false.") t.Error("Expected upgrade to be false.")
} }

@ -6,8 +6,6 @@ metadata:
heritage: {{.Release.Service}} heritage: {{.Release.Service}}
chartName: {{.Chart.Name}} chartName: {{.Chart.Name}}
chartVersion: {{.Chart.Version | quote}} chartVersion: {{.Chart.Version | quote}}
annotations:
"helm.sh/created": "{{.Release.Time.Seconds}}"
spec: spec:
restartPolicy: {{default "Never" .restart_policy}} restartPolicy: {{default "Never" .restart_policy}}
containers: containers:

@ -19,7 +19,6 @@ package rules
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"time"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -51,7 +50,7 @@ func Templates(linter *support.Linter, values []byte, namespace string, strict b
return return
} }
options := chartutil.ReleaseOptions{Name: "testRelease", Time: time.Now(), Namespace: namespace} options := chartutil.ReleaseOptions{Name: "testRelease"}
caps := &chartutil.Capabilities{ caps := &chartutil.Capabilities{
APIVersions: chartutil.DefaultVersionSet, APIVersions: chartutil.DefaultVersionSet,
KubeVersion: chartutil.DefaultKubeVersion, KubeVersion: chartutil.DefaultKubeVersion,

@ -69,9 +69,6 @@ func (s *ReleaseServer) prepareRelease(req *hapi.InstallReleaseRequest) (*releas
ts := time.Now() ts := time.Now()
options := chartutil.ReleaseOptions{ options := chartutil.ReleaseOptions{
Name: name, Name: name,
Time: ts,
Namespace: req.Namespace,
Revision: revision,
IsInstall: true, IsInstall: true,
} }
valuesToRender, err := chartutil.ToRenderValuesCaps(req.Chart, req.Values, options, caps) valuesToRender, err := chartutil.ToRenderValuesCaps(req.Chart, req.Values, options, caps)

@ -98,10 +98,7 @@ func (s *ReleaseServer) prepareUpdate(req *hapi.UpdateReleaseRequest) (*release.
ts := time.Now() ts := time.Now()
options := chartutil.ReleaseOptions{ options := chartutil.ReleaseOptions{
Name: req.Name, Name: req.Name,
Time: ts,
Namespace: currentRelease.Namespace,
IsUpgrade: true, IsUpgrade: true,
Revision: revision,
} }
caps, err := capabilities(s.discovery) caps, err := capabilities(s.discovery)

Loading…
Cancel
Save