|
|
|
@ -21,6 +21,7 @@ import (
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/Masterminds/semver/v3"
|
|
|
|
|
"github.com/gosuri/uitable"
|
|
|
|
@ -61,6 +62,7 @@ func (d *Dependency) List(chartpath string, out io.Writer) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// dependecyStatus returns a string describing the status of a dependency viz a viz the parent chart.
|
|
|
|
|
func (d *Dependency) dependencyStatus(chartpath string, dep *chart.Dependency, parent *chart.Chart) string {
|
|
|
|
|
filename := fmt.Sprintf("%s-%s.tgz", dep.Name, "*")
|
|
|
|
|
|
|
|
|
@ -75,35 +77,40 @@ func (d *Dependency) dependencyStatus(chartpath string, dep *chart.Dependency, p
|
|
|
|
|
case err != nil:
|
|
|
|
|
return "bad pattern"
|
|
|
|
|
case len(archives) > 1:
|
|
|
|
|
return "too many matches"
|
|
|
|
|
case len(archives) == 1:
|
|
|
|
|
archive := archives[0]
|
|
|
|
|
if _, err := os.Stat(archive); err == nil {
|
|
|
|
|
c, err := loader.Load(archive)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "corrupt"
|
|
|
|
|
// See if the second part is a SemVer
|
|
|
|
|
found := []string{}
|
|
|
|
|
for _, arc := range archives {
|
|
|
|
|
// we need to trip the prefix dirs and the extension off.
|
|
|
|
|
filename = strings.TrimSuffix(filepath.Base(arc), ".tgz")
|
|
|
|
|
maybeVersion := strings.TrimPrefix(filename, fmt.Sprintf("%s-", dep.Name))
|
|
|
|
|
|
|
|
|
|
if _, err := semver.StrictNewVersion(maybeVersion); err == nil {
|
|
|
|
|
// If the version parsed without an error, it is possibly a valid
|
|
|
|
|
// version.
|
|
|
|
|
found = append(found, arc)
|
|
|
|
|
}
|
|
|
|
|
if c.Name() != dep.Name {
|
|
|
|
|
return "misnamed"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if l := len(found); l == 1 {
|
|
|
|
|
// If we get here, we do the same thing as in len(archives) == 1.
|
|
|
|
|
if r := statArchiveForStatus(found[0], dep); r != "" {
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if c.Metadata.Version != dep.Version {
|
|
|
|
|
constraint, err := semver.NewConstraint(dep.Version)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "invalid version"
|
|
|
|
|
}
|
|
|
|
|
// Fall through and look for directories
|
|
|
|
|
} else if l > 1 {
|
|
|
|
|
return "too many matches"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v, err := semver.NewVersion(c.Metadata.Version)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "invalid version"
|
|
|
|
|
}
|
|
|
|
|
// The sanest thing to do here is to fall through and see if we have any directory
|
|
|
|
|
// matches.
|
|
|
|
|
|
|
|
|
|
if !constraint.Check(v) {
|
|
|
|
|
return "wrong version"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "ok"
|
|
|
|
|
case len(archives) == 1:
|
|
|
|
|
archive := archives[0]
|
|
|
|
|
if r := statArchiveForStatus(archive, dep); r != "" {
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// End unnecessary code.
|
|
|
|
|
|
|
|
|
@ -137,6 +144,40 @@ func (d *Dependency) dependencyStatus(chartpath string, dep *chart.Dependency, p
|
|
|
|
|
return "unpacked"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stat an archive and return a message if the stat is successful
|
|
|
|
|
//
|
|
|
|
|
// This is a refactor of the code originally in dependencyStatus. It is here to
|
|
|
|
|
// support legacy behavior, and should be removed in Helm 4.
|
|
|
|
|
func statArchiveForStatus(archive string, dep *chart.Dependency) string {
|
|
|
|
|
if _, err := os.Stat(archive); err == nil {
|
|
|
|
|
c, err := loader.Load(archive)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "corrupt"
|
|
|
|
|
}
|
|
|
|
|
if c.Name() != dep.Name {
|
|
|
|
|
return "misnamed"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if c.Metadata.Version != dep.Version {
|
|
|
|
|
constraint, err := semver.NewConstraint(dep.Version)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "invalid version"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v, err := semver.NewVersion(c.Metadata.Version)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "invalid version"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !constraint.Check(v) {
|
|
|
|
|
return "wrong version"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// printDependencies prints all of the dependencies in the yaml file.
|
|
|
|
|
func (d *Dependency) printDependencies(chartpath string, out io.Writer, c *chart.Chart) {
|
|
|
|
|
table := uitable.New()
|
|
|
|
|