Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for charts from OCI registries to specify a chart path #856

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/samples/source_v1beta2_helmchart_helmrepository-oci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmChart
metadata:
name: helmchart-sample-oci
spec:
chart: stefanprodan/charts/podinfo
version: '>=6.0.0 <7.0.0'
sourceRef:
kind: HelmRepository
name: helmrepository-sample-oci
interval: 1m
8 changes: 8 additions & 0 deletions config/samples/source_v1beta2_helmrepository-oci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: helmrepository-sample-oci
spec:
interval: 1m
type: oci
url: oci://ghcr.io/
2 changes: 2 additions & 0 deletions hack/ci/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ kubectl -n source-system rollout status deploy/source-controller --timeout=1m
kubectl -n source-system wait gitrepository/gitrepository-sample --for=condition=ready --timeout=1m
kubectl -n source-system wait ocirepository/ocirepository-sample --for=condition=ready --timeout=1m
kubectl -n source-system wait helmrepository/helmrepository-sample --for=condition=ready --timeout=1m
kubectl -n source-system wait helmrepository/helmrepository-sample-oci --for=condition=ready --timeout=1m
kubectl -n source-system wait helmchart/helmchart-sample --for=condition=ready --timeout=1m
kubectl -n source-system wait helmchart/helmchart-sample-oci --for=condition=ready --timeout=1m
kubectl -n source-system delete -f "${ROOT_DIR}/config/samples"

echo "Run HelmChart values file tests"
Expand Down
4 changes: 2 additions & 2 deletions internal/helm/chart/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func (r RemoteReference) Validate() error {
if r.Name == "" {
return fmt.Errorf("no name set for remote chart reference")
}
name := regexp.MustCompile("^([-a-z0-9]*)$")
name := regexp.MustCompile("^([-a-z0-9]+/?)+$")
if !name.MatchString(r.Name) {
return fmt.Errorf("invalid chart name '%s': a valid name must be lower case letters and numbers and MAY be separated with dashes (-)", r.Name)
return fmt.Errorf("invalid chart name '%s': a valid name must be lower case letters and numbers and MAY be separated with dashes (-) or slashes (/)", r.Name)
}
return nil
}
Expand Down
12 changes: 11 additions & 1 deletion internal/helm/chart/builder_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ func TestRemoteBuilder_BuildFromOCIChatRepository(t *testing.T) {

registryClient := &mockRegistryClient{
tags: map[string][]string{
"localhost:5000/my_repo/grafana": {"6.17.4"},
"localhost:5000/my_repo/grafana": {"6.17.4"},
"localhost:5000/my_repo/another/grafana": {"6.17.4"},
},
}

Expand Down Expand Up @@ -318,6 +319,15 @@ func TestRemoteBuilder_BuildFromOCIChatRepository(t *testing.T) {
"replicaCount": float64(1),
},
},
{
name: "default values",
reference: RemoteReference{Name: "another/grafana"},
repository: mockRepo(),
wantVersion: "0.1.0",
wantValues: chartutil.Values{
"replicaCount": float64(1),
},
},
{
name: "merge values",
reference: RemoteReference{Name: "grafana"},
Expand Down
19 changes: 16 additions & 3 deletions internal/helm/chart/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,34 @@ func TestRemoteReference_Validate(t *testing.T) {
name: "ref with name",
ref: RemoteReference{Name: "valid-chart-name"},
},
{
name: "ref with single-character name",
ref: RemoteReference{Name: "a"},
},
{
name: "ref with invalid name",
ref: RemoteReference{Name: "iNvAlID-ChArT-NAmE!"},
wantErr: "invalid chart name 'iNvAlID-ChArT-NAmE!'",
},
{
name: "ref with Artifactory specific invalid format",
ref: RemoteReference{Name: "i-shall/not"},
wantErr: "invalid chart name 'i-shall/not'",
name: "ref with Artifactory specific valid format",
ref: RemoteReference{Name: "i-shall/not"},
},
makkes marked this conversation as resolved.
Show resolved Hide resolved
{
name: "ref without name",
ref: RemoteReference{},
wantErr: "no name set for remote chart reference",
},
{
name: "ref with only a slash",
ref: RemoteReference{Name: "/"},
wantErr: "invalid chart name '/'",
},
{
name: "ref with double slash",
ref: RemoteReference{Name: "not//a/valid/chart"},
wantErr: "invalid chart name 'not//a/valid/chart'",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down