Merge pull request #252 from arbourd/values-files

Add `ValuesFiles` to HelmChart spec
This commit is contained in:
Hidde Beydals 2021-04-20 11:53:30 +02:00 committed by GitHub
commit 449a469ec4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 13 deletions

View File

@ -246,9 +246,19 @@ type HelmChartTemplateSpec struct {
// +optional // +optional
Interval *metav1.Duration `json:"interval,omitempty"` Interval *metav1.Duration `json:"interval,omitempty"`
// Alternative values file to use as the default chart values, expected to be a // Alternative list of values files to use as the chart values (values.yaml
// relative path in the SourceRef. Ignored when omitted. // is not included by default), expected to be a relative path in the SourceRef.
// Values files are merged in the order of this list with the last file overriding
// the first. Ignored when omitted.
// +optional // +optional
ValuesFiles []string `json:"valuesFiles,omitempty"`
// Alternative values file to use as the default chart values, expected to
// be a relative path in the SourceRef. Deprecated in favor of ValuesFiles,
// for backwards compatibility the file defined here is merged before the
// ValuesFiles items. Ignored when omitted.
// +optional
// +deprecated
ValuesFile string `json:"valuesFile,omitempty"` ValuesFile string `json:"valuesFile,omitempty"`
} }

View File

@ -68,6 +68,11 @@ func (in *HelmChartTemplateSpec) DeepCopyInto(out *HelmChartTemplateSpec) {
*out = new(metav1.Duration) *out = new(metav1.Duration)
**out = **in **out = **in
} }
if in.ValuesFiles != nil {
in, out := &in.ValuesFiles, &out.ValuesFiles
*out = make([]string, len(*in))
copy(*out, *in)
}
} }
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartTemplateSpec. // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartTemplateSpec.

View File

@ -94,8 +94,19 @@ spec:
valuesFile: valuesFile:
description: Alternative values file to use as the default description: Alternative values file to use as the default
chart values, expected to be a relative path in the SourceRef. chart values, expected to be a relative path in the SourceRef.
Deprecated in favor of ValuesFiles, for backwards compatibility
the file defined here is merged before the ValuesFiles items.
Ignored when omitted. Ignored when omitted.
type: string type: string
valuesFiles:
description: Alternative list of values files to use as the
chart values (values.yaml is not included by default), expected
to be a relative path in the SourceRef. Values files are
merged in the order of this list with the last file overriding
the first. Ignored when omitted.
items:
type: string
type: array
version: version:
default: '*' default: '*'
description: Version semver expression, ignored for charts description: Version semver expression, ignored for charts

View File

@ -24,6 +24,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"reflect"
"strings" "strings"
"github.com/go-logr/logr" "github.com/go-logr/logr"
@ -173,8 +174,9 @@ func buildHelmChartFromTemplate(hr *v2.HelmRelease) *sourcev1.HelmChart {
Name: template.Spec.SourceRef.Name, Name: template.Spec.SourceRef.Name,
Kind: template.Spec.SourceRef.Kind, Kind: template.Spec.SourceRef.Kind,
}, },
Interval: template.GetInterval(hr.Spec.Interval), Interval: template.GetInterval(hr.Spec.Interval),
ValuesFile: template.Spec.ValuesFile, ValuesFiles: template.Spec.ValuesFiles,
ValuesFile: template.Spec.ValuesFile,
}, },
} }
} }
@ -197,6 +199,8 @@ func helmChartRequiresUpdate(hr *v2.HelmRelease, chart *sourcev1.HelmChart) bool
return true return true
case template.GetInterval(hr.Spec.Interval) != chart.Spec.Interval: case template.GetInterval(hr.Spec.Interval) != chart.Spec.Interval:
return true return true
case !reflect.DeepEqual(template.Spec.ValuesFiles, chart.Spec.ValuesFiles):
return true
case template.Spec.ValuesFile != chart.Spec.ValuesFile: case template.Spec.ValuesFile != chart.Spec.ValuesFile:
return true return true
default: default:

View File

