Skip to content

Commit

Permalink
fix(application): use other path as chart cache path (#2317)
Browse files Browse the repository at this point in the history
Co-authored-by: xdonggao <xdonggao@tencent.com>
  • Loading branch information
GaoXiaodong and xdonggao committed Apr 25, 2024
1 parent d472c37 commit b291335
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pkg/application/controller/app/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Install(ctx context.Context,
if err != nil {
return nil, err
}
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app.Spec.Chart)
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/application/controller/app/action/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Pull(ctx context.Context,
if err != nil {
return "", err
}
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app.Spec.Chart)
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app)
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/application/controller/app/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"errors"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
applicationv1 "tkestack.io/tke/api/application/v1"
applicationversionedclient "tkestack.io/tke/api/client/clientset/versioned/typed/application/v1"
Expand Down Expand Up @@ -88,7 +89,7 @@ func Upgrade(ctx context.Context,
if err != nil {
return nil, err
}
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app.Spec.Chart)
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/application/helm/action/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package action

import (
"fmt"
"math/rand"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -58,7 +59,7 @@ func NewSettings(repoDir string) (*cli.EnvSettings, error) {
// ExpandFile expand existed file to destDir
func ExpandFile(srcFile, destDir string) (string, error) {
if srcFile != "" && file.IsFile(srcFile) {
temp, err := securejoin.SecureJoin(destDir, strconv.FormatInt(time.Now().Unix(), 10))
temp, err := securejoin.SecureJoin(destDir, strconv.FormatInt(time.Now().Unix(), 10)+"-"+fmt.Sprintf("%d", rand.Intn(1000)))
if err != nil {
return "", err
}
Expand Down
14 changes: 3 additions & 11 deletions pkg/application/registry/application/storage/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,22 +339,14 @@ func (rs *REST) getChart(ctx context.Context, app *application.App, cg *registry
}

func (rs *REST) dryRun(ctx context.Context, app *application.App) (*release.Release, error) {
chartGroup, err := rs.getChartGroup(ctx, app)
if err != nil {
appv1 := &v1.App{}
if err := v1.Convert_application_App_To_v1_App(app, appv1, nil); err != nil {
return nil, err
}
appChart, err := chartpath.FullfillChartInfo(app.Spec.Chart, chartGroup)
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(rs.repo, appv1)
if err != nil {
return nil, errors.NewInternalError(err)
}
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(rs.repo, appChart)
if err != nil {
return nil, errors.NewInternalError(err)
}
appv1 := &v1.App{}
if err := v1.Convert_application_App_To_v1_App(app, appv1, nil); err != nil {
return nil, err
}
client, err := util.NewHelmClientWithProvider(ctx, rs.platformClient, appv1)
if err != nil {
return nil, errors.NewBadRequest(err.Error())
Expand Down
11 changes: 3 additions & 8 deletions pkg/application/util/chartpath/chartpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package chartpath

import (
"tkestack.io/tke/api/application"
applicationv1 "tkestack.io/tke/api/application/v1"
v1 "tkestack.io/tke/api/application/v1"
registryv1 "tkestack.io/tke/api/registry/v1"
"tkestack.io/tke/pkg/application/config"
Expand Down Expand Up @@ -50,12 +51,6 @@ func FullfillChartInfo(appChart application.Chart, cg registryv1.ChartGroup) (ap
}

// BuildChartPathBasicOptions will judge chartgroup type and return well-structured ChartPathOptions
func BuildChartPathBasicOptions(repo config.RepoConfiguration, appChart application.Chart) (opt helmaction.ChartPathOptions, err error) {
var v1Chart = &v1.Chart{}
err = v1.Convert_application_Chart_To_v1_Chart(&appChart, v1Chart, nil)
if err != nil {
return opt, err
}

return chartpathv1.BuildChartPathBasicOptions(repo, *v1Chart)
func BuildChartPathBasicOptions(repo config.RepoConfiguration, app *applicationv1.App) (opt helmaction.ChartPathOptions, err error) {
return chartpathv1.BuildChartPathBasicOptions(repo, app)
}
5 changes: 3 additions & 2 deletions pkg/application/util/chartpath/v1/chartpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func FullfillChartInfo(appChart v1.Chart, cg registryv1.ChartGroup) (v1.Chart, e
}

// BuildChartPathBasicOptions will judge chartgroup type and return well-structured ChartPathOptions
func BuildChartPathBasicOptions(repo config.RepoConfiguration, appChart v1.Chart) (opt helmaction.ChartPathOptions, err error) {
func BuildChartPathBasicOptions(repo config.RepoConfiguration, app *v1.App) (opt helmaction.ChartPathOptions, err error) {
appChart := app.Spec.Chart
if appChart.ImportedRepo {
password, err := registryutil.VerifyDecodedPassword(appChart.RepoPassword)
if err != nil {
Expand All @@ -63,7 +64,7 @@ func BuildChartPathBasicOptions(repo config.RepoConfiguration, appChart v1.Chart
opt.Password = repo.AdminPassword
}

opt.ChartRepo = appChart.TenantID + "/" + appChart.ChartGroupName
opt.ChartRepo = appChart.TenantID + "/" + app.Spec.TargetCluster + "-" + app.Spec.TargetNamespace + "/" + appChart.ChartGroupName
opt.Chart = appChart.ChartName
opt.Version = appChart.ChartVersion
return opt, nil
Expand Down

0 comments on commit b291335

Please sign in to comment.