From 6c1248283363e0ba1b5c242e1d538b3880fc5f55 Mon Sep 17 00:00:00 2001 From: "Xiaolei.Liang" Date: Wed, 31 Jan 2024 09:39:36 +0800 Subject: [PATCH 1/3] 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 */ || From 934bb33d81da4cbaf89c492eb813dfa3aa5ece5a Mon Sep 17 00:00:00 2001 From: liangxiaolei5 Date: Wed, 31 Jan 2024 09:51:39 +0800 Subject: [PATCH 2/3] fix: import package fix Signed-off-by: liangxiaolei5 --- pkg/chartmuseum/server/multitenant/index.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/chartmuseum/server/multitenant/index.go b/pkg/chartmuseum/server/multitenant/index.go index fe3dba6e..f89777d8 100644 --- a/pkg/chartmuseum/server/multitenant/index.go +++ b/pkg/chartmuseum/server/multitenant/index.go @@ -51,7 +51,7 @@ func (server *MultiTenantServer) getIndexFile(log cm_logger.LoggingFn, repo stri 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{} + entry.RepoIndex.Entries = map[string]cm_repo.ChartVersions{} server.CacheInterval = 0 } } From ebf43afe3d73dc9b6e34afe6306d34a0e1abca0e Mon Sep 17 00:00:00 2001 From: liangxiaolei5 Date: Wed, 31 Jan 2024 09:56:30 +0800 Subject: [PATCH 3/3] fix: package import error fix Signed-off-by: liangxiaolei5 --- pkg/chartmuseum/server/multitenant/index.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/chartmuseum/server/multitenant/index.go b/pkg/chartmuseum/server/multitenant/index.go index f89777d8..e327a6af 100644 --- a/pkg/chartmuseum/server/multitenant/index.go +++ b/pkg/chartmuseum/server/multitenant/index.go @@ -24,6 +24,7 @@ import ( cm_logger "helm.sh/chartmuseum/pkg/chartmuseum/logger" cm_repo "helm.sh/chartmuseum/pkg/repo" + repo2 "helm.sh/helm/v3/pkg/repo" ) const ( @@ -51,7 +52,7 @@ func (server *MultiTenantServer) getIndexFile(log cm_logger.LoggingFn, repo stri 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]cm_repo.ChartVersions{} + entry.RepoIndex.Entries = map[string]repo2.ChartVersions{} server.CacheInterval = 0 } }