From 2c16fa153c3aef76b413727339e796dadd2d4afd Mon Sep 17 00:00:00 2001 From: ysicing Date: Sat, 12 Oct 2024 12:57:13 +0800 Subject: [PATCH] * [fix] imp upgrade --- internal/pkg/cli/helm/helm.go | 2 +- internal/pkg/cli/tool/domain.go | 2 +- internal/pkg/util/helm/helm.go | 12 +++++++----- pkg/qucheng/upgrade/upgrade.go | 15 +++++++-------- pkg/quickon/quickon.go | 10 +++++----- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/internal/pkg/cli/helm/helm.go b/internal/pkg/cli/helm/helm.go index f1e104fe..b30d01bb 100644 --- a/internal/pkg/cli/helm/helm.go +++ b/internal/pkg/cli/helm/helm.go @@ -194,7 +194,7 @@ func chartUpgrade(f factory.Factory) *cobra.Command { return errors.Errorf("helm create go client err: %v", err) } values, _ := exhelm.MergeValues(p) - _, err = hc.Upgrade(name, repoName, chartName, chartVersion, values) + _, err = hc.Upgrade(name, repoName, chartName, chartVersion, values, true) return err }, } diff --git a/internal/pkg/cli/tool/domain.go b/internal/pkg/cli/tool/domain.go index 258c4ee1..95f0dbde 100644 --- a/internal/pkg/cli/tool/domain.go +++ b/internal/pkg/cli/tool/domain.go @@ -151,7 +151,7 @@ func domainAdd(f factory.Factory) *cobra.Command { strvals.ParseInto(value, base) } defaultValue = exmap.MergeMaps(defaultValue, base) - if _, err := helmClient.Upgrade(common.DefaultQuchengName, common.DefaultHelmRepoName, common.DefaultQuchengName, "", defaultValue); err != nil { + if _, err := helmClient.Upgrade(common.DefaultQuchengName, common.DefaultHelmRepoName, common.DefaultQuchengName, "", defaultValue, false); err != nil { log.Warnf("upgrade %s failed, reason: %v", common.DefaultQuchengName, err) } else { log.Donef("upgrade %s success", common.DefaultQuchengName) diff --git a/internal/pkg/util/helm/helm.go b/internal/pkg/util/helm/helm.go index 04cf0233..c3e71124 100644 --- a/internal/pkg/util/helm/helm.go +++ b/internal/pkg/util/helm/helm.go @@ -103,7 +103,7 @@ func (c Client) GetDetail(name string) (*release.Release, error) { return result, nil } -func (c Client) Upgrade(name, repoName, chartName, chartVersion string, values map[string]interface{}) (*release.Release, error) { +func (c Client) Upgrade(name, repoName, chartName, chartVersion string, values map[string]interface{}, fetch bool) (*release.Release, error) { repos, err := c.ListRepo() if err != nil { return nil, err @@ -148,11 +148,13 @@ func (c Client) Upgrade(name, repoName, chartName, chartVersion string, values m if err != nil { return nil, errors.Wrap(err, fmt.Sprintf("load chart %s failed: %v", chartName, err)) } - releaseValue, err := c.GetDetail(name) - if err != nil { - return nil, errors.Errorf("fetch %s chart release value failed, %v", name, err) + if fetch { + releaseValue, err := c.GetDetail(name) + if err != nil { + return nil, errors.Errorf("fetch %s chart release value failed, %v", name, err) + } + values = MergeMaps(releaseValue.Config, values) } - values = MergeMaps(releaseValue.Config, values) release, err := client.Run(name, ct, values) if err != nil { return release, errors.Wrap(err, fmt.Sprintf("upgrade tool %s with chart %s failed: %v", name, chartName, err)) diff --git a/pkg/qucheng/upgrade/upgrade.go b/pkg/qucheng/upgrade/upgrade.go index a90418cc..f0353c34 100644 --- a/pkg/qucheng/upgrade/upgrade.go +++ b/pkg/qucheng/upgrade/upgrade.go @@ -110,8 +110,6 @@ func Upgrade(flagVersion string, testmode bool, log log.Logger) error { if devops && cv.Name == common.DefaultZentaoPaasName { deploy := defaultValue["deploy"] product := deploy.(map[string]interface{})["product"] - versions := deploy.(map[string]interface{})["versions"] - appoldVersion := versions.(map[string]interface{})[product.(string)] switch product { case common.ZenTaoBizType.String(): selectItems = selectItems[1:] @@ -120,7 +118,7 @@ func Upgrade(flagVersion string, testmode bool, log log.Logger) error { case common.ZenTaoIPDType.String(): selectItems = selectItems[3:] } - log.Infof("current version: %v(%v)", product, appoldVersion) + log.Infof("current version: %v", product) selectApp := promptui.Select{ Label: "select upgrade version", Items: selectItems, @@ -134,7 +132,6 @@ func Upgrade(flagVersion string, testmode bool, log log.Logger) error { } it, _, _ := selectApp.Run() newProduct := selectItems[it].Key.String() - defaultValue["deploy"].(map[string]interface{})["product"] = newProduct appnewVersion := common.GetVersion(true, newProduct, "") if !(selectItems[it].Key == common.ZenTaoOSSType || selectItems[it].Key == common.ZenTaoOldOSSType) { appnewVersion = fmt.Sprintf("%s%s.k8s", newProduct, common.GetVersion(true, newProduct, "")) @@ -142,9 +139,11 @@ func Upgrade(flagVersion string, testmode bool, log log.Logger) error { log.Warn("切换版本升级(如开源版升级到企业版), 可能导致因版本授权问题无法正常使用, 如有问题请联系技术支持!") } } - defaultValue["deploy"].(map[string]interface{})["versions"].(map[string]interface{})[product.(string)] = appnewVersion - log.Infof("devops mode, product: %v, oldversion: %v, newversion: %v", product, appoldVersion, appnewVersion) - msg := fmt.Sprintf("Are you sure to upgrade from %v(%v) to %v(%v)", product, appoldVersion, selectItems[it].Key.String(), appnewVersion) + defaultValue["deploy"] = map[string]any{ + "product": newProduct, + } + log.Debugf("devops mode, product: %v, version: %v", product, appnewVersion) + msg := fmt.Sprintf("Are you sure to upgrade to %v(%v)", selectItems[it].Key.String(), appnewVersion) status, _ := confirm.Confirm(msg) if !status { log.Warnf("upgrade %s canceled", cv.Name) @@ -156,7 +155,7 @@ func Upgrade(flagVersion string, testmode bool, log log.Logger) error { } } } - if _, err := helmClient.Upgrade(cv.Name, common.DefaultHelmRepoName, cv.Name, "", defaultValue); err != nil { + if _, err := helmClient.Upgrade(cv.Name, common.DefaultHelmRepoName, cv.Name, "", defaultValue, false); err != nil { log.Warnf("upgrade %s failed, reason: %v", cv.Name, err) } else { log.Donef("upgrade %s success", cv.Name) diff --git a/pkg/quickon/quickon.go b/pkg/quickon/quickon.go index 374834ac..4028fa03 100644 --- a/pkg/quickon/quickon.go +++ b/pkg/quickon/quickon.go @@ -362,11 +362,11 @@ func (m *Meta) Init() error { if m.DevopsMode { // 指定类型 helmargs = append(helmargs, "--set", fmt.Sprintf("deploy.product=%s", m.Type)) - deployVersion := fmt.Sprintf("deploy.versions.%s=%s%s.k8s", m.Type, m.Type, installVersion) - if m.Type == common.ZenTaoOSSType.String() { - deployVersion = fmt.Sprintf("deploy.versions.%s=%s", m.Type, installVersion) - } - helmargs = append(helmargs, "--set", deployVersion) + // deployVersion := fmt.Sprintf("deploy.versions.%s=%s%s.k8s", m.Type, m.Type, installVersion) + // if m.Type == common.ZenTaoOSSType.String() { + // deployVersion = fmt.Sprintf("deploy.versions.%s=%s", m.Type, installVersion) + // } + // helmargs = append(helmargs, "--set", deployVersion) if helmchan != "stable" { helmargs = append(helmargs, "--set", "image.repository=test/zentao") }