-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4766 from fluxcd/reconcile-hr-with-chartref
Add support for HelmRelease v2 in `flux reconcile` and `flux create`
- Loading branch information
Showing
7 changed files
with
253 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//go:build unit | ||
// +build unit | ||
|
||
/* | ||
Copyright 2024 The Flux authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import "testing" | ||
|
||
func TestCreateHelmRelease(t *testing.T) { | ||
tmpl := map[string]string{ | ||
"fluxns": allocateNamespace("flux-system"), | ||
} | ||
setupHRSource(t, tmpl) | ||
|
||
tests := []struct { | ||
name string | ||
args string | ||
assert assertFunc | ||
}{ | ||
{ | ||
name: "missing name", | ||
args: "create helmrelease --export", | ||
assert: assertError("name is required"), | ||
}, | ||
{ | ||
name: "missing chart template and chartRef", | ||
args: "create helmrelease podinfo --export", | ||
assert: assertError("chart or chart-ref is required"), | ||
}, | ||
{ | ||
name: "unknown source kind", | ||
args: "create helmrelease podinfo --source foobar/podinfo --chart podinfo --export", | ||
assert: assertError(`invalid argument "foobar/podinfo" for "--source" flag: source kind 'foobar' is not supported, must be one of: HelmRepository, GitRepository, Bucket`), | ||
}, | ||
{ | ||
name: "unknown chart reference kind", | ||
args: "create helmrelease podinfo --chart-ref foobar/podinfo --export", | ||
assert: assertError(`chart reference kind 'foobar' is not supported, must be one of: OCIRepository, HelmChart`), | ||
}, | ||
{ | ||
name: "basic helmrelease", | ||
args: "create helmrelease podinfo --source Helmrepository/podinfo --chart podinfo --interval=1m0s --export", | ||
assert: assertGoldenTemplateFile("testdata/create_hr/basic.yaml", tmpl), | ||
}, | ||
{ | ||
name: "chart with OCIRepository source", | ||
args: "create helmrelease podinfo --chart-ref OCIRepository/podinfo --interval=1m0s --export", | ||
assert: assertGoldenTemplateFile("testdata/create_hr/or_basic.yaml", tmpl), | ||
}, | ||
{ | ||
name: "chart with HelmChart source", | ||
args: "create helmrelease podinfo --chart-ref HelmChart/podinfo --interval=1m0s --export", | ||
assert: assertGoldenTemplateFile("testdata/create_hr/hc_basic.yaml", tmpl), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cmd := cmdTestCase{ | ||
args: tt.args + " -n " + tmpl["fluxns"], | ||
assert: tt.assert, | ||
} | ||
cmd.runTestCmd(t) | ||
}) | ||
} | ||
} | ||
|
||
func setupHRSource(t *testing.T, tmpl map[string]string) { | ||
t.Helper() | ||
testEnv.CreateObjectFile("./testdata/create_hr/setup-source.yaml", tmpl, t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
apiVersion: helm.toolkit.fluxcd.io/v2 | ||
kind: HelmRelease | ||
metadata: | ||
name: podinfo | ||
namespace: {{ .fluxns }} | ||
spec: | ||
chart: | ||
spec: | ||
chart: podinfo | ||
reconcileStrategy: ChartVersion | ||
sourceRef: | ||
kind: HelmRepository | ||
name: podinfo | ||
interval: 1m0s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
apiVersion: helm.toolkit.fluxcd.io/v2 | ||
kind: HelmRelease | ||
metadata: | ||
name: podinfo | ||
namespace: {{ .fluxns }} | ||
spec: | ||
chartRef: | ||
kind: HelmChart | ||
name: podinfo | ||
interval: 1m0s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
apiVersion: helm.toolkit.fluxcd.io/v2 | ||
kind: HelmRelease | ||
metadata: | ||
name: podinfo | ||
namespace: {{ .fluxns }} | ||
spec: | ||
chartRef: | ||
kind: OCIRepository | ||
name: podinfo | ||
interval: 1m0s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: {{ .fluxns }} | ||
--- | ||
apiVersion: source.toolkit.fluxcd.io/v1 | ||
kind: HelmRepository | ||
metadata: | ||
name: podinfo | ||
namespace: {{ .fluxns }} | ||
spec: | ||
interval: 1m0s | ||
provider: generic | ||
type: oci | ||
url: oci://ghcr.io/stefanprodan/charts | ||
--- | ||
apiVersion: source.toolkit.fluxcd.io/v1 | ||
kind: HelmChart | ||
metadata: | ||
name: podinfo | ||
namespace: {{ .fluxns }} | ||
spec: | ||
interval: 1m0s | ||
chart: podinfo | ||
sourceRef: | ||
kind: HelmRepository | ||
name: podinfo | ||
--- | ||
apiVersion: source.toolkit.fluxcd.io/v1beta2 | ||
kind: OCIRepository | ||
metadata: | ||
name: podinfo | ||
namespace: flux-system | ||
spec: | ||
interval: 10m | ||
url: oci://ghcr.io/stefanprodan/manifests/podinfo | ||
ref: | ||
tag: latest |