Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(application): use other path as chart cache path #2317

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分不需要了吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要了,这部分转化就是为了构建后面的path,用不到了

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{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

54部分需要去掉吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去掉了,这部分就是为了构建后面的path,用不到了

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里使用 appChart.ChartName 是否更好。ChartGroupName 都是local

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后面解压缩的时候,会用chart的名字做为文件夹的名字的

opt.Chart = appChart.ChartName
opt.Version = appChart.ChartVersion
return opt, nil
Expand Down
Loading