Skip to content

Commit 64180d0

Browse files
authored
Merge pull request #202 from nicholasSUSE/fix-multi-rcs
Fixing GenerateIndex for Multiple RCs
2 parents 83444bc + dd107f0 commit 64180d0

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

pkg/helm/helm.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func CreateOrUpdateHelmIndex(rootFs billy.Filesystem) error {
3838
return fmt.Errorf("encountered error while trying to generate new Helm index: %s", err)
3939
}
4040

41+
// Sort entries to ensure consistent ordering
42+
helmIndexFile.SortEntries()
43+
newHelmIndexFile.SortEntries()
44+
4145
// Update index
4246
helmIndexFile, upToDate := UpdateIndex(helmIndexFile, newHelmIndexFile)
4347

@@ -57,16 +61,13 @@ func CreateOrUpdateHelmIndex(rootFs billy.Filesystem) error {
5761

5862
// UpdateIndex updates the original index with the new contents
5963
func UpdateIndex(original, new *helmRepo.IndexFile) (*helmRepo.IndexFile, bool) {
60-
// Create a copy of new to return
61-
updatedIndex := helmRepo.NewIndexFile()
62-
updatedIndex.Merge(new)
63-
upToDate := true
6464

65+
upToDate := true
6566
// Preserve generated timestamp
66-
updatedIndex.Generated = original.Generated
67+
new.Generated = original.Generated
6768

6869
// Ensure newer version of chart is used if it has been updated
69-
for chartName, chartVersions := range updatedIndex.Entries {
70+
for chartName, chartVersions := range new.Entries {
7071
for i, chartVersion := range chartVersions {
7172
version := chartVersion.Version
7273
if !original.Has(chartName, version) {
@@ -86,7 +87,7 @@ func UpdateIndex(original, new *helmRepo.IndexFile) (*helmRepo.IndexFile, bool)
8687
// Try to preserve it only if nothing has changed.
8788
if originalChartVersion.Digest == chartVersion.Digest {
8889
// Don't modify created timestamp
89-
updatedIndex.Entries[chartName][i].Created = originalChartVersion.Created
90+
new.Entries[chartName][i].Created = originalChartVersion.Created
9091
} else {
9192
upToDate = false
9293
logrus.Debugf("Chart %s at version %s has been modified", chartName, originalChartVersion.Version)
@@ -96,7 +97,7 @@ func UpdateIndex(original, new *helmRepo.IndexFile) (*helmRepo.IndexFile, bool)
9697

9798
for chartName, chartVersions := range original.Entries {
9899
for _, chartVersion := range chartVersions {
99-
if !updatedIndex.Has(chartName, chartVersion.Version) {
100+
if !new.Has(chartName, chartVersion.Version) {
100101
// Chart was removed
101102
upToDate = false
102103
logrus.Debugf("Chart %s at version %s has been removed: %v", chartName, chartVersion.Version, *chartVersion)
@@ -105,9 +106,9 @@ func UpdateIndex(original, new *helmRepo.IndexFile) (*helmRepo.IndexFile, bool)
105106
}
106107
}
107108

108-
// Sort and return entries
109-
updatedIndex.SortEntries()
110-
return updatedIndex, upToDate
109+
// Sort one more time for safety
110+
new.SortEntries()
111+
return new, upToDate
111112
}
112113

113114
// OpenIndexYaml will check and open the index.yaml file in the local repository at the default file path

0 commit comments

Comments
 (0)