Skip to content

Commit 107558e

Browse files
fix remote terminal connection (#841)
1 parent b01874e commit 107558e

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

internal/dashboard/handler/conn_handler.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434

3535
"github.com/oceanbase/ob-operator/internal/clients"
3636
oceanbaseconst "github.com/oceanbase/ob-operator/internal/const/oceanbase"
37+
serverstatus "github.com/oceanbase/ob-operator/internal/const/status/observer"
3738
"github.com/oceanbase/ob-operator/internal/dashboard/business/k8s"
3839
"github.com/oceanbase/ob-operator/internal/dashboard/model/param"
3940
"github.com/oceanbase/ob-operator/internal/dashboard/model/response"
@@ -135,22 +136,31 @@ func CreateOBClusterConnTerminal(c *gin.Context) (*response.OBConnection, error)
135136
}
136137
passwd := string(secret.Data["password"])
137138

138-
pods, err := client.GetClient().ClientSet.CoreV1().Pods(nn.Namespace).List(c, metav1.ListOptions{
139-
LabelSelector: oceanbaseconst.LabelRefOBCluster + "=" + obcluster.Name,
140-
FieldSelector: "status.phase=Running",
141-
})
139+
observerList, err := clients.ListOBServersOfOBCluster(c, obcluster)
142140
if err != nil {
143141
return nil, err
144142
}
145-
if len(pods.Items) == 0 {
146-
return nil, httpErr.NewBadRequest("no running pods found in obcluster")
143+
if len(observerList.Items) == 0 {
144+
return nil, httpErr.NewBadRequest("no running observers found in obcluster")
145+
}
146+
147+
name := ""
148+
host := ""
149+
for _, observer := range observerList.Items {
150+
if observer.Status.Status == serverstatus.Running {
151+
name = observer.Name
152+
host = observer.Status.PodIp
153+
}
154+
}
155+
if name == "" && host == "" {
156+
return nil, httpErr.NewBadRequest("no running observers found in obcluster")
147157
}
148158

149159
conn := &response.OBConnection{}
150160
conn.Namespace = nn.Namespace
151161
conn.Cluster = nn.Name
152-
conn.Pod = pods.Items[0].Name
153-
conn.Host = pods.Items[0].Status.PodIP
162+
conn.Pod = name
163+
conn.Host = host
154164
conn.ClientIP = c.ClientIP()
155165
conn.Password = passwd
156166
conn.User = "root"

0 commit comments

Comments
 (0)