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

Commit

Permalink
ui: hide deprecated charts (#313)
Browse files Browse the repository at this point in the history
Skips any charts that are marked as deprecated (based on the rule
described in
https://github.com/kubernetes/helm/blob/master/docs/charts.md#deprecating-charts).

We currently ignore them entirely, in the future we may want still want
to process them and provide controls for displaying/hiding deprecated
charts in the frontend.
  • Loading branch information
prydonius authored Jul 19, 2017
1 parent 2a0148d commit 2ab28c6
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ repo-data/
coverage.txt
*.log
src/api/.glide
.vscode
7 changes: 7 additions & 0 deletions src/api/data/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/Masterminds/semver"
log "github.com/Sirupsen/logrus"
"github.com/ghodss/yaml"
"github.com/kubernetes-helm/monocular/src/api/config"
"github.com/kubernetes-helm/monocular/src/api/config/repos"
Expand Down Expand Up @@ -40,6 +41,12 @@ func ParseYAMLRepo(rawYAML []byte, repoName string) ([]*models.ChartPackage, err
return nil, err
}
for entry := range chartEntries {
if chartEntries[entry][0].Deprecated != nil && *chartEntries[entry][0].Deprecated {
log.WithFields(log.Fields{
"name": entry,
}).Info("Deprecated chart skipped")
continue
}
for i := range chartEntries[entry] {
chartEntries[entry][i].Repo = repoName
ret = append(ret, &chartEntries[entry][i])
Expand Down
60 changes: 60 additions & 0 deletions src/api/data/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ func TestParseYAMLRepo(t *testing.T) {
assert.ExistsErr(t, err, "sent bogus repo yaml ParseYAMLRepo")
}

func TestParseYAMLRepoWithDeprecatedChart(t *testing.T) {
charts, err := ParseYAMLRepo(getTestRepoYAMLWithDeprecatedChart(), repoName)
assert.NoErr(t, err)
assert.Equal(t, len(charts), 1, "charts slice response from ParseYAMLRepo")
assert.Equal(t, *charts[0].Name, chartName, "chart name field value")
assert.Equal(t, *charts[0].Created, chartCreated, "chart created field value")
assert.Equal(t, *charts[0].Digest, chartDigest, "chart checksum field value")
assert.Equal(t, *charts[0].Description, chartDescription, "chart description field value")
assert.Equal(t, *charts[0].Version, chartVersion, "chart version field value")
assert.Equal(t, *charts[0].AppVersion, chartAppVersion, "chart app version field value")
assert.Equal(t, *charts[0].Home, chartHome, "chart home field value")
}

func TestMakeChartResource(t *testing.T) {
charts, err := ParseYAMLRepo(getTestRepoYAML(), repoName)
repo := getRepoObject(charts[0])
Expand Down Expand Up @@ -278,6 +291,53 @@ entries:
generated: 2016-10-06T16:23:20.499029981-06:00`, APIVer1String, chartCreated, chartDescription, chartDigest, chartHome, chartName, chartSource, chartURL, chartVersion, chartAppVersion))
}

func getTestRepoYAMLWithDeprecatedChart() []byte {
return []byte(fmt.Sprintf(`
apiVersion: %s
entries:
apache:
- created: %s
description: %s
digest: %s
home: %s
name: %s
sources:
- %s
urls:
- %s
version: %s
appVersion: %s
deprecated:
- created: %s
deprecated: true
description: %s
digest: %s
home: %s
name: deprecated
sources:
- %s
urls:
- %s
version: 1.0.0
appVersion: %s
- created: %s
description: %s
digest: %s
home: %s
name: deprecated
sources:
- %s
urls:
- %s
version: %s
appVersion: %s
generated: 2016-10-06T16:23:20.499029981-06:00`,
APIVer1String, chartCreated, chartDescription, chartDigest, chartHome, chartName, chartSource, chartURL, chartVersion, chartAppVersion,
chartCreated, chartDescription, chartDigest, chartHome, chartSource, chartURL, chartAppVersion,
chartCreated, chartDescription, chartDigest, chartHome, chartSource, chartURL, chartVersion, chartAppVersion,
))
}

func TestMakeAvailableIcons(t *testing.T) {
charts, err := ParseYAMLRepo(getTestRepoYAML(), repoName)
assert.NoErr(t, err)
Expand Down
3 changes: 3 additions & 0 deletions src/api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ definitions:
- urls
- version
- appVersion
- deprecated
properties:
repo:
type: string
Expand Down Expand Up @@ -373,6 +374,8 @@ definitions:
type: array
items:
type: string
deprecated:
type: boolean
chart: # a data type that describes a "chart"
type: object
required:
Expand Down
20 changes: 20 additions & 0 deletions src/api/swagger/models/chart_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ type ChartPackage struct {
*/
Created *string `json:"created"`

/* deprecated
Required: true
*/
Deprecated *bool `json:"deprecated"`

/* description
Required: true
Expand Down Expand Up @@ -113,6 +119,11 @@ func (m *ChartPackage) Validate(formats strfmt.Registry) error {
res = append(res, err)
}

if err := m.validateDeprecated(formats); err != nil {
// prop
res = append(res, err)
}

if err := m.validateDescription(formats); err != nil {
// prop
res = append(res, err)
Expand Down Expand Up @@ -195,6 +206,15 @@ func (m *ChartPackage) validateCreated(formats strfmt.Registry) error {
return nil
}

func (m *ChartPackage) validateDeprecated(formats strfmt.Registry) error {

if err := validate.Required("deprecated", "body", m.Deprecated); err != nil {
return err
}

return nil
}

func (m *ChartPackage) validateDescription(formats strfmt.Registry) error {

if err := validate.Required("description", "body", m.Description); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/api/swagger/restapi/embedded_spec.go

Large diffs are not rendered by default.

0 comments on commit 2ab28c6

Please sign in to comment.