Skip to content

Commit

Permalink
fix(helm-dependencies): enable loading of .helm/charts/CHART-VERSION.…
Browse files Browse the repository at this point in the history
…tgz charts

Do not download into ~/.werf/local_cache those dependencies charts which are listed in the .helm/Chart.lock and already exists in the .helm/charts directory.

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Feb 17, 2023
1 parent db98b29 commit 3addc23
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions pkg/deploy/helm/chart_extender/chart_dependencies_loader.go
Expand Up @@ -120,7 +120,7 @@ func NewChartDependenciesConfiguration(chartMetadata *chart.Metadata, chartMetad
return &ChartDependenciesConfiguration{ChartMetadata: chartMetadata, ChartMetadataLock: chartMetadataLock}
}

func (conf *ChartDependenciesConfiguration) GetExternalDependenciesFiles() (bool, *chart.ChartExtenderBufferedFile, *chart.ChartExtenderBufferedFile, error) {
func (conf *ChartDependenciesConfiguration) GetExternalDependenciesFiles(loadedChartFiles []*chart.ChartExtenderBufferedFile) (bool, *chart.ChartExtenderBufferedFile, *chart.ChartExtenderBufferedFile, error) {
metadataBytes, err := yaml.Marshal(conf.ChartMetadata)
if err != nil {
return false, nil, nil, fmt.Errorf("unable to marshal original chart metadata into yaml: %w", err)
Expand All @@ -141,28 +141,46 @@ func (conf *ChartDependenciesConfiguration) GetExternalDependenciesFiles() (bool

metadata.APIVersion = "v2"

var localDependenciesNames []string
var externalDependenciesNames []string
var isExternalDependency = func(depName string) bool {
for _, externalDepName := range externalDependenciesNames {
if depName == externalDepName {
return true
}
}
return false
}

var filteredLockDependencies []*chart.Dependency
FindExternalDependencies:
for _, depLock := range metadataLock.Dependencies {
if depLock.Repository == "" || strings.HasPrefix(depLock.Repository, "file://") {
localDependenciesNames = append(localDependenciesNames, depLock.Name)
continue
}
filteredLockDependencies = append(filteredLockDependencies, depLock)

for _, loadedFile := range loadedChartFiles {
if strings.HasPrefix(loadedFile.Name, "charts/") {
if filepath.Base(loadedFile.Name) == fmt.Sprintf("%s-%s.tgz", depLock.Name, depLock.Version) {
continue FindExternalDependencies
}
}
}

externalDependenciesNames = append(externalDependenciesNames, depLock.Name)
}

var filteredLockDependencies []*chart.Dependency
for _, depLock := range metadataLock.Dependencies {
if isExternalDependency(depLock.Name) {
filteredLockDependencies = append(filteredLockDependencies, depLock)
}
}
metadataLock.Dependencies = filteredLockDependencies

var filteredDependencies []*chart.Dependency
FilterOutLocalDependencies:
for _, dep := range metadata.Dependencies {
for _, localDepName := range localDependenciesNames {
if localDepName == dep.Name {
continue FilterOutLocalDependencies
}
if isExternalDependency(dep.Name) {
filteredDependencies = append(filteredDependencies, dep)
}

filteredDependencies = append(filteredDependencies, dep)
}
metadata.Dependencies = filteredDependencies

Expand Down Expand Up @@ -288,11 +306,10 @@ func LoadChartDependencies(ctx context.Context, loadChartDirFunc func(ctx contex
res = append(res, chartFiles...)
}

haveExternalDependencies, metadataFile, metadataLockFile, err := conf.GetExternalDependenciesFiles()
haveExternalDependencies, metadataFile, metadataLockFile, err := conf.GetExternalDependenciesFiles(loadedChartFiles)
if err != nil {
return nil, fmt.Errorf("unable to get external dependencies chart configuration files: %w", err)
}

if !haveExternalDependencies {
return res, nil
}
Expand Down

0 comments on commit 3addc23

Please sign in to comment.