Adding test filters

Signed-off-by: Jiri Tyr <jiri.tyr@gmail.com>
This commit is contained in:
Jiri Tyr 2022-07-28 11:11:14 +01:00 committed by Hidde Beydals
parent 5843cc2ef0
commit 6db62ed507
No known key found for this signature in database
GPG Key ID: 979F380FC2341744
7 changed files with 193 additions and 0 deletions

View File

@ -747,6 +747,9 @@ type Test struct {
// actions in 'Install.IgnoreTestFailures' and 'Upgrade.IgnoreTestFailures'.
// +optional
IgnoreFailures bool `json:"ignoreFailures,omitempty"`
// Filters is a list of tests to run or exclude from running.
Filters *[]Filter `json:"filters,omitempty"`
}
// GetTimeout returns the configured timeout for the Helm test action,
@ -758,6 +761,24 @@ func (in Test) GetTimeout(defaultTimeout metav1.Duration) metav1.Duration {
return *in.Timeout
}
// Filters holds the configuration for individual Helm test filters.
type Filter struct {
// Name is the name of the test.
Name string `json:"name"`
// Exclude is specifies wheter the named test should be excluded.
// +optional
Exclude bool `json:"exclude,omitempty"`
}
// GetFilters returns the configured filters for the Helm test action/
func (in Test) GetFilters() []Filter {
if in.Filters == nil {
var filters []Filter
return filters
}
return *in.Filters
}
// Rollback holds the configuration for Helm rollback actions for this
// HelmRelease.
type Rollback struct {

View File

@ -44,6 +44,21 @@ func (in *CrossNamespaceObjectReference) DeepCopy() *CrossNamespaceObjectReferen
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Filter) DeepCopyInto(out *Filter) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Filter.
func (in *Filter) DeepCopy() *Filter {
if in == nil {
return nil
}
out := new(Filter)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *HelmChartTemplate) DeepCopyInto(out *HelmChartTemplate) {
*out = *in
@ -450,6 +465,15 @@ func (in *Test) DeepCopyInto(out *Test) {
*out = new(metav1.Duration)
**out = **in
}
if in.Filters != nil {
in, out := &in.Filters, &out.Filters
*out = new([]Filter)
if **in != nil {
in, out := *in, *out
*out = make([]Filter, len(*in))
copy(*out, *in)
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Test.

View File

@ -750,6 +750,9 @@ type Test struct {
// actions in 'Install.IgnoreTestFailures' and 'Upgrade.IgnoreTestFailures'.
// +optional
IgnoreFailures bool `json:"ignoreFailures,omitempty"`
// Filters is a list of tests to run or exclude from running.
Filters *[]Filter `json:"filters,omitempty"`
}
// GetTimeout returns the configured timeout for the Helm test action,
@ -761,6 +764,24 @@ func (in Test) GetTimeout(defaultTimeout metav1.Duration) metav1.Duration {
return *in.Timeout
}
// Filters holds the configuration for individual Helm test filters.
type Filter struct {
// Name is the name of the test.
Name string `json:"name"`
// Exclude is specifies wheter the named test should be excluded.
// +optional
Exclude bool `json:"exclude,omitempty"`
}
// GetFilters returns the configured filters for the Helm test action/
func (in Test) GetFilters() []Filter {
if in.Filters == nil {
var filters []Filter
return filters
}
return *in.Filters
}
// Rollback holds the configuration for Helm rollback actions for this
// HelmRelease.
type Rollback struct {

View File

@ -44,6 +44,21 @@ func (in *CrossNamespaceObjectReference) DeepCopy() *CrossNamespaceObjectReferen
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Filter) DeepCopyInto(out *Filter) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Filter.
func (in *Filter) DeepCopy() *Filter {
if in == nil {
return nil
}
out := new(Filter)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *HelmChartTemplate) DeepCopyInto(out *HelmChartTemplate) {
*out = *in
@ -510,6 +525,15 @@ func (in *Test) DeepCopyInto(out *Test) {
*out = new(metav1.Duration)
**out = **in
}
if in.Filters != nil {
in, out := &in.Filters, &out.Filters
*out = new([]Filter)
if **in != nil {
in, out := *in, *out
*out = make([]Filter, len(*in))
copy(*out, *in)
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Test.

View File

@ -604,6 +604,24 @@ spec:
description: Enable enables Helm test actions for this HelmRelease
after an Helm install or upgrade action has been performed.
type: boolean
filters:
description: Filters is a list of tests to run or exclude from
running.
items:
description: Filters holds the configuration for individual
Helm test filters.
properties:
exclude:
description: Exclude is specifies wheter the named test
should be excluded.
type: boolean
name:
description: Name is the name of the test.
type: string
required:
- name
type: object
type: array
ignoreFailures:
description: IgnoreFailures tells the controller to skip remediation
when the Helm tests are run but fail. Can be overwritten for
@ -1508,6 +1526,24 @@ spec:
description: Enable enables Helm test actions for this HelmRelease
after an Helm install or upgrade action has been performed.
type: boolean
filters:
description: Filters is a list of tests to run or exclude from
running.
items:
description: Filters holds the configuration for individual
Helm test filters.
properties:
exclude:
description: Exclude is specifies wheter the named test
should be excluded.
type: boolean
name:
description: Name is the name of the test.
type: string
required:
- name
type: object
type: array
ignoreFailures:
description: IgnoreFailures tells the controller to skip remediation
when the Helm tests are run but fail. Can be overwritten for

View File

@ -458,6 +458,46 @@ string
<h3 id="helm.toolkit.fluxcd.io/v2beta1.DeploymentAction">DeploymentAction
</h3>
<p>DeploymentAction defines a consistent interface for Install and Upgrade.</p>
<h3 id="helm.toolkit.fluxcd.io/v2beta1.Filter">Filter
</h3>
<p>Filters holds the configuration for individual Helm test filters.</p>
<div class="md-typeset__scrollwrap">
<div class="md-typeset__table">
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>name</code><br>
<em>
string
</em>
</td>
<td>
<p>Name is the name of the test.</p>
</td>
</tr>
<tr>
<td>
<code>exclude</code><br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Exclude is specifies wheter the named test should be excluded.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3 id="helm.toolkit.fluxcd.io/v2beta1.HelmChartTemplate">HelmChartTemplate
</h3>
<p>
@ -1868,6 +1908,19 @@ are run but fail. Can be overwritten for tests run after install or upgrade
actions in &lsquo;Install.IgnoreTestFailures&rsquo; and &lsquo;Upgrade.IgnoreTestFailures&rsquo;.</p>
</td>
</tr>
<tr>
<td>
<code>filters</code><br>
<em>
<a href="#helm.toolkit.fluxcd.io/v2beta1.[]./api/v2beta1.Filter">
[]./api/v2beta1.Filter
</a>
</em>
</td>
<td>
<p>Filters is a list of tests to run or exclude from running.</p>
</td>
</tr>
</tbody>
</table>
</div>

View File

@ -381,6 +381,20 @@ func (r *Runner) Test(hr v2.HelmRelease) (*release.Release, error) {
test.Namespace = hr.GetReleaseNamespace()
test.Timeout = hr.Spec.GetTest().GetTimeout(hr.GetTimeout()).Duration
filters := make(map[string][]string)
for _, f := range hr.Spec.GetTest().GetFilters() {
name := "name"
if f.Exclude {
name = fmt.Sprintf("!%s", name)
}
filters[name] = append(filters[name], f.Name)
}
test.Filters = filters
rel, err := test.Run(hr.GetReleaseName())
return rel, wrapActionErr(r.logBuffer, err)
}