forked from helm/helm-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.go
104 lines (84 loc) · 2.67 KB
/
fetch.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
package action
import (
"os"
"path/filepath"
"github.com/helm/helm/chart"
"github.com/helm/helm/dependency"
"github.com/helm/helm/log"
helm "github.com/helm/helm/util"
)
// Fetch gets a chart from the source repo and copies to the workdir.
//
// - chartName is the source
// - lname is the local name for that chart (chart-name); if blank, it is set to the chart.
// - homedir is the home directory for the user
func Fetch(chartName, lname, homedir string) {
r := mustConfig(homedir).Repos
repository, chartName := r.RepoChart(chartName)
if lname == "" {
lname = chartName
}
fetch(chartName, lname, homedir, repository)
chartFilePath := helm.WorkspaceChartDirectory(homedir, lname, Chartfile)
cfile, err := chart.LoadChartfile(chartFilePath)
if err != nil {
log.Die("Source is not a valid chart. Missing Chart.yaml: %s", err)
}
deps, err := dependency.Resolve(cfile, helm.WorkspaceChartDirectory(homedir))
if err != nil {
log.Warn("Could not check dependencies: %s", err)
return
}
if len(deps) > 0 {
log.Warn("Unsatisfied dependencies:")
for _, d := range deps {
log.Msg("\t%s %s", d.Name, d.Version)
}
}
log.Info("Fetched chart into workspace %s", helm.WorkspaceChartDirectory(homedir, lname))
log.Info("Done")
}
func fetch(chartName, lname, homedir, chartpath string) {
src := helm.CacheDirectory(homedir, chartpath, chartName)
dest := helm.WorkspaceChartDirectory(homedir, lname)
fi, err := os.Stat(src)
if err != nil {
log.Warn("Oops. Looks like there was an issue finding the chart, %s, in %s. Running `helm update` to ensure you have the latest version of all Charts from Github...", lname, src)
Update(homedir)
fi, err = os.Stat(src)
if err != nil {
log.Die("Chart %s not found in %s", lname, src)
}
log.Info("Good news! Looks like that did the trick. Onwards and upwards!")
}
if !fi.IsDir() {
log.Die("Malformed chart %s: Chart must be in a directory.", chartName)
}
if err := os.MkdirAll(dest, 0755); err != nil {
log.Die("Could not create %q: %s", dest, err)
}
log.Debug("Fetching %s to %s", src, dest)
if err := helm.CopyDir(src, dest); err != nil {
log.Die("Failed copying %s to %s", src, dest)
}
if err := updateChartfile(src, dest, lname); err != nil {
log.Die("Failed to update Chart.yaml: %s", err)
}
}
func updateChartfile(src, dest, lname string) error {
sc, err := chart.LoadChartfile(filepath.Join(src, Chartfile))
if err != nil {
return err
}
dc, err := chart.LoadChartfile(filepath.Join(dest, Chartfile))
if err != nil {
return err
}
dc.Name = lname
dc.From = &chart.Dependency{
Name: sc.Name,
Version: sc.Version,
Repo: chart.RepoName(src),
}
return dc.Save(filepath.Join(dest, Chartfile))
}