fix(k8s): ConfigMap/Secret 列表扁平化字段供前端表格展示
后端原返回 metadata.name 嵌套结构,前端读 name/namespace/key_count 为空。
This commit is contained in:
1 parent
bdf1f41464
commit
21d40b186a
1 file changed
+32
-2
@@ -156,7 +156,21 @@ func (h *KubernetesHandler) ListConfigMaps(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, model.Response{Code: 200, Data: cms.Items})
|
||||
// 扁平化字段,与前端表格列 name/namespace/key_count 对齐 // Logan.Li
|
||||
type CMSummary struct {
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
KeyCount int `json:"key_count"`
|
||||
}
|
||||
result := make([]CMSummary, 0, len(cms.Items))
|
||||
for _, cm := range cms.Items {
|
||||
result = append(result, CMSummary{
|
||||
Namespace: cm.Metadata.Namespace,
|
||||
Name: cm.Metadata.Name,
|
||||
KeyCount: len(cm.Data),
|
||||
})
|
||||
}
|
||||
c.JSON(http.StatusOK, model.Response{Code: 200, Data: result})
|
||||
}
|
||||
|
||||
// ListSecrets 获取命名空间下的 Secret 列表(仅名称+类型,不含值)
|
||||
@@ -179,7 +193,23 @@ func (h *KubernetesHandler) ListSecrets(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, model.Response{Code: 200, Data: secrets.Items})
|
||||
// 扁平化字段,与前端表格列 name/namespace/type 对齐 // Logan.Li
|
||||
type SecretSummary struct {
|
||||
Namespace string `json:"namespace"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
KeyCount int `json:"key_count"`
|
||||
}
|
||||
result := make([]SecretSummary, 0, len(secrets.Items))
|
||||
for _, s := range secrets.Items {
|
||||
result = append(result, SecretSummary{
|
||||
Namespace: s.Metadata.Namespace,
|
||||
Name: s.Metadata.Name,
|
||||
Type: s.Type,
|
||||
KeyCount: len(s.DataKeys),
|
||||
})
|
||||
}
|
||||
c.JSON(http.StatusOK, model.Response{Code: 200, Data: result})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in new issue
Block a user