forked from helmfile/helmfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
73 lines (60 loc) · 1.67 KB
/
util.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
package state
import (
"fmt"
"os"
"path/filepath"
"strings"
)
var (
// current working directory
currentDirSymbol = "."
// parent directory
parentDirSymbol = ".."
)
func isLocalChart(chart string) bool {
if strings.HasPrefix(chart, fmt.Sprintf("%s%c", currentDirSymbol, os.PathSeparator)) || strings.HasPrefix(chart, fmt.Sprintf("%s%c", parentDirSymbol, os.PathSeparator)) {
return true
}
uriLike := strings.Contains(chart, "://")
if uriLike {
return false
}
return chart == "" ||
filepath.IsAbs(chart) ||
!strings.Contains(chart, "/") ||
(len(strings.Split(chart, "/")) != 2 &&
len(strings.Split(chart, "/")) != 3)
}
func resolveRemoteChart(repoAndChart string) (string, string, bool) {
if isLocalChart(repoAndChart) {
return "", "", false
}
uriLike := strings.Contains(repoAndChart, "://")
if uriLike {
return "", "", false
}
parts := strings.SplitN(repoAndChart, "/", 2)
if len(parts) < 2 {
return "", "", false
}
repo := parts[0]
chart := parts[1]
return repo, chart, true
}
// normalizeChart allows for the distinction between a file path reference and repository references.
// - Any single (or double character) followed by a `/` will be considered a local file reference and
// be constructed relative to the `base path`.
// - Everything else is assumed to be an absolute path or an actual <repository>/<chart> reference.
func normalizeChart(basePath, chart string) string {
if !isLocalChart(chart) || filepath.IsAbs(chart) {
return chart
}
return filepath.Join(basePath, chart)
}
func getBuildDepsFlags(cpr *chartPrepareResult) []string {
flags := []string{}
if cpr.skipRefresh {
flags = append(flags, "--skip-refresh")
}
return flags
}