Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Minor filter updates
Browse files Browse the repository at this point in the history
Adding more test data

Signed-off-by: Greg Sidelinger <gate@ilive4code.net>
  • Loading branch information
gregsidelinger committed Feb 14, 2020
1 parent 304acec commit b608901
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
47 changes: 47 additions & 0 deletions cmd/chart-repo/testdata/valid-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,53 @@ entries:
urls:
- https://kubernetes-charts.storage.googleapis.com/acs-engine-autoscaler-2.1.1.tgz
version: 2.1.1
nginx-ingress:
- apiVersion: v1
appVersion: 0.28.0
created: 2020-02-14T00:58:48.780420335Z
description: An nginx Ingress controller that uses ConfigMap to store the nginx
configuration.
digest: c170639916a16e33a570923cebefe06066558a266f28a9b2c04d98357f984427
engine: gotpl
home: https://github.com/kubernetes/ingress-nginx
icon: https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Nginx_logo.svg/500px-Nginx_logo.svg.png
keywords:
- ingress
- nginx
kubeVersion: '>=1.10.0-0'
maintainers:
- name: ChiefAlexander
- email: Trevor.G.Wood@gmail.com
name: taharah
name: nginx-ingress
sources:
- https://github.com/kubernetes/ingress-nginx
urls:
- https://kubernetes-charts.storage.googleapis.com/nginx-ingress-1.30.2.tgz
version: 1.30.2
- apiVersion: v1
appVersion: 0.28.0
created: 2020-02-13T21:29:23.810801158Z
description: An nginx Ingress controller that uses ConfigMap to store the nginx
configuration.
digest: be955d4e77599468d63d61d1dc471fc488e36a3fca2263efd639f17260db1968
engine: gotpl
home: https://github.com/kubernetes/ingress-nginx
icon: https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Nginx_logo.svg/500px-Nginx_logo.svg.png
keywords:
- ingress
- nginx
kubeVersion: '>=1.10.0-0'
maintainers:
- name: ChiefAlexander
- email: Trevor.G.Wood@gmail.com
name: taharah
name: nginx-ingress
sources:
- https://github.com/kubernetes/ingress-nginx
urls:
- https://kubernetes-charts.storage.googleapis.com/nginx-ingress-1.30.1.tgz
version: 1.30.1
wordpress:
- appVersion: 4.9.1
created: 2017-12-06T18:48:59.644981487Z
Expand Down
9 changes: 4 additions & 5 deletions cmd/chart-repo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,10 @@ func chartsFromIndex(index *helmrepo.IndexFile, r repo, filter *filters) []chart

if len(filter.Annotations) > 0 ||
len(filter.Names) > 0 {
if filterEntry(entry[0], filter){
charts = append(charts, newChart(entry, r))
if !filterEntry(entry[0], filter) {
log.WithFields(log.Fields{"name": entry[0].GetName()}).Info("skipping chart as filters did not match")
continue
}
log.WithFields(log.Fields{"name": entry[0].GetName()}).Info("skipping chart as filters did not match")
continue
}

charts = append(charts, newChart(entry, r))
Expand Down Expand Up @@ -548,7 +547,7 @@ func initNetClient(additionalCA string) (*http.Client, error) {
}

// return true if entry matches any filter
func filterEntry( entry *helmrepo.ChartVersion, filter *filters) bool {
func filterEntry(entry *helmrepo.ChartVersion, filter *filters) bool {
if len(filter.Annotations) > 0 {
for a, av := range filter.Annotations {
if v, ok := entry.Annotations[a]; ok {
Expand Down
6 changes: 3 additions & 3 deletions cmd/chart-repo/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func Test_parseRepoIndex(t *testing.T) {
t.Run("valid", func(t *testing.T) {
index, err := parseRepoIndex([]byte(validRepoIndexYAML))
assert.NoErr(t, err)
assert.Equal(t, len(index.Entries), 2, "number of charts")
assert.Equal(t, len(index.Entries), 3, "number of charts")
assert.Equal(t, index.Entries["acs-engine-autoscaler"][0].GetName(), "acs-engine-autoscaler", "chart version populated")
})
}
Expand All @@ -286,15 +286,15 @@ func Test_chartsFromIndex(t *testing.T) {
r := repo{Name: "test", URL: "http://testrepo.com"}
index, _ := parseRepoIndex([]byte(validRepoIndexYAML))
charts := chartsFromIndex(index, r, new(filters))
assert.Equal(t, len(charts), 2, "number of charts")
assert.Equal(t, len(charts), 3, "number of charts")
indexWithDeprecated := validRepoIndexYAML + `
deprecated-chart:
- name: deprecated-chart
deprecated: true`
index2, err := parseRepoIndex([]byte(indexWithDeprecated))
assert.NoErr(t, err)
charts = chartsFromIndex(index2, r, new(filters))
assert.Equal(t, len(charts), 2, "number of charts")
assert.Equal(t, len(charts), 3, "number of charts")
}

func Test_chartsFromIndexFilterByName(t *testing.T) {
Expand Down

0 comments on commit b608901

Please sign in to comment.