From 0cf7b19b216ccc17314dccb9a0d1322f4bfe1983 Mon Sep 17 00:00:00 2001 From: Suleiman Dibirov Date: Sat, 10 Aug 2024 08:20:24 +0300 Subject: [PATCH] feat(dependency): Add --skip-download-if-exists into dependency build/update Signed-off-by: Suleiman Dibirov --- pkg/action/dependency.go | 1 + pkg/cmd/dependency.go | 1 + pkg/cmd/dependency_build.go | 1 + pkg/cmd/dependency_update.go | 1 + pkg/downloader/manager.go | 10 ++++++++++ 5 files changed, 14 insertions(+) diff --git a/pkg/action/dependency.go b/pkg/action/dependency.go index 03c370c8e..82b69b676 100644 --- a/pkg/action/dependency.go +++ b/pkg/action/dependency.go @@ -37,6 +37,7 @@ type Dependency struct { Verify bool Keyring string SkipRefresh bool + SkipDownloadIfExists bool ColumnWidth uint Username string Password string diff --git a/pkg/cmd/dependency.go b/pkg/cmd/dependency.go index 34bbff6be..587b16dc7 100644 --- a/pkg/cmd/dependency.go +++ b/pkg/cmd/dependency.go @@ -133,4 +133,5 @@ func addDependencySubcommandFlags(f *pflag.FlagSet, client *action.Dependency) { f.BoolVar(&client.InsecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the chart download") f.BoolVar(&client.PlainHTTP, "plain-http", false, "use insecure HTTP connections for the chart download") f.StringVar(&client.CaFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle") + f.BoolVar(&client.SkipDownloadIfExists, "skip-download-if-exists", false, "skip download of the chart if it already exists in the charts directory") } diff --git a/pkg/cmd/dependency_build.go b/pkg/cmd/dependency_build.go index 320fe12ae..08075845e 100644 --- a/pkg/cmd/dependency_build.go +++ b/pkg/cmd/dependency_build.go @@ -65,6 +65,7 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command { ChartPath: chartpath, Keyring: client.Keyring, SkipUpdate: client.SkipRefresh, + SkipDownloadIfExists: client.SkipDownloadIfExists, Getters: getter.All(settings), RegistryClient: registryClient, RepositoryConfig: settings.RepositoryConfig, diff --git a/pkg/cmd/dependency_update.go b/pkg/cmd/dependency_update.go index b534fb48a..714893ea1 100644 --- a/pkg/cmd/dependency_update.go +++ b/pkg/cmd/dependency_update.go @@ -69,6 +69,7 @@ func newDependencyUpdateCmd(_ *action.Configuration, out io.Writer) *cobra.Comma ChartPath: chartpath, Keyring: client.Keyring, SkipUpdate: client.SkipRefresh, + SkipDownloadIfExists: client.SkipDownloadIfExists, Getters: getter.All(settings), RegistryClient: registryClient, RepositoryConfig: settings.RepositoryConfig, diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index d41b8fdb4..3bb776473 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -70,6 +70,8 @@ type Manager struct { Keyring string // SkipUpdate indicates that the repository should not be updated first. SkipUpdate bool + // SkipDownloadIfExists indicates that the chart should not be downloaded if it already exists. + SkipDownloadIfExists bool // Getter collection for the operation Getters []getter.Provider RegistryClient *registry.Client @@ -326,6 +328,14 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error { continue } + if m.SkipDownloadIfExists { + name := filepath.Base(churl) + if _, err = os.Stat(filepath.Join(destPath, name)); err == nil { + fmt.Fprintf(m.Out, "Already exists locally %s from repo %s\n", dep.Name, dep.Repository) + continue + } + } + fmt.Fprintf(m.Out, "Downloading %s from repo %s\n", dep.Name, dep.Repository) dl := ChartDownloader{