-
Notifications
You must be signed in to change notification settings - Fork 114
/
helm.go
105 lines (92 loc) · 2.16 KB
/
helm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package warehouses
import (
"context"
"github.com/pkg/errors"
kargoapi "github.com/akuity/kargo/api/v1alpha1"
"github.com/akuity/kargo/internal/credentials"
"github.com/akuity/kargo/internal/helm"
"github.com/akuity/kargo/internal/logging"
)
func (r *reconciler) selectCharts(
ctx context.Context,
namespace string,
subs []kargoapi.RepoSubscription,
) ([]kargoapi.Chart, error) {
charts := make([]kargoapi.Chart, 0, len(subs))
for _, s := range subs {
if s.Chart == nil {
continue
}
sub := s.Chart
logger := logging.LoggerFromContext(ctx).WithField("repoURL", sub.RepoURL)
if sub.Name != "" {
logger = logger.WithField("chart", sub.Name)
}
creds, ok, err :=
r.credentialsDB.Get(ctx, namespace, credentials.TypeHelm, sub.RepoURL)
if err != nil {
return nil, errors.Wrapf(
err,
"error obtaining credentials for chart repository %q",
sub.RepoURL,
)
}
var helmCreds *helm.Credentials
if ok {
helmCreds = &helm.Credentials{
Username: creds.Username,
Password: creds.Password,
}
logger.Debug("obtained credentials for chart repo")
} else {
logger.Debug("found no credentials for chart repo")
}
vers, err := r.selectChartVersionFn(
ctx,
sub.RepoURL,
sub.Name,
sub.SemverConstraint,
helmCreds,
)
if err != nil {
if sub.Name == "" {
return nil, errors.Wrapf(
err,
"error searching for latest version of chart in repository %q",
sub.RepoURL,
)
}
return nil, errors.Wrapf(
err,
"error searching for latest version of chart %q in repository %q",
sub.Name,
sub.RepoURL,
)
}
if vers == "" {
logger.Error("found no suitable chart version")
if sub.Name == "" {
return nil, errors.Errorf(
"found no suitable version of chart in repository %q",
sub.RepoURL,
)
}
return nil, errors.Errorf(
"found no suitable version of chart %q in repository %q",
sub.Name,
sub.RepoURL,
)
}
logger.WithField("version", vers).
Debug("found latest suitable chart version")
charts = append(
charts,
kargoapi.Chart{
RepoURL: sub.RepoURL,
Name: sub.Name,
Version: vers,
},
)
}
return charts, nil
}