Skip to content

Commit e2a9e1f

Browse files
authored
Merge pull request #184 from mattfarina/fix-182
Fixing issue where charts in repos not erroring on dep issues
2 parents 38f3545 + 2029e94 commit e2a9e1f

File tree

2 files changed

+58
-24
lines changed

2 files changed

+58
-24
lines changed

cmd/hypper/install.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"strings"
21+
2022
"github.com/pkg/errors"
2123
"github.com/spf13/cobra"
2224
"github.com/spf13/pflag"
@@ -83,6 +85,12 @@ func newInstallCmd(actionConfig *action.Configuration, logger log.Logger) *cobra
8385
// TODO decide how to use returned rel:
8486
_, err := runInstall(solver.InstallOne, args, client, valueOpts, logger)
8587
if err != nil {
88+
// Capturing a specific error message, when a chart in a repo
89+
// was called for but the repo was never added. Adding more
90+
// context for the user.
91+
if strings.HasPrefix(err.Error(), "unable to load dependency") {
92+
logger.Info("Please add any missing repositories, if necessary")
93+
}
8694
err = errors.New(eyecandy.ESPrintf(settings.NoEmojis, ":x: %s", err))
8795
return err
8896
}

pkg/action/world.go

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ limitations under the License.
1717
package action
1818

1919
import (
20+
"fmt"
21+
"net/url"
2022
"path/filepath"
23+
"runtime"
2124
"strings"
2225

2326
"github.com/Masterminds/log-go"
27+
"github.com/pkg/errors"
2428
"gopkg.in/yaml.v2"
2529

2630
pkg "github.com/rancher-sandbox/hypper/internal/package"
@@ -167,40 +171,62 @@ func (i *Install) CreateDepRelsFromAnnot(p *pkg.Pkg,
167171
// find dependency:
168172
depChrtVer, depInRepo := repoEntries[dep.Name]
169173
if !depInRepo {
170-
// pull chart to obtain default ns
171-
log.Debugf("Dependency \"%s\" not found in repos, loading chart", dep.Name)
172-
depChart, err := i.LoadChart(dep.Name, p.ParentChartPath, dep.Repository, dep.Version, settings, logger)
174+
u, err := url.Parse(dep.Repository)
175+
var isWindowsPath bool
173176
if err != nil {
174-
return err
177+
// check if the path is a windows local path like c:\foo\bar
178+
// Is there a better way to check for this? There must be
179+
if runtime.GOOS == "windows" && strings.Contains(err.Error(), "invalid control character in URL") {
180+
isWindowsPath = true
181+
} else {
182+
// we have an invalid repository
183+
return errors.Wrap(err, fmt.Sprintf("unable to parse repository %q", dep.Repository))
184+
}
175185
}
176-
// obtain default ns and release name of dep:
177-
depNS = GetNamespaceFromAnnot(depChart.Metadata.Annotations, settings.Namespace())
178-
depRelName = GetNameFromAnnot(depChart.Metadata.Annotations, depChart.Name())
186+
// Local charts (where there is no scheme) and those specified
187+
// with the file scheme can be processed. They are local. No
188+
// dependencies will be pulled from repos not added to Hypper.
189+
// Adding a repo enables a user to opt-in for security purposes.
190+
// This is what linux system package managers do and it has been
191+
// a recommendation from security reviews for Helm.
192+
if u.Scheme == "" || u.Scheme == "file" || isWindowsPath {
193+
// pull chart to obtain default ns
194+
log.Debugf("Dependency \"%s\" not found in repos, loading chart", dep.Name)
195+
depChart, err := i.LoadChart(dep.Name, p.ParentChartPath, dep.Repository, dep.Version, settings, logger)
196+
if err != nil {
197+
return err
198+
}
199+
// obtain default ns and release name of dep:
200+
depNS = GetNamespaceFromAnnot(depChart.Metadata.Annotations, settings.Namespace())
201+
depRelName = GetNameFromAnnot(depChart.Metadata.Annotations, depChart.Name())
179202

180-
depP := pkg.NewPkg(depRelName, dep.Name, depChart.Metadata.Version, depNS,
181-
pkg.Unknown, pkg.Unknown, pkg.Unknown, dep.Repository, p.ParentChartPath)
203+
depP := pkg.NewPkg(depRelName, dep.Name, depChart.Metadata.Version, depNS,
204+
pkg.Unknown, pkg.Unknown, pkg.Unknown, dep.Repository, p.ParentChartPath)
182205

183-
if strings.HasPrefix(dep.Repository, "file://") /* depP local */ {
184-
// if depP is local, it can depend on local charts too: check recursively,
185-
// but break loops by not recurse into charts already processed.
206+
if strings.HasPrefix(dep.Repository, "file://") /* depP local */ {
207+
// if depP is local, it can depend on local charts too: check recursively,
208+
// but break loops by not recurse into charts already processed.
186209

187-
if depPinDB := pkgdb.GetPackageByFingerprint(depP.GetFingerPrint()); depPinDB == nil {
188-
// first time we process depP
210+
if depPinDB := pkgdb.GetPackageByFingerprint(depP.GetFingerPrint()); depPinDB == nil {
211+
// first time we process depP
189212

190-
// Add dep to DB, marking it as processed
191-
pkgdb.Add(depP)
213+
// Add dep to DB, marking it as processed
214+
pkgdb.Add(depP)
192215

193-
// Create depP dependency relations, and recursively add any
194-
// deps depP may have.
195-
if err := i.CreateDepRelsFromAnnot(depP, depChart.Metadata.Annotations, repoEntries,
196-
pkgdb, settings, logger); err != nil {
197-
return err
216+
// Create depP dependency relations, and recursively add any
217+
// deps depP may have.
218+
if err := i.CreateDepRelsFromAnnot(depP, depChart.Metadata.Annotations, repoEntries,
219+
pkgdb, settings, logger); err != nil {
220+
return err
221+
}
198222
}
223+
} else {
224+
// depP is not a local chart
225+
// Add dep to DB
226+
pkgdb.Add(depP)
199227
}
200228
} else {
201-
// depP is not a local chart
202-
// Add dep to DB
203-
pkgdb.Add(depP)
229+
return fmt.Errorf("unable to load dependency %q from repository %q", dep.Name, dep.Repository)
204230
}
205231

206232
} else {

0 commit comments

Comments
 (0)