From c225ba28429618bd308532750c231eefc7217b6e Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Fri, 21 Jun 2024 16:38:18 +0800 Subject: [PATCH] fix(apigateway): compose environment without k8s service (#20616) --- .../modules/webconsole/mod_webconsole.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/mcclient/modules/webconsole/mod_webconsole.go b/pkg/mcclient/modules/webconsole/mod_webconsole.go index 9aa8d115d4..3a83f38ee5 100644 --- a/pkg/mcclient/modules/webconsole/mod_webconsole.go +++ b/pkg/mcclient/modules/webconsole/mod_webconsole.go @@ -16,6 +16,7 @@ package webconsole import ( "fmt" + "strings" "yunion.io/x/jsonutils" "yunion.io/x/pkg/errors" @@ -77,10 +78,8 @@ func (m WebConsoleManager) DoCloudShell(s *mcclient.ClientSession, _ jsonutils.J query.Add(jsonutils.NewString("system"), "scope") query.Add(jsonutils.NewString("system-default"), "name") clusters, err := k8s.KubeClusters.List(adminSession, query) - if err != nil { - return nil, errors.Wrap(err, "KubeClusters") - } - if len(clusters.Data) == 0 { + + climcSshConnect := func(s *mcclient.ClientSession) (jsonutils.JSONObject, error) { // maybe running in docker compose environment, so try to use ssh way if data, err := m.DoClimcSshConnect(s, "climc", 22); err != nil { return nil, httperrors.NewNotFoundError(errors.Wrap(err, "cluster system-default not found, try to use ssh way").Error()) @@ -88,6 +87,15 @@ func (m WebConsoleManager) DoCloudShell(s *mcclient.ClientSession, _ jsonutils.J return data, nil } } + if err != nil { + if errors.Cause(err) == errors.ErrNotFound && strings.Contains(err.Error(), "No such service k8s") { + return climcSshConnect(s) + } + return nil, errors.Wrap(err, "KubeClusters") + } + if len(clusters.Data) == 0 { + return climcSshConnect(s) + } clusterId, _ := clusters.Data[0].GetString("id") if len(clusterId) == 0 { return nil, httperrors.NewNotFoundError("cluster system-default no id")