update
This commit is contained in:
1 parent
0690285147
commit
5618cd2738
154 files changed
+5021
-3161
No files matched your search
@@ -223,7 +223,6 @@ func (h *KubernetesHandler) SaveTopology(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, model.Response{Code: 200, Message: "保存成功"})
|
||||
}
|
||||
|
||||
|
||||
// SyncCluster 同步集群资源(连接真实K8s API拉取数据)
|
||||
func (h *KubernetesHandler) ListConfigMaps(c *gin.Context) {
|
||||
clusterID, _ := strconv.Atoi(c.Param("id"))
|
||||
@@ -313,11 +312,19 @@ func (h *KubernetesHandler) ListIngressesNS(c *gin.Context) {
|
||||
}
|
||||
func (h *KubernetesHandler) listServicesWithNS(c *gin.Context, ns string) {
|
||||
clusterID, _ := strconv.Atoi(c.Param("id"))
|
||||
if clusterID == 0 { clusterID = h.resolveClusterCode(c.Param("clusterCode")) }
|
||||
if clusterID == 0 {
|
||||
clusterID = h.resolveClusterCode(c.Param("clusterCode"))
|
||||
}
|
||||
client, _, err := h.getK8sClient(clusterID)
|
||||
if err != nil { c.JSON(500, model.Response{Code: 500, Message: err.Error()}); return }
|
||||
if err != nil {
|
||||
c.JSON(500, model.Response{Code: 500, Message: err.Error()})
|
||||
return
|
||||
}
|
||||
svcs, err := client.ListServices()
|
||||
if err != nil { c.JSON(500, model.Response{Code: 500, Message: "K8s API error: " + err.Error()}); return }
|
||||
if err != nil {
|
||||
c.JSON(500, model.Response{Code: 500, Message: "K8s API error: " + err.Error()})
|
||||
return
|
||||
}
|
||||
type SvcPortDetail struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Port int `json:"port"`
|
||||
@@ -326,17 +333,19 @@ func (h *KubernetesHandler) listServicesWithNS(c *gin.Context, ns string) {
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
}
|
||||
type SvcSummary struct {
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
ClusterIP string `json:"cluster_ip"`
|
||||
Ports int `json:"ports"`
|
||||
PortList []SvcPortDetail `json:"portList,omitempty"`
|
||||
Selector map[string]string `json:"selector,omitempty"`
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
ClusterIP string `json:"cluster_ip"`
|
||||
Ports int `json:"ports"`
|
||||
PortList []SvcPortDetail `json:"portList,omitempty"`
|
||||
Selector map[string]string `json:"selector,omitempty"`
|
||||
}
|
||||
result := []SvcSummary{}
|
||||
for _, s := range svcs.Items {
|
||||
if s.Metadata.Namespace != ns { continue }
|
||||
if s.Metadata.Namespace != ns {
|
||||
continue
|
||||
}
|
||||
ports := []SvcPortDetail{}
|
||||
for _, p := range s.Spec.Ports {
|
||||
ports = append(ports, SvcPortDetail{
|
||||
@@ -345,28 +354,36 @@ func (h *KubernetesHandler) listServicesWithNS(c *gin.Context, ns string) {
|
||||
})
|
||||
}
|
||||
result = append(result, SvcSummary{
|
||||
Namespace: s.Metadata.Namespace,
|
||||
Name: s.Metadata.Name,
|
||||
Type: s.Spec.Type,
|
||||
ClusterIP: s.Spec.ClusterIP,
|
||||
Ports: len(s.Spec.Ports),
|
||||
PortList: ports,
|
||||
Selector: s.Spec.Selector,
|
||||
Namespace: s.Metadata.Namespace,
|
||||
Name: s.Metadata.Name,
|
||||
Type: s.Spec.Type,
|
||||
ClusterIP: s.Spec.ClusterIP,
|
||||
Ports: len(s.Spec.Ports),
|
||||
PortList: ports,
|
||||
Selector: s.Spec.Selector,
|
||||
})
|
||||
}
|
||||
c.JSON(200, model.Response{Code: 200, Data: result})
|
||||
}
|
||||
func (h *KubernetesHandler) listIngressesWithNS(c *gin.Context, ns string) {
|
||||
clusterID, _ := strconv.Atoi(c.Param("id"))
|
||||
if clusterID == 0 { clusterID = h.resolveClusterCode(c.Param("clusterCode")) }
|
||||
if clusterID == 0 {
|
||||
clusterID = h.resolveClusterCode(c.Param("clusterCode"))
|
||||
}
|
||||
client, _, err := h.getK8sClient(clusterID)
|
||||
if err != nil { c.JSON(500, model.Response{Code: 500, Message: err.Error()}); return }
|
||||
if err != nil {
|
||||
c.JSON(500, model.Response{Code: 500, Message: err.Error()})
|
||||
return
|
||||
}
|
||||
ings, err := client.ListIngresses()
|
||||
if err != nil { c.JSON(500, model.Response{Code: 500, Message: "K8s API error: " + err.Error()}); return }
|
||||
if err != nil {
|
||||
c.JSON(500, model.Response{Code: 500, Message: "K8s API error: " + err.Error()})
|
||||
return
|
||||
}
|
||||
type PathDetail struct {
|
||||
Path string `json:"path"`
|
||||
PathType string `json:"pathType,omitempty"`
|
||||
BackendSvc string `json:"backendService,omitempty"`
|
||||
Path string `json:"path"`
|
||||
PathType string `json:"pathType,omitempty"`
|
||||
BackendSvc string `json:"backendService,omitempty"`
|
||||
BackendPort string `json:"backendPort,omitempty"`
|
||||
}
|
||||
type RuleDetail struct {
|
||||
@@ -374,20 +391,24 @@ func (h *KubernetesHandler) listIngressesWithNS(c *gin.Context, ns string) {
|
||||
Paths []PathDetail `json:"paths"`
|
||||
}
|
||||
type IngSummary struct {
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
Hosts []string `json:"hosts"`
|
||||
TLS bool `json:"tls"`
|
||||
IngressClass string `json:"ingressClass,omitempty"`
|
||||
Rules []RuleDetail `json:"rules,omitempty"`
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
Hosts []string `json:"hosts"`
|
||||
TLS bool `json:"tls"`
|
||||
IngressClass string `json:"ingressClass,omitempty"`
|
||||
Rules []RuleDetail `json:"rules,omitempty"`
|
||||
}
|
||||
result := []IngSummary{}
|
||||
for _, ing := range ings.Items {
|
||||
if ing.Metadata.Namespace != ns { continue }
|
||||
if ing.Metadata.Namespace != ns {
|
||||
continue
|
||||
}
|
||||
hosts := []string{}
|
||||
rules := []RuleDetail{}
|
||||
for _, rule := range ing.Spec.Rules {
|
||||
if rule.Host != "" { hosts = append(hosts, rule.Host) }
|
||||
if rule.Host != "" {
|
||||
hosts = append(hosts, rule.Host)
|
||||
}
|
||||
rd := RuleDetail{Host: rule.Host, Paths: []PathDetail{}}
|
||||
if rule.HTTP != nil {
|
||||
for _, p := range rule.HTTP.Paths {
|
||||
@@ -453,12 +474,21 @@ func (h *KubernetesHandler) ListIngressClasses(c *gin.Context) {
|
||||
|
||||
func (h *KubernetesHandler) ListPVCsNS(c *gin.Context) {
|
||||
clusterID := h.resolveClusterCode(c.Param("clusterCode"))
|
||||
if clusterID == 0 { c.JSON(500, model.Response{Code: 500, Message: "cluster not found"}); return }
|
||||
if clusterID == 0 {
|
||||
c.JSON(500, model.Response{Code: 500, Message: "cluster not found"})
|
||||
return
|
||||
}
|
||||
client, _, err := h.getK8sClient(clusterID)
|
||||
if err != nil { c.JSON(500, model.Response{Code: 500, Message: err.Error()}); return }
|
||||
if err != nil {
|
||||
c.JSON(500, model.Response{Code: 500, Message: err.Error()})
|
||||
return
|
||||
}
|
||||
ns := c.Param("namespace")
|
||||
pvcs, err := client.ListPVCs(ns)
|
||||
if err != nil { c.JSON(500, model.Response{Code: 500, Message: "K8s API error: " + err.Error()}); return }
|
||||
if err != nil {
|
||||
c.JSON(500, model.Response{Code: 500, Message: "K8s API error: " + err.Error()})
|
||||
return
|
||||
}
|
||||
type PVCSummary struct {
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
@@ -470,14 +500,16 @@ func (h *KubernetesHandler) ListPVCsNS(c *gin.Context) {
|
||||
for _, p := range pvcs.Items {
|
||||
size := ""
|
||||
if p.Status.Capacity != nil {
|
||||
if s, ok := p.Status.Capacity["storage"]; ok { size = s }
|
||||
if s, ok := p.Status.Capacity["storage"]; ok {
|
||||
size = s
|
||||
}
|
||||
}
|
||||
result = append(result, PVCSummary{
|
||||
Namespace: p.Metadata.Namespace,
|
||||
Name: p.Metadata.Name,
|
||||
Phase: p.Status.Phase,
|
||||
Size: size,
|
||||
StorageClass: p.Spec.StorageClassName,
|
||||
Namespace: p.Metadata.Namespace,
|
||||
Name: p.Metadata.Name,
|
||||
Phase: p.Status.Phase,
|
||||
Size: size,
|
||||
StorageClass: p.Spec.StorageClassName,
|
||||
})
|
||||
}
|
||||
c.JSON(200, model.Response{Code: 200, Data: result})
|
||||
@@ -486,11 +518,18 @@ func (h *KubernetesHandler) ListPVCsNS(c *gin.Context) {
|
||||
// DeletePVCNS deletes a PVC (code-based)
|
||||
func (h *KubernetesHandler) DeletePVCNS(c *gin.Context) {
|
||||
clusterID := h.resolveClusterCode(c.Param("clusterCode"))
|
||||
if clusterID == 0 { c.JSON(500, model.Response{Code: 500, Message: "cluster not found"}); return }
|
||||
if clusterID == 0 {
|
||||
c.JSON(500, model.Response{Code: 500, Message: "cluster not found"})
|
||||
return
|
||||
}
|
||||
client, _, err := h.getK8sClient(clusterID)
|
||||
if err != nil { c.JSON(500, model.Response{Code: 500, Message: err.Error()}); return }
|
||||
if err != nil {
|
||||
c.JSON(500, model.Response{Code: 500, Message: err.Error()})
|
||||
return
|
||||
}
|
||||
if err := client.DeletePVC(c.Param("namespace"), c.Param("name")); err != nil {
|
||||
c.JSON(500, model.Response{Code: 500, Message: "删除失败: " + err.Error()}); return
|
||||
c.JSON(500, model.Response{Code: 500, Message: "删除失败: " + err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(200, model.Response{Code: 200, Message: "已删除"})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user