Skip to content

Commit

Permalink
fix helm chart download conflict
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zhao <[email protected]>
  • Loading branch information
PetrusZ committed Feb 12, 2025
1 parent bf8c443 commit d619aaf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/microservice/aslan/core/common/service/kube/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/tool/helmclient/helmclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,13 +958,17 @@ 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)

err := hClient.DownloadChart(repoEntry, chartRef, chartVersion, localPath, true)
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())
Expand Down

0 comments on commit d619aaf

Please sign in to comment.