换成单集群模式

This commit is contained in:
robin
2026-03-02 20:07:53 +08:00
parent 5d0b7c7e91
commit 2a76d1773d
432 changed files with 5681 additions and 5095 deletions

View File

@@ -1,6 +1,9 @@
package sandbox
import (
"encoding/json"
"strings"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
@@ -25,9 +28,37 @@ func (this *IndexAction) RunGet(params struct{}) {
}
clusters := make([]maps.Map, 0, len(clusterResp.GetClusters()))
for _, cluster := range clusterResp.GetClusters() {
serviceDomain := strings.TrimSpace(cluster.GetServiceDomain())
port := "443"
if rawTLS := cluster.GetTlsPolicyJSON(); len(rawTLS) > 0 {
var tlsConfig map[string]interface{}
if err := json.Unmarshal(rawTLS, &tlsConfig); err == nil {
if listenRaw, ok := tlsConfig["listen"]; ok && listenRaw != nil {
if data, err := json.Marshal(listenRaw); err == nil {
var listenAddresses []map[string]interface{}
if err := json.Unmarshal(data, &listenAddresses); err == nil {
if len(listenAddresses) > 0 {
if portRange, ok := listenAddresses[0]["portRange"].(string); ok && len(portRange) > 0 {
port = portRange
}
}
}
}
}
}
}
apiAddress := "https://" + serviceDomain + ":" + port
displayName := apiAddress
if len(serviceDomain) == 0 {
displayName = cluster.GetName()
}
clusters = append(clusters, maps.Map{
"id": cluster.GetId(),
"name": cluster.GetName(),
"id": cluster.GetId(),
"name": cluster.GetName(),
"serviceDomain": serviceDomain,
"displayName": displayName,
})
}
this.Data["clusters"] = clusters
@@ -50,14 +81,18 @@ func (this *IndexAction) RunGet(params struct{}) {
for _, domain := range domainResp.GetDomains() {
domains = append(domains, domain.GetDomain())
}
// 解析集群ID列表
var clusterIds []int64
if len(app.GetClusterIdsJSON()) > 0 {
_ = json.Unmarshal(app.GetClusterIdsJSON(), &clusterIds)
}
apps = append(apps, maps.Map{
"id": app.GetId(),
"name": app.GetName(),
"appId": app.GetAppId(),
"clusterId": app.GetPrimaryClusterId(),
"primaryClusterId": app.GetPrimaryClusterId(),
"backupClusterId": app.GetBackupClusterId(),
"domains": domains,
"id": app.GetId(),
"name": app.GetName(),
"appId": app.GetAppId(),
"clusterIds": clusterIds,
"domains": domains,
})
}
this.Data["apps"] = apps

View File

@@ -4,6 +4,7 @@ import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"net/url"
"strconv"
"strings"
@@ -52,12 +53,30 @@ func (this *TestAction) RunPost(params struct {
}
clusterDomain := ""
port := "443"
if params.ClusterId > 0 {
clusterResp, findErr := this.RPC().HTTPDNSClusterRPC().FindHTTPDNSCluster(this.AdminContext(), &pb.FindHTTPDNSClusterRequest{
ClusterId: params.ClusterId,
})
if findErr == nil && clusterResp.GetCluster() != nil {
clusterDomain = strings.TrimSpace(clusterResp.GetCluster().GetServiceDomain())
if rawTLS := clusterResp.GetCluster().GetTlsPolicyJSON(); len(rawTLS) > 0 {
var tlsConfig map[string]interface{}
if err := json.Unmarshal(rawTLS, &tlsConfig); err == nil {
if listenRaw, ok := tlsConfig["listen"]; ok && listenRaw != nil {
if data, err := json.Marshal(listenRaw); err == nil {
var listenAddresses []map[string]interface{}
if err := json.Unmarshal(data, &listenAddresses); err == nil {
if len(listenAddresses) > 0 {
if portRange, ok := listenAddresses[0]["portRange"].(string); ok && len(portRange) > 0 {
port = portRange
}
}
}
}
}
}
}
}
}
if len(clusterDomain) == 0 {
@@ -80,7 +99,7 @@ func (this *TestAction) RunPost(params struct {
query.Set("nonce", nonce)
query.Set("sign", sign)
}
requestURL := "https://" + clusterDomain + "/resolve?" + query.Encode()
requestURL := "https://" + clusterDomain + ":" + port + "/resolve?" + query.Encode()
resultCode := 1
if strings.EqualFold(resp.GetCode(), "SUCCESS") {