From c95b4f0fdc930351639096fa59894c874e8b29fc Mon Sep 17 00:00:00 2001 From: Greg Sidelinger Date: Thu, 13 Feb 2020 20:51:30 -0500 Subject: [PATCH] Minor filter updates Adding more test data Signed-off-by: Greg Sidelinger --- cmd/chart-repo/testdata/valid-index.yaml | 47 ++++++++++++++++++++++++ cmd/chart-repo/utils.go | 9 ++--- cmd/chart-repo/utils_test.go | 6 +-- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/cmd/chart-repo/testdata/valid-index.yaml b/cmd/chart-repo/testdata/valid-index.yaml index cab568ca..549ff28f 100644 --- a/cmd/chart-repo/testdata/valid-index.yaml +++ b/cmd/chart-repo/testdata/valid-index.yaml @@ -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 diff --git a/cmd/chart-repo/utils.go b/cmd/chart-repo/utils.go index 985ed3c1..f54f804f 100644 --- a/cmd/chart-repo/utils.go +++ b/cmd/chart-repo/utils.go @@ -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)) @@ -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 { diff --git a/cmd/chart-repo/utils_test.go b/cmd/chart-repo/utils_test.go index ac77dc08..a9fc6905 100644 --- a/cmd/chart-repo/utils_test.go +++ b/cmd/chart-repo/utils_test.go @@ -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") }) } @@ -286,7 +286,7 @@ 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 @@ -294,7 +294,7 @@ func Test_chartsFromIndex(t *testing.T) { 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) {