You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
package node
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"k8s-manager/handler/common"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// List 获取NodeList
|
|
|
|
|
func List(ctx *gin.Context) {
|
|
|
|
|
// 1. 得到client(ClientSet)对象
|
|
|
|
|
clientSet, err := common.GetClientSet()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{
|
|
|
|
|
// code == 2, 意味着配置文件有问题
|
|
|
|
|
"code": 2,
|
|
|
|
|
"message": err.Error(),
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. 发出获取节点列表的请求
|
|
|
|
|
nodeList, err := clientSet.CoreV1().Nodes().List(
|
|
|
|
|
context.Background(),
|
|
|
|
|
metav1.ListOptions{},
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{
|
|
|
|
|
"code": 1,
|
|
|
|
|
"message": err.Error(),
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. 接收 k8s cluster 的 apiServer 的响应,处理
|
|
|
|
|
// 整理 NodeList 对象
|
|
|
|
|
|
|
|
|
|
// 4. 给前端做响应
|
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{
|
|
|
|
|
"code": 0,
|
|
|
|
|
"data": nodeList,
|
|
|
|
|
})
|
|
|
|
|
}
|