/
condition.go
55 lines (43 loc) · 1.3 KB
/
condition.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
package helm
import (
"fmt"
"strings"
"github.com/sirupsen/logrus"
"helm.sh/helm/v3/pkg/repo"
"github.com/updatecli/updatecli/pkg/core/pipeline/scm"
)
// Condition checks if a specific chart version exist
func (c *Chart) Condition(source string, scm scm.ScmHandler) (pass bool, message string, err error) {
if strings.HasPrefix(c.spec.URL, "oci://") {
return c.OCICondition(source, scm)
}
if c.spec.Version != "" {
logrus.Infof("Version %v, already defined from configuration file", c.spec.Version)
} else {
c.spec.Version = source
}
var index repo.IndexFile
if strings.HasPrefix(c.spec.URL, "https://") || strings.HasPrefix(c.spec.URL, "http://") {
index, err = c.GetRepoIndexFromURL()
if err != nil {
return false, "", err
}
} else {
rootDir := ""
if scm != nil {
rootDir = scm.GetDirectory()
}
index, err = c.GetRepoIndexFromFile(rootDir)
if err != nil {
return false, "", err
}
}
baseMessage := ""
if c.spec.Version != "" {
baseMessage = fmt.Sprintf(" for version '%s'", c.spec.Version)
}
if index.Has(c.spec.Name, c.spec.Version) {
return true, fmt.Sprintf("Helm Chart %q is available on %s%s", c.spec.Name, c.spec.URL, baseMessage), nil
}
return false, fmt.Sprintf("the Helm chart %q isn't available on %s%s", c.spec.Name, c.spec.URL, baseMessage), nil
}