Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/third_party/charts/charts.go
2499 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package charts
6
7
import (
8
"embed"
9
"io/fs"
10
"io/ioutil"
11
"os"
12
"path/filepath"
13
"strings"
14
)
15
16
type Chart struct {
17
// Name of the Helm chart - this is free text, but should be the same as the chart name
18
Name string
19
20
// The entire chart content
21
Content *embed.FS
22
23
// Location is the location of the chart within the content
24
Location string
25
26
// AdditionalFiles list files in the content filesystem that
27
// would be applied via "kubectl apply -f"
28
AdditionalFiles []string
29
}
30
31
// Export writes the content of the chart to the dest location
32
func (c *Chart) Export(dest string) error {
33
return fs.WalkDir(c.Content, ".", func(path string, d fs.DirEntry, err error) error {
34
if !strings.HasPrefix(path, c.Location) {
35
return nil
36
}
37
38
dst := filepath.Join(dest, strings.TrimPrefix(path, c.Location))
39
if d.IsDir() {
40
err := os.MkdirAll(dst, 0755)
41
if err != nil {
42
return err
43
}
44
} else {
45
fc, err := c.Content.ReadFile(path)
46
if err != nil {
47
return err
48
}
49
err = ioutil.WriteFile(dst, fc, 0644)
50
if err != nil {
51
return err
52
}
53
}
54
55
return nil
56
})
57
}
58
59