Skip to content

Commit 67442c3

Browse files
committed
feat: refactor channel handling and improve logging practices
- Simplify logic in the GetChannel function by returning directly based on the condition. - Introduce a new function, NeedUseCustomVersion, for determining if a custom version is needed. - Adjust logging to use the retrieved channel directly instead of calling GetChannel multiple times. - Remove unnecessary conditional checks for helm channel handling and improve its related logic. - Modify helm arguments to allow specific image configurations when the channel is set to "test." Signed-off-by: ysicing <[email protected]>
1 parent 9a64d5a commit 67442c3

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

Diff for: common/func.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ func GetChartRepo(p string) string {
5252
// GetChannel 获取chartrepo channel地址
5353
func GetChannel(p string) string {
5454
if strings.HasPrefix(p, "test") || strings.HasPrefix(p, "edge") {
55-
p = "test"
56-
} else {
57-
p = "stable"
55+
return "test"
5856
}
59-
return p
57+
return "stable"
6058
}
6159

6260
// GetVersion 获取版本地址
@@ -84,6 +82,15 @@ func GetVersion(devops bool, typ, version string) string {
8482
return defaultVersion
8583
}
8684

85+
// NeedUseCustomVersion 是否需要使用自定义版本
86+
func NeedUseCustomVersion(version string) bool {
87+
if strings.Contains(version, "stable") {
88+
return false
89+
}
90+
v := strings.Split(version, "-")
91+
return len(v) == 2
92+
}
93+
8794
func GetDefaultConfig() string {
8895
home := zos.GetHomeDir()
8996
return home + "/" + DefaultCfgDir + "/cluster.yaml"

Diff for: pkg/quickon/quickon.go

+9-16
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ func (m *Meta) Init() error {
250250
}
251251
}
252252
installVersion := common.GetVersion(m.DevopsMode, m.Type, m.Version)
253-
m.Log.Infof("devops: %v, type: %s, version: %s, channel: %s", m.DevopsMode, m.Type, installVersion, common.GetChannel(m.Version))
253+
repoChannel := common.GetChannel(m.Version)
254+
m.Log.Infof("devops: %v, type: %s, version: %s, channel: %s", m.DevopsMode, m.Type, installVersion, repoChannel)
254255
m.Log.Debugf("start init %s", common.GetInstallType(m.DevopsMode))
255256
cfg.Quickon.Type = common.QuickonType(m.Type)
256257
cfg.Quickon.DevOps = m.DevopsMode
@@ -342,13 +343,7 @@ func (m *Meta) Init() error {
342343
m.Log.Done("check operator ready success")
343344
}
344345

345-
helmchan := common.GetChannel(m.Version)
346-
helmargs := []string{"experimental", "helm", "upgrade", "--name", common.GetReleaseName(m.DevopsMode), "--repo", common.DefaultHelmRepoName, "--chart", common.GetReleaseName(m.DevopsMode), "--namespace", common.GetDefaultSystemNamespace(true), "--set", "env.APP_DOMAIN=" + m.Domain, "--set", "env.CNE_API_TOKEN=" + token, "--set", "cloud.defaultChannel=" + helmchan}
347-
if helmchan != "stable" {
348-
helmargs = append(helmargs, "--set", "env.PHP_DEBUG=2")
349-
helmargs = append(helmargs, "--set", "cloud.switchChannel=true")
350-
helmargs = append(helmargs, "--set", "cloud.selectVersion=true")
351-
}
346+
helmargs := []string{"experimental", "helm", "upgrade", "--name", common.GetReleaseName(m.DevopsMode), "--repo", common.DefaultHelmRepoName, "--chart", common.GetReleaseName(m.DevopsMode), "--namespace", common.GetDefaultSystemNamespace(true), "--set", "env.APP_DOMAIN=" + m.Domain, "--set", "env.CNE_API_TOKEN=" + token, "--set", "cloud.defaultChannel=" + repoChannel}
352347
hostdomain := m.Domain
353348
if kutil.IsLegalDomain(hostdomain) && m.DomainType == "api" {
354349
m.Log.Debugf("use tls cert for domain %s", hostdomain)
@@ -380,21 +375,19 @@ func (m *Meta) Init() error {
380375
}
381376

382377
helmargs = append(helmargs, "--set", fmt.Sprintf("ingress.host=%s", hostdomain))
383-
384378
if m.DevopsMode {
385379
// 指定类型
386380
helmargs = append(helmargs, "--set", fmt.Sprintf("deploy.product=%s", m.Type))
387-
// deployVersion := fmt.Sprintf("deploy.versions.%s=%s%s.k8s", m.Type, m.Type, installVersion)
388-
// if m.Type == common.ZenTaoOSSType.String() {
389-
// deployVersion = fmt.Sprintf("deploy.versions.%s=%s", m.Type, installVersion)
390-
// }
391-
// helmargs = append(helmargs, "--set", deployVersion)
392-
if helmchan != "stable" {
381+
if repoChannel == "test" {
393382
helmargs = append(helmargs, "--set", "image.repository=test/zentao")
394383
helmargs = append(helmargs, "--set", "sidecars.backend.image.tag=dev")
395384
helmargs = append(helmargs, "--set", "sidecars.backend.image.pullPolicy=Always")
385+
helmargs = append(helmargs, "--set", "env.PHP_DEBUG=2")
386+
helmargs = append(helmargs, "--set", "cloud.switchChannel=true")
387+
helmargs = append(helmargs, "--set", "cloud.selectVersion=true")
388+
}
389+
if common.NeedUseCustomVersion(m.Version) {
396390
deployVersion := fmt.Sprintf("deploy.versions.%s=%s%s.k8s", m.Type, m.Type, installVersion)
397-
helmargs = append(helmargs, "--set", deployVersion)
398391
if m.Type == common.ZenTaoOSSType.String() || m.Type == common.ZenTaoOldOSSType.String() {
399392
deployVersion = fmt.Sprintf("deploy.versions.open=%s", installVersion)
400393
}

0 commit comments

Comments
 (0)