Skip to content

Commit

Permalink
Adds a layer field to the profiles response (#1277)
Browse files Browse the repository at this point in the history
* Adds a layer field to the profiles response

- Layers allow you to specify the order in which profiles are installed

* fixes tests

* fixes up formatting

* new buf

* fixes cuddling

* Add comment about Layers
  • Loading branch information
foot committed Jan 11, 2022
1 parent 1a3a6ed commit 022e932
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 56 deletions.
2 changes: 2 additions & 0 deletions api/profiles/profiles.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ message Profile {
HelmRepository helm_repository = 10;
// A list of available versions
repeated string available_versions = 11;
// The layer of the profile
string layer = 12;
}

message GetProfilesRequest {
Expand Down
4 changes: 4 additions & 0 deletions api/profiles/profiles.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@
"type": "string"
},
"title": "A list of available versions"
},
"layer": {
"type": "string",
"title": "The layer of the profile"
}
}
}
Expand Down
122 changes: 66 additions & 56 deletions pkg/api/profiles/profiles.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/helm/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"net/url"
"os"
"path"
"sort"

Expand All @@ -27,6 +28,11 @@ import (
// that they provide a Profile.
const ProfileAnnotation = "weave.works/profile"

// LayerAnnotation specifies profile application order.
// Profiles are sorted by layer and those at a higher "layer" are only installed after
// lower layers have successfully installed and started.
const LayerAnnotation = "weave.works/layer"

// NewRepoManager creates and returns a new RepoManager.
func NewRepoManager(kc client.Client, cacheDir string) *RepoManager {
return &RepoManager{
Expand Down Expand Up @@ -97,6 +103,7 @@ func (h *RepoManager) GetCharts(ctx context.Context, hr *sourcev1beta1.HelmRepos
Keywords: v.Keywords,
Icon: v.Icon,
KubeVersion: v.KubeVersion,
Layer: getLayer(v.Annotations),
}
for _, m := range v.Maintainers {
p.Maintainers = append(p.Maintainers, &pb.Maintainer{
Expand Down Expand Up @@ -229,6 +236,16 @@ func credsForRepository(ctx context.Context, kc client.Client, hr *sourcev1beta1
}

func fetchIndexFile(chartURL string) (*repo.IndexFile, error) {
if hostname := os.Getenv("SOURCE_CONTROLLER_LOCALHOST"); hostname != "" {
u, err := url.Parse(chartURL)
if err != nil {
return nil, err
}

u.Host = hostname
chartURL = u.String()
}

u, err := url.Parse(chartURL)
if err != nil {
return nil, fmt.Errorf("error parsing URL %q: %w", chartURL, err)
Expand Down Expand Up @@ -263,6 +280,10 @@ func fetchIndexFile(chartURL string) (*repo.IndexFile, error) {
return i, nil
}

func getLayer(annotations map[string]string) string {
return annotations[LayerAnnotation]
}

func hasAnnotation(cm *chart.Metadata, name string) bool {
for k := range cm.Annotations {
if k == name {
Expand Down
1 change: 1 addition & 0 deletions pkg/helm/charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var _ = Describe("RepoManager", func() {
"1.1.0",
"1.1.2",
},
Layer: "layer-1",
}))
})

Expand Down
2 changes: 2 additions & 0 deletions pkg/helm/testdata/with_profiles/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ entries:
- created: 2016-10-06T16:23:20.499543808-06:00
annotations:
weave.works/profile: demo-profile
weave.works/layer: layer-1
description: Simple demo profile
digest: aaff4545f79d8b2913a10cb400ebb6fa9c77fe813287afbacf1a0b897cdffffff
home: https://helm.sh/helm
Expand Down Expand Up @@ -76,6 +77,7 @@ entries:
- created: 2016-10-06T16:23:20.499543808-06:00
annotations:
weave.works/profile: demo-profile
weave.works/layer: layer-1
description: Simple demo profile
digest: aaff4545f79d8b2913a10cb400ebb6fa9c77fe813287afbacf1a0b897cdffffff
home: https://helm.sh/helm
Expand Down
1 change: 1 addition & 0 deletions ui/lib/api/profiles/profiles.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type Profile = {
kubeVersion?: string
helmRepository?: HelmRepository
availableVersions?: string[]
layer?: string
}

export type GetProfilesRequest = {
Expand Down

0 comments on commit 022e932

Please sign in to comment.