Skip to content

Commit

Permalink
fixes issue with not filtering invalid cahrts from index fluxcd#1515
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-Ricardo committed Jul 12, 2024
1 parent 6078ea4 commit 419f4df
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 3 deletions.
4 changes: 3 additions & 1 deletion internal/helm/repository/chart_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func IndexFromBytes(b []byte) (*repo.IndexFile, error) {
return nil, repo.ErrNoAPIVersion
}

for _, cvs := range i.Entries {
for name, cvs := range i.Entries {
for idx := len(cvs) - 1; idx >= 0; idx-- {
if cvs[idx] == nil {
continue
Expand All @@ -103,6 +103,8 @@ func IndexFromBytes(b []byte) (*repo.IndexFile, error) {
cvs = append(cvs[:idx], cvs[idx+1:]...)
}
}
// adjust slice to only contain a set of valid versions
i.Entries[name] = cvs
}

i.SortEntries()
Expand Down
21 changes: 19 additions & 2 deletions internal/helm/repository/chart_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ func verifyLocalIndex(t *testing.T, i *repo.IndexFile) {
g := NewWithT(t)

g.Expect(i.Entries).ToNot(BeNil())
g.Expect(i.Entries).To(HaveLen(3), "expected 3 entries in index file")
g.Expect(i.Entries).To(HaveLen(4), "expected 4 entries in index file")

alpine, ok := i.Entries["alpine"]
g.Expect(ok).To(BeTrue(), "expected 'alpine' entry to exist")
Expand All @@ -682,6 +682,10 @@ func verifyLocalIndex(t *testing.T, i *repo.IndexFile) {
g.Expect(ok).To(BeTrue(), "expected 'nginx' entry to exist")
g.Expect(nginx).To(HaveLen(2), "'nginx' should have 2 entries")

broken, ok := i.Entries["xChartWithBrokenDependencies"]
g.Expect(ok).To(BeTrue(), "expected 'xChartWithBrokenDependencies' entry to exist")
g.Expect(broken).To(HaveLen(1), "'xChartWithBrokenDependencies' should have 1 entries")

expects := []*repo.ChartVersion{
{
Metadata: &chart.Metadata{
Expand Down Expand Up @@ -723,8 +727,21 @@ func verifyLocalIndex(t *testing.T, i *repo.IndexFile) {
},
Digest: "sha256:1234567890abcdef",
},
{
Metadata: &chart.Metadata{
Name: "xChartWithBrokenDependencies",
Description: "string",
Version: "1.2.3",
Keywords: []string{"broken", "still accepted"},
Home: "https://example.com/something",
},
URLs: []string{
"https://kubernetes-charts.storage.googleapis.com/nginx-1.2.3.tgz",
},
Digest: "sha256:1234567890abcdef",
},
}
tests := []*repo.ChartVersion{alpine[0], nginx[0], nginx[1]}
tests := []*repo.ChartVersion{alpine[0], nginx[0], nginx[1], broken[0]}

for i, tt := range tests {
expect := expects[i]
Expand Down
30 changes: 30 additions & 0 deletions internal/helm/testdata/chartmuseum-index.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,36 @@
"created": "0001-01-01T00:00:00Z",
"digest": "sha256:1234567890abcdef"
}
],
"xChartWithBrokenDependencies": [
{
"name": "xChartWithBrokenDependencies",
"home": "https://example.com/something",
"version": "1.2.3",
"description": "string",
"keywords": [
"broken",
"still accepted"
],
"apiVersion": "v1",
"dependencies": [
{
"name": "kube-rbac-proxy",
"version": "0.9.1",
"repository": ""
},
{
"name": "kube-rbac-proxy",
"version": "0.9.1",
"repository": ""
}
],
"urls": [
"https://kubernetes-charts.storage.googleapis.com/nginx-1.2.3.tgz"
],
"created": "0001-01-01T00:00:00Z",
"digest": "sha256:1234567890abcdef"
}
]
}
}
16 changes: 16 additions & 0 deletions internal/helm/testdata/chartmuseum-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@ entries:
- small
- sumtin
digest: "sha256:1234567890abcdef"
xChartWithBrokenDependencies:
- name: xChartWithBrokenDependencies
description: string
version: 1.2.3
home: https://example.com/something
keywords:
- broken
- still accepted
urls:
- https://kubernetes-charts.storage.googleapis.com/nginx-1.2.3.tgz
digest: "sha256:1234567890abcdef"
dependencies:
- name: kube-rbac-proxy
version: "0.9.1"
- name: kube-rbac-proxy
version: "0.9.1"
16 changes: 16 additions & 0 deletions internal/helm/testdata/local-index-unordered.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,19 @@ entries:
- small
- sumtin
digest: "sha256:1234567890abcdef"
xChartWithBrokenDependencies:
- name: xChartWithBrokenDependencies
description: string
version: 1.2.3
home: https://example.com/something
keywords:
- broken
- still accepted
urls:
- https://kubernetes-charts.storage.googleapis.com/nginx-1.2.3.tgz
digest: "sha256:1234567890abcdef"
dependencies:
- name: kube-rbac-proxy
version: "0.9.1"
- name: kube-rbac-proxy
version: "0.9.1"
16 changes: 16 additions & 0 deletions internal/helm/testdata/local-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,19 @@ entries:
- small
- sumtin
digest: "sha256:1234567890abcdef"
xChartWithBrokenDependencies:
- name: xChartWithBrokenDependencies
description: string
version: 1.2.3
home: https://example.com/something
keywords:
- broken
- still accepted
urls:
- https://kubernetes-charts.storage.googleapis.com/nginx-1.2.3.tgz
digest: "sha256:1234567890abcdef"
dependencies:
- name: kube-rbac-proxy
version: "0.9.1"
- name: kube-rbac-proxy
version: "0.9.1"

0 comments on commit 419f4df

Please sign in to comment.