Skip to content

Commit cdcced9

Browse files
Merge branch 'master' of github.com:DirtyCajunRice/hub
Signed-off-by: Nicholas St. Germain <[email protected]>
2 parents e9c1d8a + 81810b1 commit cdcced9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1108
-677
lines changed

docs/helm_annotations.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Artifact Hub annotations in Helm Chart.yaml file
2+
3+
Artifact Hub uses the metadata in the chart's `Chart.yaml` file to populate the information for a package of kind Helm. Usually most of the information needed is already there, so there is no extra work required by charts maintainers to list them on Artifact Hub.
4+
5+
However, sometimes there might be cases in which it may be useful to provide some more context that helps improving users' experience in Artifact Hub. This can be done using some special **annotations** in the [Chart.yaml](https://helm.sh/docs/topics/charts/#the-chartyaml-file) file.
6+
7+
## Supported annotations
8+
9+
- **artifacthub.io/operator** *(boolean)*
10+
11+
Use this annotation to indicate that your chart represents an operator. Artifact Hub at the moment also considers your chart to represent an operator if the word *operator* appears in the chart name.
12+
13+
- **artifacthub.io/links** *(yaml string, see example below)*
14+
15+
This annotation allows including named links, which will be rendered nicely in Artifact Hub. You can use this annotation to include links not included previously in the Chart.yaml file, or you can use it to name links already present (in the sources section, for example).
16+
17+
- **artifacthub.io/maintainers** *(yaml string, see example below)*
18+
19+
This annotation can be used if you want to display a different name for a given user in Artifact Hub than the one used in the Chart.yaml file. If the email used matches, the name used in the annotations entry will be displayed in Artifact Hub. It's also possible to include maintainers that should only be listed in Artifact Hub by adding additional entries.
20+
21+
## Example
22+
23+
Artifact Hub annotations in`Chart.yaml`:
24+
25+
```yaml
26+
annotations:
27+
"artifacthub.io/operator": true
28+
"artifacthub.io/links": |
29+
- name: link1
30+
url: https://link1.url
31+
- name: link2
32+
url: https://link2.url
33+
"artifacthub.io/maintainers": |
34+
- name: user1
35+
36+
- name: user2
37+
38+
```
-94 Bytes
Binary file not shown.

internal/tracker/helm/worker.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010
"path"
1111
"runtime/debug"
12+
"strconv"
1213
"strings"
1314
"sync"
1415

@@ -19,10 +20,17 @@ import (
1920
"github.com/rs/zerolog/log"
2021
"github.com/vincent-petithory/dataurl"
2122
"golang.org/x/time/rate"
23+
"gopkg.in/yaml.v2"
2224
"helm.sh/helm/v3/pkg/chart"
2325
"helm.sh/helm/v3/pkg/chart/loader"
2426
)
2527

28+
const (
29+
operatorAnnotation = "artifacthub.io/operator"
30+
linksAnnotation = "artifacthub.io/links"
31+
maintainersAnnotation = "artifacthub.io/maintainers"
32+
)
33+
2634
// githubRL represents a rate limiter used when loading charts from Github, to
2735
// avoid some rate limiting issues were are experiencing.
2836
var githubRL = rate.NewLimiter(2, 1)
@@ -195,6 +203,11 @@ func (w *Worker) handleRegisterJob(j *Job) {
195203
}
196204
}
197205

206+
// Enrich package with information from annotations
207+
if err := enrichPackageFromAnnotations(p, md.Annotations); err != nil {
208+
w.warn(name, version, fmt.Errorf("error enriching package: %w", err))
209+
}
210+
198211
// Register package
199212
w.logger.Debug().Str("name", md.Name).Str("v", md.Version).Msg("registering package")
200213
if err := w.svc.Pm.Register(w.svc.Ctx, p); err != nil {
@@ -297,3 +310,76 @@ func getFile(chart *chart.Chart, name string) *chart.File {
297310
}
298311
return nil
299312
}
313+
314+
// enrichPackageFromAnnotations adds some extra information to the package from
315+
// the provided annotations.
316+
//
317+
// The annotations supported at the moment are:
318+
//
319+
// - artifacthub.io/operator
320+
// - artifacthub.io/links
321+
// - artifacthub.io/maintainers
322+
//
323+
// Example:
324+
//
325+
// annotations:
326+
// "artifacthub.io/operator": true
327+
// "artifacthub.io/links": |
328+
// - name: link1
329+
// url: https://link1.url
330+
// - name: link2
331+
// url: https://link2.url
332+
// "artifacthub.io/maintainers": |
333+
// - name: user1
334+
335+
// - name: user2
336+
337+
//
338+
func enrichPackageFromAnnotations(p *hub.Package, annotations map[string]string) error {
339+
// Operator flag
340+
if v, ok := annotations[operatorAnnotation]; ok {
341+
isOperator, err := strconv.ParseBool(v)
342+
if err != nil {
343+
return errors.New("invalid operator value")
344+
}
345+
p.IsOperator = isOperator
346+
}
347+
348+
// Links
349+
if v, ok := annotations[linksAnnotation]; ok {
350+
var links []*hub.Link
351+
if err := yaml.Unmarshal([]byte(v), &links); err != nil {
352+
return fmt.Errorf("invalid links value: %s", v)
353+
}
354+
LL:
355+
for _, link := range links {
356+
for _, pLink := range p.Links {
357+
if link.URL == pLink.URL {
358+
pLink.Name = link.Name
359+
continue LL
360+
}
361+
}
362+
p.Links = append(p.Links, link)
363+
}
364+
}
365+
366+
// Maintainers
367+
if v, ok := annotations[maintainersAnnotation]; ok {
368+
var maintainers []*hub.Maintainer
369+
if err := yaml.Unmarshal([]byte(v), &maintainers); err != nil {
370+
return fmt.Errorf("invalid maintainers value: %s", v)
371+
}
372+
ML:
373+
for _, maintainer := range maintainers {
374+
for _, pMaintainer := range p.Maintainers {
375+
if maintainer.Email == pMaintainer.Email {
376+
pMaintainer.Name = maintainer.Name
377+
continue ML
378+
}
379+
}
380+
p.Maintainers = append(p.Maintainers, maintainer)
381+
}
382+
}
383+
384+
return nil
385+
}

0 commit comments

Comments
 (0)