Skip to content

Commit b291335

Browse files
GaoXiaodongxdonggao
and
xdonggao
authored
fix(application): use other path as chart cache path (#2317)
Co-authored-by: xdonggao <[email protected]>
1 parent d472c37 commit b291335

File tree

7 files changed

+15
-25
lines changed

7 files changed

+15
-25
lines changed

pkg/application/controller/app/action/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func Install(ctx context.Context,
8888
if err != nil {
8989
return nil, err
9090
}
91-
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app.Spec.Chart)
91+
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app)
9292
if err != nil {
9393
return nil, err
9494
}

pkg/application/controller/app/action/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func Pull(ctx context.Context,
4242
if err != nil {
4343
return "", err
4444
}
45-
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app.Spec.Chart)
45+
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app)
4646
if err != nil {
4747
return "", err
4848
}

pkg/application/controller/app/action/upgrade.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"context"
2323
"errors"
2424
"fmt"
25+
2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
applicationv1 "tkestack.io/tke/api/application/v1"
2728
applicationversionedclient "tkestack.io/tke/api/client/clientset/versioned/typed/application/v1"
@@ -88,7 +89,7 @@ func Upgrade(ctx context.Context,
8889
if err != nil {
8990
return nil, err
9091
}
91-
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app.Spec.Chart)
92+
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(repo, app)
9293
if err != nil {
9394
return nil, err
9495
}

pkg/application/helm/action/setting.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package action
2020

2121
import (
2222
"fmt"
23+
"math/rand"
2324
"strconv"
2425
"strings"
2526
"time"
@@ -58,7 +59,7 @@ func NewSettings(repoDir string) (*cli.EnvSettings, error) {
5859
// ExpandFile expand existed file to destDir
5960
func ExpandFile(srcFile, destDir string) (string, error) {
6061
if srcFile != "" && file.IsFile(srcFile) {
61-
temp, err := securejoin.SecureJoin(destDir, strconv.FormatInt(time.Now().Unix(), 10))
62+
temp, err := securejoin.SecureJoin(destDir, strconv.FormatInt(time.Now().Unix(), 10)+"-"+fmt.Sprintf("%d", rand.Intn(1000)))
6263
if err != nil {
6364
return "", err
6465
}

pkg/application/registry/application/storage/rest.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,22 +339,14 @@ func (rs *REST) getChart(ctx context.Context, app *application.App, cg *registry
339339
}
340340

341341
func (rs *REST) dryRun(ctx context.Context, app *application.App) (*release.Release, error) {
342-
chartGroup, err := rs.getChartGroup(ctx, app)
343-
if err != nil {
342+
appv1 := &v1.App{}
343+
if err := v1.Convert_application_App_To_v1_App(app, appv1, nil); err != nil {
344344
return nil, err
345345
}
346-
appChart, err := chartpath.FullfillChartInfo(app.Spec.Chart, chartGroup)
346+
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(rs.repo, appv1)
347347
if err != nil {
348348
return nil, errors.NewInternalError(err)
349349
}
350-
chartPathBasicOptions, err := chartpath.BuildChartPathBasicOptions(rs.repo, appChart)
351-
if err != nil {
352-
return nil, errors.NewInternalError(err)
353-
}
354-
appv1 := &v1.App{}
355-
if err := v1.Convert_application_App_To_v1_App(app, appv1, nil); err != nil {
356-
return nil, err
357-
}
358350
client, err := util.NewHelmClientWithProvider(ctx, rs.platformClient, appv1)
359351
if err != nil {
360352
return nil, errors.NewBadRequest(err.Error())

pkg/application/util/chartpath/chartpath.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package chartpath
2020

2121
import (
2222
"tkestack.io/tke/api/application"
23+
applicationv1 "tkestack.io/tke/api/application/v1"
2324
v1 "tkestack.io/tke/api/application/v1"
2425
registryv1 "tkestack.io/tke/api/registry/v1"
2526
"tkestack.io/tke/pkg/application/config"
@@ -50,12 +51,6 @@ func FullfillChartInfo(appChart application.Chart, cg registryv1.ChartGroup) (ap
5051
}
5152

5253
// BuildChartPathBasicOptions will judge chartgroup type and return well-structured ChartPathOptions
53-
func BuildChartPathBasicOptions(repo config.RepoConfiguration, appChart application.Chart) (opt helmaction.ChartPathOptions, err error) {
54-
var v1Chart = &v1.Chart{}
55-
err = v1.Convert_application_Chart_To_v1_Chart(&appChart, v1Chart, nil)
56-
if err != nil {
57-
return opt, err
58-
}
59-
60-
return chartpathv1.BuildChartPathBasicOptions(repo, *v1Chart)
54+
func BuildChartPathBasicOptions(repo config.RepoConfiguration, app *applicationv1.App) (opt helmaction.ChartPathOptions, err error) {
55+
return chartpathv1.BuildChartPathBasicOptions(repo, app)
6156
}

pkg/application/util/chartpath/v1/chartpath.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ func FullfillChartInfo(appChart v1.Chart, cg registryv1.ChartGroup) (v1.Chart, e
4141
}
4242

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

66-
opt.ChartRepo = appChart.TenantID + "/" + appChart.ChartGroupName
67+
opt.ChartRepo = appChart.TenantID + "/" + app.Spec.TargetCluster + "-" + app.Spec.TargetNamespace + "/" + appChart.ChartGroupName
6768
opt.Chart = appChart.ChartName
6869
opt.Version = appChart.ChartVersion
6970
return opt, nil

0 commit comments

Comments
 (0)