Skip to content

Commit 28dfabf

Browse files
committed
[fix][init] check activate cluster
1 parent 3cfd33b commit 28dfabf

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

cli/cli/cli.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,11 @@ func (dingoadm *DingoAdm) init() error {
167167
var cluster storage.Cluster
168168
// check current active cluster config in env or not
169169

170-
if activatedClusterName, exists := os.LookupEnv(comm.KEY_ENV_ACTIVATE_CLUSTER); exists && len(activatedClusterName) > 0 {
170+
if activatedClusterName := getActivatedClusterFromEnv(); activatedClusterName != "" {
171171
cluster, err = s.GetClusterByName(activatedClusterName)
172172
if err != nil {
173173
log.Error("Get cluster by name failed",
174174
log.Field("Error", err))
175-
return errno.ERR_GET_CLUSTER_BY_NAME_FAILED.E(err)
176-
}
177-
} else if activatedClusterName, exists = os.LookupEnv(strings.ToLower(comm.KEY_ENV_ACTIVATE_CLUSTER)); exists && len(activatedClusterName) > 0 {
178-
cluster, err = s.GetClusterByName(activatedClusterName)
179-
if err != nil {
180-
log.Error("Get cluster by name failed",
181-
log.Field("Error", err))
182-
return errno.ERR_GET_CLUSTER_BY_NAME_FAILED.E(err)
183175
}
184176
} else {
185177
cluster, err = s.GetCurrentCluster()
@@ -219,6 +211,20 @@ func (dingoadm *DingoAdm) init() error {
219211
return nil
220212
}
221213

214+
func getActivatedClusterFromEnv() string {
215+
// Check original case first
216+
if activatedClusterName, exists := os.LookupEnv(comm.KEY_ENV_ACTIVATE_CLUSTER); exists && len(activatedClusterName) > 0 {
217+
return activatedClusterName
218+
}
219+
220+
// Check lowercase version as fallback
221+
if activatedClusterName, exists := os.LookupEnv(strings.ToLower(comm.KEY_ENV_ACTIVATE_CLUSTER)); exists && len(activatedClusterName) > 0 {
222+
return activatedClusterName
223+
}
224+
225+
return ""
226+
}
227+
222228
func (dingoadm *DingoAdm) detectVersion() {
223229
latestVersion, err := tools.GetLatestVersion(Version)
224230
if err != nil || len(latestVersion) == 0 {

0 commit comments

Comments
 (0)