@ -420,6 +420,13 @@ func Test_helmChartRequiresUpdate(t *testing.T) {
}, },
want: true, want: true,
}, },
{
name: "detects values files change",
modify: func(hr *v2.HelmRelease, hc *sourcev1.HelmChart) {
hr.Spec.Chart.Spec.ValuesFiles = []string{"values-prod.yaml"}
},
want: true,
},
{ {
name: "detects values file change", name: "detects values file change",
modify: func(hr *v2.HelmRelease, hc *sourcev1.HelmChart) { modify: func(hr *v2.HelmRelease, hc *sourcev1.HelmChart) {

View File

@ -509,6 +509,21 @@ Kubernetes meta/v1.Duration
</tr> </tr>
<tr> <tr>
<td> <td>
<code>valuesFiles</code><br>
<em>
[]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Alternative list of values files to use as the chart values (values.yaml
is not included by default), expected to be a relative path in the SourceRef.
Values files are merged in the order of this list with the last file overriding
the first. Ignored when omitted.</p>
</td>
</tr>
<tr>
<td>
<code>valuesFile</code><br> <code>valuesFile</code><br>
<em> <em>
string string
@ -516,8 +531,10 @@ string
</td> </td>
<td> <td>
<em>(Optional)</em> <em>(Optional)</em>
<p>Alternative values file to use as the default chart values, expected to be a <p>Alternative values file to use as the default chart values, expected to
relative path in the SourceRef. Ignored when omitted.</p> be a relative path in the SourceRef. Deprecated in favor of ValuesFiles,
for backwards compatibility the file defined here is merged before the
ValuesFiles items. Ignored when omitted.</p>
</td> </td>
</tr> </tr>
</table> </table>
@ -599,6 +616,21 @@ Kubernetes meta/v1.Duration
</tr> </tr>
<tr> <tr>
<td> <td>
<code>valuesFiles</code><br>
<em>
[]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>Alternative list of values files to use as the chart values (values.yaml
is not included by default), expected to be a relative path in the SourceRef.
Values files are merged in the order of this list with the last file overriding
the first. Ignored when omitted.</p>
</td>
</tr>
<tr>
<td>
<code>valuesFile</code><br> <code>valuesFile</code><br>
<em> <em>
string string
@ -606,8 +638,10 @@ string
</td> </td>
<td> <td>
<em>(Optional)</em> <em>(Optional)</em>
<p>Alternative values file to use as the default chart values, expected to be a <p>Alternative values file to use as the default chart values, expected to
relative path in the SourceRef. Ignored when omitted.</p> be a relative path in the SourceRef. Deprecated in favor of ValuesFiles,
for backwards compatibility the file defined here is merged before the
ValuesFiles items. Ignored when omitted.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>

4
go.mod
View File

@ -9,7 +9,7 @@ require (
github.com/fluxcd/pkg/apis/kustomize v0.0.1 github.com/fluxcd/pkg/apis/kustomize v0.0.1
github.com/fluxcd/pkg/apis/meta v0.8.0 github.com/fluxcd/pkg/apis/meta v0.8.0
github.com/fluxcd/pkg/runtime v0.10.2 github.com/fluxcd/pkg/runtime v0.10.2
github.com/fluxcd/source-controller/api v0.10.0 github.com/fluxcd/source-controller/api v0.11.1-0.20210419133153-f56c96fff636
github.com/go-logr/logr v0.3.0 github.com/go-logr/logr v0.3.0
github.com/hashicorp/go-retryablehttp v0.6.8 github.com/hashicorp/go-retryablehttp v0.6.8
github.com/onsi/ginkgo v1.14.1 github.com/onsi/ginkgo v1.14.1
@ -18,7 +18,7 @@ require (
helm.sh/helm/v3 v3.5.3 helm.sh/helm/v3 v3.5.3
k8s.io/api v0.20.2 k8s.io/api v0.20.2
k8s.io/apiextensions-apiserver v0.20.2 k8s.io/apiextensions-apiserver v0.20.2
k8s.io/apimachinery v0.20.2 k8s.io/apimachinery v0.20.4
k8s.io/cli-runtime v0.20.2 k8s.io/cli-runtime v0.20.2
k8s.io/client-go v0.20.2 k8s.io/client-go v0.20.2
sigs.k8s.io/controller-runtime v0.8.3 sigs.k8s.io/controller-runtime v0.8.3

7
go.sum
View File

@ -239,8 +239,8 @@ github.com/fluxcd/pkg/apis/meta v0.8.0 h1:wqWpUsxhKHB1ZztcvOz+vnyhdKW9cWmjFp8Vci
github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po= github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po=
github.com/fluxcd/pkg/runtime v0.10.2 h1:JAI/pOfU3Rgr4MysWJoWenEP6vq03EspBmoekSZMUfo= github.com/fluxcd/pkg/runtime v0.10.2 h1:JAI/pOfU3Rgr4MysWJoWenEP6vq03EspBmoekSZMUfo=
github.com/fluxcd/pkg/runtime v0.10.2/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw= github.com/fluxcd/pkg/runtime v0.10.2/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw=
github.com/fluxcd/source-controller/api v0.10.0 h1:Mu4cAXtZ7yq/rIrab81q1jbbhWwUxxAZ2R5bZ1m8AxE= github.com/fluxcd/source-controller/api v0.11.1-0.20210419133153-f56c96fff636 h1:MKewkVohNKjqpQW/J4dU9oyKGv8TCN5jcfuS09iPkjY=
github.com/fluxcd/source-controller/api v0.10.0/go.mod h1:Vuw+7UqEUUOdkKBfTUPHwaQgbn6LL2FwqPDx2UAk7NE= github.com/fluxcd/source-controller/api v0.11.1-0.20210419133153-f56c96fff636/go.mod h1:/LRxF55Mf+j5mXVfHLbonb/2YYHVSaouLa5zt5aj7D4=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
@ -1275,8 +1275,9 @@ k8s.io/apiextensions-apiserver v0.20.2 h1:rfrMWQ87lhd8EzQWRnbQ4gXrniL/yTRBgYH1x1
k8s.io/apiextensions-apiserver v0.20.2/go.mod h1:F6TXp389Xntt+LUq3vw6HFOLttPa0V8821ogLGwb6Zs= k8s.io/apiextensions-apiserver v0.20.2/go.mod h1:F6TXp389Xntt+LUq3vw6HFOLttPa0V8821ogLGwb6Zs=
k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg= k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
k8s.io/apimachinery v0.20.1/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU= k8s.io/apimachinery v0.20.1/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
k8s.io/apimachinery v0.20.2 h1:hFx6Sbt1oG0n6DZ+g4bFt5f6BoMkOjKWsQFu077M3Vg=
k8s.io/apimachinery v0.20.2/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU= k8s.io/apimachinery v0.20.2/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
k8s.io/apimachinery v0.20.4 h1:vhxQ0PPUUU2Ns1b9r4/UFp13UPs8cw2iOoTjnY9faa0=
k8s.io/apimachinery v0.20.4/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
k8s.io/apiserver v0.20.1/go.mod h1:ro5QHeQkgMS7ZGpvf4tSMx6bBOgPfE+f52KwvXfScaU= k8s.io/apiserver v0.20.1/go.mod h1:ro5QHeQkgMS7ZGpvf4tSMx6bBOgPfE+f52KwvXfScaU=
k8s.io/apiserver v0.20.2 h1:lGno2t3gcZnLtzsKH4oG0xA9/4GTiBzMO1DGp+K+Bak= k8s.io/apiserver v0.20.2 h1:lGno2t3gcZnLtzsKH4oG0xA9/4GTiBzMO1DGp+K+Bak=
k8s.io/apiserver v0.20.2/go.mod h1:2nKd93WyMhZx4Hp3RfgH2K5PhwyTrprrkWYnI7id7jA= k8s.io/apiserver v0.20.2/go.mod h1:2nKd93WyMhZx4Hp3RfgH2K5PhwyTrprrkWYnI7id7jA=