Commit e74772f1 authored by Matt Butcher's avatar Matt Butcher Committed by GitHub

Merge pull request #2021 from technosophos/feat/2019-dep-up-skip-refresh

feat(helm): add --skip-refresh flag to 'helm dep up'
parents 12478308 f7b010a1
...@@ -46,6 +46,7 @@ type dependencyUpdateCmd struct { ...@@ -46,6 +46,7 @@ type dependencyUpdateCmd struct {
helmhome helmpath.Home helmhome helmpath.Home
verify bool verify bool
keyring string keyring string
skipRefresh bool
} }
// newDependencyUpdateCmd creates a new dependency update command. // newDependencyUpdateCmd creates a new dependency update command.
...@@ -80,6 +81,7 @@ func newDependencyUpdateCmd(out io.Writer) *cobra.Command { ...@@ -80,6 +81,7 @@ func newDependencyUpdateCmd(out io.Writer) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.BoolVar(&duc.verify, "verify", false, "verify the packages against signatures") f.BoolVar(&duc.verify, "verify", false, "verify the packages against signatures")
f.StringVar(&duc.keyring, "keyring", defaultKeyring(), "keyring containing public keys") f.StringVar(&duc.keyring, "keyring", defaultKeyring(), "keyring containing public keys")
f.BoolVar(&duc.skipRefresh, "skip-refresh", false, "do not refresh the local repository cache")
return cmd return cmd
} }
...@@ -91,6 +93,7 @@ func (d *dependencyUpdateCmd) run() error { ...@@ -91,6 +93,7 @@ func (d *dependencyUpdateCmd) run() error {
ChartPath: d.chartpath, ChartPath: d.chartpath,
HelmHome: d.helmhome, HelmHome: d.helmhome,
Keyring: d.keyring, Keyring: d.keyring,
SkipUpdate: d.skipRefresh,
} }
if d.verify { if d.verify {
man.Verify = downloader.VerifyIfPossible man.Verify = downloader.VerifyIfPossible
......
...@@ -128,6 +128,50 @@ func TestDependencyUpdateCmd(t *testing.T) { ...@@ -128,6 +128,50 @@ func TestDependencyUpdateCmd(t *testing.T) {
} }
} }
func TestDependencyUpdateCmd_SkipRefresh(t *testing.T) {
// Set up a testing helm home
oldhome := helmHome
hh, err := tempHelmHome(t)
if err != nil {
t.Fatal(err)
}
helmHome = hh
defer func() {
os.RemoveAll(hh)
helmHome = oldhome
}()
srv := repotest.NewServer(hh)
defer srv.Stop()
copied, err := srv.CopyCharts("testdata/testcharts/*.tgz")
if err != nil {
t.Fatal(err)
}
t.Logf("Copied charts:\n%s", strings.Join(copied, "\n"))
t.Logf("Listening on directory %s", srv.Root())
chartname := "depup"
if err := createTestingChart(hh, chartname, srv.URL()); err != nil {
t.Fatal(err)
}
out := bytes.NewBuffer(nil)
duc := &dependencyUpdateCmd{out: out}
duc.helmhome = helmpath.Home(hh)
duc.chartpath = filepath.Join(hh, chartname)
duc.skipRefresh = true
if err := duc.run(); err == nil {
t.Fatal("Expected failure to find the repo with skipRefresh")
}
output := out.String()
// This is written directly to stdout, so we have to capture as is.
if strings.Contains(output, `update from the "test" chart repository`) {
t.Errorf("Repo was unexpectedly updated\n%s", output)
}
}
// createTestingChart creates a basic chart that depends on reqtest-0.1.0 // createTestingChart creates a basic chart that depends on reqtest-0.1.0
// //
// The baseURL can be used to point to a particular repository server. // The baseURL can be used to point to a particular repository server.
......
...@@ -53,11 +53,15 @@ type Manager struct { ...@@ -53,11 +53,15 @@ type Manager struct {
Verify VerificationStrategy Verify VerificationStrategy
// Keyring is the key ring file. // Keyring is the key ring file.
Keyring string Keyring string
// SkipUpdate indicates that the repository should not be updated first.
SkipUpdate bool
} }
// Build rebuilds a local charts directory from a lockfile. // Build rebuilds a local charts directory from a lockfile.
// //
// If the lockfile is not present, this will run a Manager.Update() // If the lockfile is not present, this will run a Manager.Update()
//
// If SkipUpdate is set, this will not update the repository.
func (m *Manager) Build() error { func (m *Manager) Build() error {
c, err := m.loadChartDir() c, err := m.loadChartDir()
if err != nil { if err != nil {
...@@ -85,10 +89,12 @@ func (m *Manager) Build() error { ...@@ -85,10 +89,12 @@ func (m *Manager) Build() error {
return err return err
} }
if !m.SkipUpdate {
// For each repo in the file, update the cached copy of that repo // For each repo in the file, update the cached copy of that repo
if err := m.UpdateRepositories(); err != nil { if err := m.UpdateRepositories(); err != nil {
return err return err
} }
}
// Now we need to fetch every package here into charts/ // Now we need to fetch every package here into charts/
if err := m.downloadAll(lock.Dependencies); err != nil { if err := m.downloadAll(lock.Dependencies); err != nil {
...@@ -102,7 +108,7 @@ func (m *Manager) Build() error { ...@@ -102,7 +108,7 @@ func (m *Manager) Build() error {
// //
// It first reads the requirements.yaml file, and then attempts to // It first reads the requirements.yaml file, and then attempts to
// negotiate versions based on that. It will download the versions // negotiate versions based on that. It will download the versions
// from remote chart repositories. // from remote chart repositories unless SkipUpdate is true.
func (m *Manager) Update() error { func (m *Manager) Update() error {
c, err := m.loadChartDir() c, err := m.loadChartDir()
if err != nil { if err != nil {
...@@ -127,9 +133,11 @@ func (m *Manager) Update() error { ...@@ -127,9 +133,11 @@ func (m *Manager) Update() error {
} }
// For each repo in the file, update the cached copy of that repo // For each repo in the file, update the cached copy of that repo
if !m.SkipUpdate {
if err := m.UpdateRepositories(); err != nil { if err := m.UpdateRepositories(); err != nil {
return err return err
} }
}
// Now we need to find out which version of a chart best satisfies the // Now we need to find out which version of a chart best satisfies the
// requirements the requirements.yaml // requirements the requirements.yaml
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment