-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
k8s的config配置文件存储数据库和k8s api使用数据库里的kube config
- Loading branch information
Showing
21 changed files
with
1,060 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package apis_k8s | ||
|
||
import ( | ||
"cmdb-ops-flow/models/k8s" | ||
"cmdb-ops-flow/service/service_k8s" | ||
"cmdb-ops-flow/utils/msg" | ||
"cmdb-ops-flow/utils/result" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
func GetallNamespace(c *gin.Context) { | ||
var data struct { | ||
ID int `json:"id"` | ||
} | ||
if err := c.ShouldBindJSON(&data); err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(400, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
list, err := service_k8s.GetNamespace(data.ID) | ||
if err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(msg.ERROR, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
code := msg.SUCCSE | ||
c.JSON(http.StatusOK, (&result.Result{}).Ok(code, list, msg.GetErrMsg(code))) | ||
} | ||
|
||
func AddNamespace(c *gin.Context) { | ||
//var data struct { | ||
// ID int `json:"id"` | ||
//} | ||
//if err := c.ShouldBindJSON(&data); err != nil { | ||
// c.JSON(http.StatusOK, (&result.Result{}).Error(500, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
// return | ||
//} | ||
var data k8s.NameSpace | ||
if err := c.ShouldBindJSON(&data); err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(5001, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
list, err := service_k8s.AddNamespace(data.ID, data) | ||
if err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(msg.ERROR, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
code := msg.SUCCSE | ||
c.JSON(http.StatusOK, (&result.Result{}).Ok(code, list, msg.GetErrMsg(code))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package apis_k8s | ||
|
||
import ( | ||
"cmdb-ops-flow/service/service_k8s" | ||
"cmdb-ops-flow/utils/msg" | ||
"cmdb-ops-flow/utils/result" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
func GetVersion(c *gin.Context) { | ||
var data struct { | ||
ID int `json:"id"` | ||
} | ||
if err := c.ShouldBindJSON(&data); err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(400, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
list, err := service_k8s.Version(data.ID) | ||
if err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(msg.ERROR, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
code := msg.SUCCSE | ||
c.JSON(http.StatusOK, (&result.Result{}).Ok(code, list, msg.GetErrMsg(code))) | ||
} | ||
|
||
func GetAllNodes(c *gin.Context) { | ||
var data struct { | ||
ID int `json:"id"` | ||
} | ||
if err := c.ShouldBindJSON(&data); err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(400, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
list, err := service_k8s.Getnodes(data.ID) | ||
if err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(msg.ERROR, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
code := msg.SUCCSE | ||
c.JSON(http.StatusOK, (&result.Result{}).Ok(code, list, msg.GetErrMsg(code))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package apis_k8s | ||
|
||
import ( | ||
"cmdb-ops-flow/service/service_k8s" | ||
"cmdb-ops-flow/utils/msg" | ||
"cmdb-ops-flow/utils/result" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
func GetAllPods(c *gin.Context) { | ||
var data struct { | ||
ID int `json:"id"` | ||
} | ||
if err := c.ShouldBindJSON(&data); err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(400, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
list, err := service_k8s.GetPods(data.ID) | ||
if err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(msg.ERROR, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
code := msg.SUCCSE | ||
c.JSON(http.StatusOK, (&result.Result{}).Ok(code, list, msg.GetErrMsg(code))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package api | ||
|
||
import ( | ||
"cmdb-ops-flow/models" | ||
"cmdb-ops-flow/service" | ||
"cmdb-ops-flow/utils/msg" | ||
"cmdb-ops-flow/utils/result" | ||
"github.com/gin-gonic/gin" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
func AddKubeConfig(c *gin.Context) { | ||
file, err := c.FormFile("yamlFile") | ||
if err != nil { | ||
c.JSON(http.StatusOK, gin.H{"error1": err.Error()}) | ||
return | ||
} | ||
kubeconfigname := c.PostForm("kubeconfigname") | ||
|
||
fileContent, err := file.Open() | ||
if err != nil { | ||
c.JSON(http.StatusOK, gin.H{"error2": err.Error()}) | ||
return | ||
} | ||
defer fileContent.Close() | ||
yamlData, err := ioutil.ReadAll(fileContent) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error3": err.Error()}) | ||
return | ||
} | ||
|
||
data, err := service.AddKubeConfig(yamlData, kubeconfigname) | ||
if err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, (&result.Result{}).Ok(200, data, msg.GetErrMsg(200))) | ||
|
||
} | ||
func EditKubeConfig(c *gin.Context) { | ||
var data models.KubeConfig | ||
if err := c.ShouldBindJSON(&data); err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(msg.ERROR, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
list, err := service.EditKubeConfig(data) | ||
if err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(msg.ERROR, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
code := msg.SUCCSE | ||
c.JSON(http.StatusOK, (&result.Result{}).Ok(code, list, msg.GetErrMsg(code))) | ||
} | ||
func GetKubeConfig(c *gin.Context) { | ||
//var data models.ScriptManager | ||
var data struct { | ||
ID int `json:"id"` | ||
} | ||
|
||
if err := c.ShouldBindJSON(&data); err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(400, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
list, err := service.GetKubeConfigList(data.ID) | ||
if err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(msg.ERROR, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
code := msg.SUCCSE | ||
c.JSON(http.StatusOK, (&result.Result{}).Ok(code, list, msg.GetErrMsg(code))) | ||
|
||
} | ||
|
||
func DelKubeConfig(c *gin.Context) { | ||
|
||
var data models.KubeConfig | ||
if err := c.ShouldBindJSON(&data); err != nil { | ||
c.JSON(http.StatusOK, (&result.Result{}).Error(msg.ERROR, err.Error(), msg.GetErrMsg(msg.ERROR))) | ||
return | ||
} | ||
code := models.DelKubeConfig(data.Kubeconfigid) | ||
|
||
c.JSON(http.StatusOK, (&result.Result{}).Ok(code, msg.SUCCSE, msg.GetErrMsg(code))) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.