-
Notifications
You must be signed in to change notification settings - Fork 90
/
kustomize.go
43 lines (35 loc) · 919 Bytes
/
kustomize.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
package binaries
import (
"io/fs"
"os"
"os/exec"
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/logger"
)
var (
kustomizeBinPath string
)
// InitKustomize will discover kustomize binary path from the environment
func InitKustomize() (err error) {
kustomizeBinPath, err = discoverKustomizeBinPath(os.DirFS("/"))
if err != nil {
return errors.Wrap(err, "discover kustomize bin path")
}
logger.Infof("Found kustomize binary at %s", kustomizeBinPath)
return nil
}
// GetKustomizeBinPath returns the path to the kustomize binary
func GetKustomizeBinPath() string {
if kustomizeBinPath != "" {
return kustomizeBinPath
}
return "kustomize"
}
func discoverKustomizeBinPath(fileSystem fs.FS) (string, error) {
// NOTE: exec.LookPath does not yet support io/fs
binPath, err := exec.LookPath("kustomize")
if err != nil {
return "", errors.Wrap(err, "look path")
}
return binPath, nil
}