Skip to content

Commit

Permalink
* [fix] imp upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ysicing committed Oct 12, 2024
1 parent c63f5fc commit 2c16fa1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/cli/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/tool/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions internal/pkg/util/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
15 changes: 7 additions & 8 deletions pkg/qucheng/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand All @@ -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,
Expand All @@ -134,17 +132,18 @@ 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, ""))
if newProduct != product.(string) {
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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/quickon/quickon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 2c16fa1

Please sign in to comment.