From d619aaf2c556490751ca48ab3b3448fb0683bc03 Mon Sep 17 00:00:00 2001 From: Patrick Zhao Date: Wed, 12 Feb 2025 10:05:15 +0800 Subject: [PATCH] fix helm chart download conflict Signed-off-by: Patrick Zhao --- .../aslan/core/common/service/kube/helm.go | 11 +++++++++++ pkg/tool/helmclient/helmclient.go | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/pkg/microservice/aslan/core/common/service/kube/helm.go b/pkg/microservice/aslan/core/common/service/kube/helm.go index 771f8f15b9..5fadddf913 100644 --- a/pkg/microservice/aslan/core/common/service/kube/helm.go +++ b/pkg/microservice/aslan/core/common/service/kube/helm.go @@ -590,6 +590,10 @@ func DeploySingleHelmRelease(product *commonmodels.Product, productSvc *commonmo chartRef := fmt.Sprintf("%s/%s", chartInfo.ChartRepo, chartInfo.ChartName) localPath := config.LocalServicePathWithRevision(product.ProductName, releaseName, chartInfo.ChartVersion, product.Production) + + mutex := cache.NewRedisLockWithExpiry(fmt.Sprintf("helm_chart_download:%s", localPath), time.Minute*1) + mutex.Lock() + defer mutex.Unlock() // remove local file to untar _ = os.RemoveAll(localPath) @@ -601,6 +605,7 @@ func DeploySingleHelmRelease(product *commonmodels.Product, productSvc *commonmo if err != nil { return fmt.Errorf("failed to download chart, chartName: %s, chartRepo: %+v, err: %s", chartInfo.ChartName, chartRepo.RepoName, err) } + mutex.Unlock() } helmClient, err := helmtool.NewClientFromNamespace(product.ClusterID, product.Namespace) @@ -690,6 +695,11 @@ func DeployMultiHelmRelease(productResp *commonmodels.Product, helmClient *helmt chartRef := fmt.Sprintf("%s/%s", param.RenderChart.ChartRepo, param.RenderChart.ChartName) localPath := config.LocalServicePathWithRevision(param.ProductName, param.ReleaseName, param.RenderChart.ChartVersion, param.Production) + + mutex := cache.NewRedisLockWithExpiry(fmt.Sprintf("helm_chart_download:%s", localPath), time.Minute*1) + mutex.Lock() + defer mutex.Unlock() + // remove local file to untar _ = os.RemoveAll(localPath) @@ -702,6 +712,7 @@ func DeployMultiHelmRelease(productResp *commonmodels.Product, helmClient *helmt if err != nil { return fmt.Errorf("failed to download chart, chartName: %s, chartRepo: %+v, err: %s", param.RenderChart.ChartName, chartRepo.RepoName, err) } + mutex.Unlock() } errInstall := InstallOrUpgradeHelmChartWithValues(param, isRetry, helmClient) diff --git a/pkg/tool/helmclient/helmclient.go b/pkg/tool/helmclient/helmclient.go index ba657a5726..b02e01512d 100644 --- a/pkg/tool/helmclient/helmclient.go +++ b/pkg/tool/helmclient/helmclient.go @@ -958,6 +958,9 @@ func (hClient *HelmClient) GetChartValues(repoEntry *repo.Entry, projectName, re lock.Lock() defer lock.Unlock() + mutex := cache.NewRedisLockWithExpiry(fmt.Sprintf("helm_chart_download:%s", localPath), time.Minute*1) + mutex.Lock() + defer mutex.Unlock() // remove local file to untar _ = os.RemoveAll(localPath) @@ -965,6 +968,7 @@ func (hClient *HelmClient) GetChartValues(repoEntry *repo.Entry, projectName, re if err != nil { return "", fmt.Errorf("failed to download chart, chartName: %s, chartRepo: %+v, err: %s", chartName, repoEntry.Name, err) } + mutex.Unlock() fsTree := os.DirFS(localPath) valuesYAML, err := util.ReadValuesYAML(fsTree, chartName, log.SugaredLogger())