|
|
|
@ -2,35 +2,19 @@ package node
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"k8s-manager/handler/common"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
|
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
|
|
|
|
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// List 获取NodeList
|
|
|
|
|
func List(ctx *gin.Context) {
|
|
|
|
|
// 1. 配置 kubeconfig, 得到client(ClientSet)对象
|
|
|
|
|
// 配置文件位置
|
|
|
|
|
kubeConfigPath := ".kube/config"
|
|
|
|
|
// 构建配置,读取配置文件内容,解析为配置对象
|
|
|
|
|
config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{
|
|
|
|
|
"code": 1,
|
|
|
|
|
"message": err.Error(),
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// 使用配置i,得到ClientSet对象
|
|
|
|
|
clientSet, err := kubernetes.NewForConfig(config)
|
|
|
|
|
// 1. 得到client(ClientSet)对象
|
|
|
|
|
clientSet, err := common.GetClientSet()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{
|
|
|
|
|