查询域和集群接口修改
This commit is contained in:
parent
6653fb8fd9
commit
f49ee3fb3f
|
@ -533,33 +533,16 @@ func ListByDomain(c *gin.Context) {
|
|||
deploymentName := c.Query("deployment_name")
|
||||
domainId := c.Query("domain_id")
|
||||
|
||||
//
|
||||
deployJson := GetDeployFromOS(namespaceName, deploymentName, "")
|
||||
hits, _ := deployJson.Get("hits").Get("hits").Array()
|
||||
var clusterSet []Cluster
|
||||
for i := 0; i < len(hits); i++ {
|
||||
cluster, _ := deployJson.Get("hits").Get("hits").GetIndex(i).Get("_source").Get("metadata").Get("annotations").Get("resource.karmada.io/cached-from-cluster").String()
|
||||
//获取域列表
|
||||
rows, _ := DB.Query("select dc.cluster_name,d.domain_name,d.domain_id from domain_cluster dc,domain d where d.domain_id = ? and dc.domain_id = d.domain_id ", domainId)
|
||||
for rows.Next() {
|
||||
var clusterName string
|
||||
var domainName string
|
||||
var domainIdResult int32
|
||||
rows.Scan(&clusterName, &domainName, &domainId)
|
||||
|
||||
if clusterName == cluster {
|
||||
cluster := Cluster{
|
||||
ClusterName: clusterName,
|
||||
DomainId: domainIdResult,
|
||||
DomainName: domainName,
|
||||
}
|
||||
|
||||
clusterSet = append(clusterSet, cluster)
|
||||
}
|
||||
}
|
||||
propagationPolicy, err := KarmadaClient.PolicyV1alpha1().PropagationPolicies(namespaceName).Get(context.TODO(), "deployment."+namespaceName+"."+deploymentName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
}
|
||||
|
||||
Response(c, http.StatusOK, "success", clusterSet)
|
||||
var clusterList []string
|
||||
for _, clusterName := range propagationPolicy.Spec.Placement.ClusterAffinity.ClusterNames {
|
||||
clusterList = append(clusterList, clusterName)
|
||||
}
|
||||
var result []string
|
||||
Gorm.Debug().Raw("SELECT distinct cluster_name from domain_cluster where cluster_name in (?) and domain_id = ?", clusterList, domainId).Scan(&result)
|
||||
Response(c, http.StatusOK, "success", result)
|
||||
}
|
||||
|
||||
// @Summary 集群注册
|
||||
|
|
|
@ -244,13 +244,6 @@ func DescribeDomain(c *gin.Context) {
|
|||
}
|
||||
func ListClusters(c *gin.Context) {
|
||||
|
||||
namespaceName := c.Query("namespace")
|
||||
deploymentName := c.Query("deployment_name")
|
||||
|
||||
propagationPolicy, _ := KarmadaClient.PolicyV1alpha1().PropagationPolicies(namespaceName).Get(context.TODO(), "deployment."+namespaceName+"."+deploymentName, v2.GetOptions{})
|
||||
|
||||
Response(c, http.StatusOK, "success", propagationPolicy.Spec.Placement.ClusterAffinity.ClusterNames)
|
||||
|
||||
}
|
||||
|
||||
// ListByDeployment 根据项目名称和工作负载查询域列表
|
||||
|
@ -268,26 +261,23 @@ func ListByDeployment(c *gin.Context) {
|
|||
namespaceName := c.Query("namespace")
|
||||
deploymentName := c.Query("deployment_name")
|
||||
|
||||
domainList := getDomainsByDeployment(namespaceName, deploymentName)
|
||||
Response(c, http.StatusOK, "success", domainList)
|
||||
}
|
||||
|
||||
// 通过ns名称+deploy名称查询deploy所在域的信息,单独方法供复用
|
||||
func getDomainsByDeployment(namespaceName string, deploymentName string) []string {
|
||||
// 获取策略信息
|
||||
propagationPolicy, err := KarmadaClient.PolicyV1alpha1().PropagationPolicies(namespaceName).Get(context.TODO(), "deployment."+namespaceName+"."+deploymentName, v2.GetOptions{})
|
||||
if err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
var clusterList []string
|
||||
for _, clusterName := range propagationPolicy.Spec.Placement.ClusterAffinity.ClusterNames {
|
||||
clusterList = append(clusterList, clusterName)
|
||||
}
|
||||
var domainList []string
|
||||
//strings.Join(clusterList, ",")
|
||||
Gorm.Debug().Raw("SELECT domain_name from domain_cluster where cluster_name in (?)", clusterList).Scan(&domainList)
|
||||
var domainInfos []DomainInfo
|
||||
Gorm.Debug().Raw("SELECT distinct domain_id,domain_name from domain_cluster where cluster_name in (?)", clusterList).Scan(&domainInfos)
|
||||
|
||||
return domainList
|
||||
Response(c, http.StatusOK, "success", domainInfos)
|
||||
}
|
||||
|
||||
type DomainInfo struct {
|
||||
DomainId int `json:"domainId"`
|
||||
DomainName string `json:"domainName"`
|
||||
}
|
||||
|
||||
func QueryDomainUsedRate(c *gin.Context) {
|
||||
|
|
Loading…
Reference in New Issue