Expose release version as .Release.ChartVersion for templating (#2080)
This commit is contained in:
parent
c03f86de0f
commit
d84243992e
|
|
@ -52,6 +52,7 @@ releases:
|
||||||
- `Release.Labels`: The labels to be applied to the release
|
- `Release.Labels`: The labels to be applied to the release
|
||||||
- `Release.Chart`: The chart name of the release
|
- `Release.Chart`: The chart name of the release
|
||||||
- `Release.KubeContext`: The kube context to be used for the release
|
- `Release.KubeContext`: The kube context to be used for the release
|
||||||
|
- `Release.ChartVersion`: The version of the current chart
|
||||||
- `Values`: Values passed into the environment.
|
- `Values`: Values passed into the environment.
|
||||||
- `StateValues`: alias for `Values`.
|
- `StateValues`: alias for `Values`.
|
||||||
- `Environment`: The information about the environment. This is set by the
|
- `Environment`: The information about the environment. This is set by the
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,12 @@ func (st *HelmState) createReleaseTemplateData(release *ReleaseSpec, vals map[st
|
||||||
Chart: st.OverrideChart,
|
Chart: st.OverrideChart,
|
||||||
Values: vals,
|
Values: vals,
|
||||||
Release: releaseTemplateDataRelease{
|
Release: releaseTemplateDataRelease{
|
||||||
Name: release.Name,
|
Name: release.Name,
|
||||||
Chart: release.Chart,
|
Chart: release.Chart,
|
||||||
Namespace: release.Namespace,
|
Namespace: release.Namespace,
|
||||||
Labels: release.Labels,
|
Labels: release.Labels,
|
||||||
KubeContext: release.KubeContext,
|
KubeContext: release.KubeContext,
|
||||||
|
ChartVersion: release.Version,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tmplData.StateValues = &tmplData.Values
|
tmplData.StateValues = &tmplData.Values
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ func TestHelmState_executeTemplates(t *testing.T) {
|
||||||
Version: "{{ .Release.Name }}-0.1",
|
Version: "{{ .Release.Name }}-0.1",
|
||||||
Name: "test-app",
|
Name: "test-app",
|
||||||
Namespace: "test-namespace-{{ .Release.Name }}",
|
Namespace: "test-namespace-{{ .Release.Name }}",
|
||||||
ValuesTemplate: []any{"config/{{ .Environment.Name }}/{{ .Release.Name }}/values.yaml"},
|
ValuesTemplate: []any{"config/{{ .Environment.Name }}/{{ .Release.Name }}/{{ .Release.ChartVersion }}/values.yaml"},
|
||||||
Secrets: []any{"config/{{ .Environment.Name }}/{{ .Release.Name }}/secrets.yaml"},
|
Secrets: []any{"config/{{ .Environment.Name }}/{{ .Release.Name }}/{{ .Release.ChartVersion }}/secrets.yaml"},
|
||||||
Labels: map[string]string{"id": "{{ .Release.Name }}"},
|
Labels: map[string]string{"id": "{{ .Release.Name }}"},
|
||||||
},
|
},
|
||||||
want: ReleaseSpec{
|
want: ReleaseSpec{
|
||||||
|
|
@ -41,8 +41,8 @@ func TestHelmState_executeTemplates(t *testing.T) {
|
||||||
Version: "test-app-0.1",
|
Version: "test-app-0.1",
|
||||||
Name: "test-app",
|
Name: "test-app",
|
||||||
Namespace: "test-namespace-test-app",
|
Namespace: "test-namespace-test-app",
|
||||||
Values: []any{"config/test_env/test-app/values.yaml"},
|
Values: []any{"config/test_env/test-app/test-app-0.1/values.yaml"},
|
||||||
Secrets: []any{"config/test_env/test-app/secrets.yaml"},
|
Secrets: []any{"config/test_env/test-app/test-app-0.1/secrets.yaml"},
|
||||||
Labels: map[string]string{"id": "test-app"},
|
Labels: map[string]string{"id": "test-app"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -89,20 +89,24 @@ func TestHelmState_executeTemplates(t *testing.T) {
|
||||||
Chart: "test-charts/chart",
|
Chart: "test-charts/chart",
|
||||||
Name: "test-app",
|
Name: "test-app",
|
||||||
Namespace: "dev",
|
Namespace: "dev",
|
||||||
|
Version: "1.5",
|
||||||
SetValuesTemplate: []SetValue{
|
SetValuesTemplate: []SetValue{
|
||||||
{Name: "val1", Value: "{{ .Release.Name }}-val1"},
|
{Name: "val1", Value: "{{ .Release.Name }}-val1"},
|
||||||
{Name: "val2", File: "{{ .Release.Name }}.yml"},
|
{Name: "val2", File: "{{ .Release.Name }}.yml"},
|
||||||
{Name: "val3", Values: []string{"{{ .Release.Name }}-val2", "{{ .Release.Name }}-val3"}},
|
{Name: "val3", Values: []string{"{{ .Release.Name }}-val2", "{{ .Release.Name }}-val3"}},
|
||||||
|
{Name: "val4", Value: "{{ .Release.Chart }}-{{ .Release.ChartVersion}}"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: ReleaseSpec{
|
want: ReleaseSpec{
|
||||||
Chart: "test-charts/chart",
|
Chart: "test-charts/chart",
|
||||||
Name: "test-app",
|
Name: "test-app",
|
||||||
Namespace: "dev",
|
Namespace: "dev",
|
||||||
|
Version: "1.5",
|
||||||
SetValues: []SetValue{
|
SetValues: []SetValue{
|
||||||
{Name: "val1", Value: "test-app-val1"},
|
{Name: "val1", Value: "test-app-val1"},
|
||||||
{Name: "val2", File: "test-app.yml"},
|
{Name: "val2", File: "test-app.yml"},
|
||||||
{Name: "val3", Values: []string{"test-app-val2", "test-app-val3"}},
|
{Name: "val3", Values: []string{"test-app-val2", "test-app-val3"}},
|
||||||
|
{Name: "val4", Value: "test-charts/chart-1.5"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -146,6 +150,19 @@ func TestHelmState_executeTemplates(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Version is empty but used in templates (render as empty string)",
|
||||||
|
input: ReleaseSpec{
|
||||||
|
Name: "test-app",
|
||||||
|
Chart: "test-charts/{{ .Release.Name }}",
|
||||||
|
ValuesTemplate: []any{"config/values-{{ .Release.ChartVersion }}.yaml"},
|
||||||
|
},
|
||||||
|
want: ReleaseSpec{
|
||||||
|
Name: "test-app",
|
||||||
|
Chart: "test-charts/test-app",
|
||||||
|
Values: []any{"config/values-.yaml"},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range tests {
|
for i := range tests {
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ type releaseTemplateDataRelease struct {
|
||||||
// Chart is ReleaseSpec.Chart
|
// Chart is ReleaseSpec.Chart
|
||||||
Chart string
|
Chart string
|
||||||
|
|
||||||
|
// ChartVersion is ReleaseSpec.Version
|
||||||
|
ChartVersion string
|
||||||
|
|
||||||
// KubeContext is ReleaseSpec.KubeContext
|
// KubeContext is ReleaseSpec.KubeContext
|
||||||
KubeContext string
|
KubeContext string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue