From 6c1248283363e0ba1b5c242e1d538b3880fc5f55 Mon Sep 17 00:00:00 2001 From: "Xiaolei.Liang" Date: Wed, 31 Jan 2024 09:39:36 +0800 Subject: [PATCH] Update index.go the chartversions of index.yaml should be equal to the length of chartversion objects in storage backend. if not equal, we should regenerate the index.yaml. Signed-off-by: Xiaolei.Liang Signed-off-by: liangxiaolei5 --- pkg/chartmuseum/server/multitenant/index.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/chartmuseum/server/multitenant/index.go b/pkg/chartmuseum/server/multitenant/index.go index 009cfb71..fe3dba6e 100644 --- a/pkg/chartmuseum/server/multitenant/index.go +++ b/pkg/chartmuseum/server/multitenant/index.go @@ -42,6 +42,20 @@ func (server *MultiTenantServer) getIndexFile(log cm_logger.LoggingFn, repo stri entry.RepoLock.Lock() defer entry.RepoLock.Unlock() + allChartsCount := 0 + if len(entry.RepoIndex.Entries) != 0 || server.CacheInterval != 0 { + for _, chVersions := range entry.RepoIndex.Entries { + allChartsCount += len(chVersions) + } + } + if len(entry.RepoIndex.Entries) != 0 || server.CacheInterval != 0 { + allObjects, err := server.fetchChartsInStorage(log, repo) + if err != nil || allChartsCount != len(allObjects) { + entry.RepoIndex.Entries = map[string]repo.ChartVersions{} + server.CacheInterval = 0 + } + } + // if the always-regenerate-chart-index flag is set, we always update the index file // and ignore the chart cache if server.AlwaysRegenerateIndex /* the flag is set */ ||