Merge pull request #419 from helmfile/405-helmfile-deps-cannot-create-a-lock-file-for-an-oci-repo

fix: helmfile deps issue with oci repo
This commit is contained in:
yxxhero 2022-10-09 09:13:46 +08:00 committed by GitHub
commit ad257554c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 6 deletions

View File

@ -217,16 +217,13 @@ func (st *HelmState) updateDependenciesInTempDir(shell helmexec.DependencyUpdate
} }
func getUnresolvedDependenciess(st *HelmState) (string, *UnresolvedDependencies, error) { func getUnresolvedDependenciess(st *HelmState) (string, *UnresolvedDependencies, error) {
repoToURL := map[string]string{} repoToURL := map[string]RepositorySpec{}
for _, r := range st.Repositories { for _, r := range st.Repositories {
repoToURL[r.Name] = r.URL repoToURL[r.Name] = r
} }
unresolved := &UnresolvedDependencies{deps: map[string][]unresolvedChartDependency{}} unresolved := &UnresolvedDependencies{deps: map[string][]unresolvedChartDependency{}}
// if err := unresolved.Add("stable/envoy", "https://kubernetes-charts.storage.googleapis.com", ""); err != nil {
// panic(err)
// }
for _, r := range st.Releases { for _, r := range st.Releases {
repo, chart, ok := resolveRemoteChart(r.Chart) repo, chart, ok := resolveRemoteChart(r.Chart)
@ -234,13 +231,19 @@ func getUnresolvedDependenciess(st *HelmState) (string, *UnresolvedDependencies,
continue continue
} }
url, ok := repoToURL[repo] repoSpec, ok := repoToURL[repo]
// Skip this chart from dependency management, as there's no matching `repository` in the helmfile state, // Skip this chart from dependency management, as there's no matching `repository` in the helmfile state,
// which may imply that this is a local chart within a directory, like `charts/myapp` // which may imply that this is a local chart within a directory, like `charts/myapp`
if !ok { if !ok {
continue continue
} }
url := repoSpec.URL
if repoSpec.OCI {
url = fmt.Sprintf("oci://%s", url)
}
if err := unresolved.Add(chart, url, r.Version); err != nil { if err := unresolved.Add(chart, url, r.Version); err != nil {
return "", nil, err return "", nil, err
} }

View File

@ -0,0 +1,66 @@
package state
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestGetUnresolvedDependenciess(t *testing.T) {
tests := []struct {
name string
helmState *HelmState
wantErr bool
expectfile string
expectDeps *UnresolvedDependencies
}{
{
name: "oci chart",
helmState: &HelmState{
FilePath: "helmfile.yaml",
ReleaseSetSpec: ReleaseSetSpec{
Releases: []ReleaseSpec{
{
Name: "foo",
Chart: "charts/abc",
Version: "0.1.0",
},
},
Repositories: []RepositorySpec{
{
Name: "charts",
URL: "localhost:5000/aaa",
OCI: true,
},
},
},
},
wantErr: false,
expectfile: "helmfile",
expectDeps: &UnresolvedDependencies{
deps: map[string][]unresolvedChartDependency{
"abc": {
{
ChartName: "abc",
Repository: "oci://localhost:5000/aaa",
VersionConstraint: "0.1.0",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f, ds, err := getUnresolvedDependenciess(tt.helmState)
if tt.wantErr {
require.Error(t, err, "getUnresolvedDependenciess() error = nil, wantErr")
} else {
require.NoErrorf(t, err, "getUnresolvedDependenciess() want no error, got %v", err)
}
require.Equalf(t, tt.expectfile, f, "getUnresolvedDependenciess() expect file %s, got %s", tt.expectfile, f)
require.Equalf(t, tt.expectDeps, ds, "getUnresolvedDependenciess() expect deps %v, got %v", tt.expectDeps, ds)
})
}
}