-
Notifications
You must be signed in to change notification settings - Fork 90
/
write.go
51 lines (40 loc) · 1.22 KB
/
write.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
package downstream
import (
"os"
"path"
"path/filepath"
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/k8sutil"
)
type WriteOptions struct {
DownstreamDir string
MidstreamDir string
}
func (d *Downstream) WriteDownstream(options WriteOptions) error {
relativeMidstreamDir, err := filepath.Rel(options.DownstreamDir, options.MidstreamDir)
if err != nil {
return errors.Wrap(err, "failed to determine relative path for base from midstream")
}
renderDir := options.DownstreamDir
_, err = os.Stat(renderDir)
if err == nil {
// We intentionally don't support overwriting downstreams... this is user-created content
// and the user should be intentional about removing it
// But it's also not an error
return nil
}
fileRenderPath := path.Join(renderDir, "kustomization.yaml")
dir, _ := path.Split(fileRenderPath)
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, 0744); err != nil {
return errors.Wrap(err, "failed to mkdir")
}
}
d.Kustomization.Bases = []string{
relativeMidstreamDir,
}
if err := k8sutil.WriteKustomizationToFile(*d.Kustomization, fileRenderPath); err != nil {
return errors.Wrap(err, "failed to write kustomization to file")
}
return nil
}