Skip to content

Commit

Permalink
Add support for ChartCenter (#1492)
Browse files Browse the repository at this point in the history
Resolves #1326
  • Loading branch information
mumoshu authored Sep 21, 2020
1 parent b176408 commit 942b9a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
14 changes: 11 additions & 3 deletions pkg/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,11 +775,11 @@ func Test_isLocalChart(t *testing.T) {
want: true,
},
{
name: "local chart in 3-level deep dir",
name: "remote chart in 3-level deep dir (e.g. ChartCenter)",
args: args{
chart: "foo/bar/baz",
chart: "center/bar/baz",
},
want: true,
want: false,
},
}
for i := range tests {
Expand Down Expand Up @@ -818,6 +818,14 @@ func Test_normalizeChart(t *testing.T) {
},
want: "remote/app",
},
{
name: "chartcenter repo path",
args: args{
basePath: "/Users/jane/code/deploy/charts",
chart: "center/stable/myapp",
},
want: "center/stable/myapp",
},
{
name: "construct local chart path, parent dir",
args: args{
Expand Down
12 changes: 9 additions & 3 deletions pkg/state/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ func isLocalChart(chart string) bool {
return chart == "" ||
chart[0] == '/' ||
strings.Index(chart, "/") == -1 ||
len(strings.Split(chart, "/")) != 2
(len(strings.Split(chart, "/")) != 2 &&
len(strings.Split(chart, "/")) != 3)
}

func resolveRemoteChart(repoAndChart string) (string, string, bool) {
if isLocalChart(repoAndChart) {
return "", "", false
}

parts := strings.Split(repoAndChart, "/")
if len(parts) != 2 {
uriLike := strings.Index(repoAndChart, "://") > -1
if uriLike {
return "", "", false
}

parts := strings.SplitN(repoAndChart, "/", 2)
if len(parts) < 2 {
return "", "", false
}

Expand Down
14 changes: 10 additions & 4 deletions pkg/state/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ func TestIsLocalChart(t *testing.T) {
input: "stable/mysql",
expected: false,
},
{
input: "center/stable/mysql",
expected: false,
},
{
input: "./charts/myapp",
expected: true,
},
{
input: "charts/mysubsystem/myapp",
expected: true,
input: "center/stable/myapp",
expected: false,
},
{
input: "./charts/mysubsystem/myapp",
Expand Down Expand Up @@ -77,8 +81,10 @@ func TestResolveRemortChart(t *testing.T) {
remote: false,
},
{
input: "charts/mysubsystem/myapp",
remote: false,
input: "center/stable/myapp",
repo: "center",
chart: "stable/myapp",
remote: true,
},
{
input: "./charts/mysubsystem/myapp",
Expand Down
6 changes: 3 additions & 3 deletions test/integration/happypath.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ environments:
repositories:
- name: stable
url: https://kubernetes-charts.storage.googleapis.com/
- name: incubator
url: https://kubernetes-charts-incubator.storage.googleapis.com
- name: center
url: https://repo.chartcenter.io

helmDefaults:
kubeContext: minikube
Expand All @@ -29,7 +29,7 @@ releases:
- "{{`{{.HelmfileCommand}}`}}"

- name: raw
chart: incubator/raw
chart: center/incubator/raw
values:
- mysecret: {{ .Environment.Values.mysecret }}
- values.yaml
Expand Down

0 comments on commit 942b9a6

Please sign in to comment.