Merge remote-tracking branch 'origin/master'
# Conflicts: # src/k8s_client.go
This commit is contained in:
commit
bba5910492
5
Makefile
5
Makefile
|
|
@ -1,4 +1,4 @@
|
||||||
IMAGE_TAG ?= docker.educg.net/k8s/manager:dev
|
IMAGE_TAG ?= docker.educg.net/cg/k8s-manager:v1.0.1
|
||||||
|
|
||||||
build: export CGO_ENABLED=0
|
build: export CGO_ENABLED=0
|
||||||
build: export GOOS=linux
|
build: export GOOS=linux
|
||||||
|
|
@ -18,3 +18,6 @@ uninstall:
|
||||||
restart: docker
|
restart: docker
|
||||||
kubectl delete -f install.yaml
|
kubectl delete -f install.yaml
|
||||||
kubectl apply -f install.yaml
|
kubectl apply -f install.yaml
|
||||||
|
|
||||||
|
push: docker
|
||||||
|
docker push $(IMAGE_TAG)
|
||||||
|
|
@ -23,7 +23,7 @@ kubectl get secret dev-secret -o yaml
|
||||||
```bash
|
```bash
|
||||||
helm repo add traefik https://traefik.github.io/charts
|
helm repo add traefik https://traefik.github.io/charts
|
||||||
helm repo update
|
helm repo update
|
||||||
helm install traefik traefik/traefik
|
helm install -f traefik-conf.yaml traefik traefik/traefik
|
||||||
helm uninstall traefik traefik/traefik
|
helm uninstall traefik
|
||||||
helm install traefik traefik/traefik --set expose.dashboard=true
|
helm install traefik traefik/traefik --set expose.dashboard=true
|
||||||
```
|
```
|
||||||
15
main.go
15
main.go
|
|
@ -17,21 +17,12 @@ func main() {
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
||||||
//r.SetFuncMap(template.FuncMap{
|
|
||||||
// "inc": m.Inc,
|
|
||||||
//})
|
|
||||||
//
|
|
||||||
//tmp := template.Must(template.New("").
|
|
||||||
// Funcs(template.FuncMap{
|
|
||||||
// "inc": m.Inc,
|
|
||||||
// }).
|
|
||||||
// ParseFS(f, "template/*"))
|
|
||||||
//
|
|
||||||
//r.SetHTMLTemplate(tmp)
|
|
||||||
fp, _ := fs.Sub(f, "static")
|
fp, _ := fs.Sub(f, "static")
|
||||||
r.StaticFS("/static", http.FS(fp))
|
r.StaticFS("/static", http.FS(fp))
|
||||||
|
|
||||||
r.GET("/index", m.JWTAuthMiddleware, m.AppPage)
|
r.GET("/index", m.JWTAuthMiddleware, func(c *gin.Context) {
|
||||||
|
c.FileFromFS("/template/app_view.html", http.FS(f))
|
||||||
|
})
|
||||||
r.GET("/apps", m.JWTAuthMiddleware, m.GetAppsController)
|
r.GET("/apps", m.JWTAuthMiddleware, m.GetAppsController)
|
||||||
r.POST("/app", m.JWTAuthMiddleware, m.CreateUpdateDeleteApp)
|
r.POST("/app", m.JWTAuthMiddleware, m.CreateUpdateDeleteApp)
|
||||||
r.PUT("/app", m.JWTAuthMiddleware, m.CreateUpdateDeleteApp)
|
r.PUT("/app", m.JWTAuthMiddleware, m.CreateUpdateDeleteApp)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/thoas/go-funk"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
@ -48,20 +49,7 @@ func statusString(a *AppViewModel) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func AppPage(c *gin.Context) {
|
func AppPage(c *gin.Context) {
|
||||||
//username := c.MustGet("username").(string)
|
|
||||||
//appsvm := funk.Map(GetApps(username), func(a AppModel) AppViewModel { return AppViewModel{AppModel: &a} }).([]AppViewModel)
|
|
||||||
//for i := range appsvm {
|
|
||||||
// a := &appsvm[i]
|
|
||||||
// a.Status = statusString(a)
|
|
||||||
// a.ServiceDisplayName = a.ServiceName()
|
|
||||||
//}
|
|
||||||
//vm := &AppsViewModel{
|
|
||||||
// Username: username,
|
|
||||||
// Apps: appsvm,
|
|
||||||
//}
|
|
||||||
|
|
||||||
c.File("template/app_view.html")
|
c.File("template/app_view.html")
|
||||||
// c.HTML(http.StatusOK, "app_view.html", vm)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AppMiddleware(c *gin.Context) {
|
func AppMiddleware(c *gin.Context) {
|
||||||
|
|
@ -107,8 +95,18 @@ func CreateUpdateDeleteApp(c *gin.Context) {
|
||||||
|
|
||||||
func GetAppsController(c *gin.Context) {
|
func GetAppsController(c *gin.Context) {
|
||||||
username := c.MustGet("username").(string)
|
username := c.MustGet("username").(string)
|
||||||
apps := GetApps(username)
|
|
||||||
c.JSON(http.StatusOK, apps)
|
appsvm := funk.Map(GetApps(username), func(a AppModel) AppViewModel { return AppViewModel{AppModel: &a} }).([]AppViewModel)
|
||||||
|
for i := range appsvm {
|
||||||
|
a := &appsvm[i]
|
||||||
|
a.Status = statusString(a)
|
||||||
|
a.ServiceDisplayName = a.ServiceName()
|
||||||
|
}
|
||||||
|
vm := &AppsViewModel{
|
||||||
|
Username: username,
|
||||||
|
Apps: appsvm,
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, vm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUsername(c *gin.Context) {
|
func GetUsername(c *gin.Context) {
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label for="app-name" class="form-label">应用名</label>
|
<label for="app-name" class="form-label">应用名</label>
|
||||||
<input type="text" id="app-name" class="form-control" v-model="selectApp.AppName"
|
<input type="text" id="app-name" class="form-control" v-model="selectApp.AppName"
|
||||||
placeholder="只能为字母、数字和下划线"/>
|
placeholder="只能为小写字母、数字和下划线"/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -130,13 +130,18 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="position-fixed top-0 end-0 p-3" style="z-index: 11">
|
||||||
|
<div id="liveToast" class="toast alert-danger" role="alert" aria-live="assertive" aria-atomic="true">
|
||||||
|
<div class="toast-header">
|
||||||
|
<strong class="me-auto">请求失败</strong>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="toast-body">
|
||||||
|
{{ toastText }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- <div class="toast d-flex align-items-center top-0 end-0" id="success-toast">-->
|
|
||||||
<!-- <div class="toast-body">-->
|
|
||||||
<!-- <p id="toast-content"></p>-->
|
|
||||||
<!-- </div>-->
|
|
||||||
<!-- <button type="button" class="btn-close ms-auto me-2" data-bs-dismiss="toast" aria-label="Close"></button>-->
|
|
||||||
<!-- </div>-->
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
@ -150,6 +155,7 @@
|
||||||
username: "",
|
username: "",
|
||||||
apps: [],
|
apps: [],
|
||||||
blankApp: {},
|
blankApp: {},
|
||||||
|
toastText: "",
|
||||||
selectApp: {
|
selectApp: {
|
||||||
Id: "",
|
Id: "",
|
||||||
AppName: "",
|
AppName: "",
|
||||||
|
|
@ -164,6 +170,19 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
toast(text) {
|
||||||
|
this.toastText = text
|
||||||
|
let toastLiveExample = document.getElementById('liveToast')
|
||||||
|
let toast = new bootstrap.Toast(toastLiveExample)
|
||||||
|
toast.show()
|
||||||
|
},
|
||||||
|
handleResponse(e) {
|
||||||
|
if (e.data.msg !== "ok") {
|
||||||
|
this.toast(e.data.msg)
|
||||||
|
} else {
|
||||||
|
this.refresh()
|
||||||
|
}
|
||||||
|
},
|
||||||
showModal(a) {
|
showModal(a) {
|
||||||
if (!a) {
|
if (!a) {
|
||||||
a = JSON.parse(JSON.stringify(this.blankApp))
|
a = JSON.parse(JSON.stringify(this.blankApp))
|
||||||
|
|
@ -172,46 +191,36 @@
|
||||||
(new bootstrap.Modal("#edit-modal")).show()
|
(new bootstrap.Modal("#edit-modal")).show()
|
||||||
},
|
},
|
||||||
startApp(item) {
|
startApp(item) {
|
||||||
axios.post("dep?id=" + item.Id).then(e => {
|
axios.post("dep?id=" + item.Id).then(this.handleResponse)
|
||||||
console.log(e.data)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
deleteApp(app) {
|
deleteApp(app) {
|
||||||
axios.delete("app", {
|
axios.delete("app", {
|
||||||
data: app
|
data: app
|
||||||
}).then(e => {
|
}).then(this.handleResponse)
|
||||||
console.log(e.data)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
stopApp(app) {
|
stopApp(app) {
|
||||||
axios.delete("dep?id=" + app.Id).then(e => {
|
axios.delete("dep?id=" + app.Id).then(this.handleResponse)
|
||||||
console.log(e.data)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
updateApp() {
|
updateApp() {
|
||||||
let app = this.selectApp
|
let app = this.selectApp
|
||||||
if (app.Id) {
|
if (app.Id) {
|
||||||
axios.put("app", app).then(e => {
|
axios.put("app", app).then(this.handleResponse)
|
||||||
console.log(e)
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
app.Id = null
|
app.Id = null
|
||||||
app.UserName = this.username
|
app.UserName = this.username
|
||||||
axios.post("app", app).then(e => {
|
axios.post("app", app).then(this.handleResponse);
|
||||||
console.log(e)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
refresh() {
|
||||||
|
axios.get("apps").then(r => {
|
||||||
|
this.username = r.data.Username
|
||||||
|
this.apps = r.data.Apps
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.blankApp = JSON.parse(JSON.stringify(this.selectApp))
|
this.blankApp = JSON.parse(JSON.stringify(this.selectApp))
|
||||||
axios.get("username").then(r => {
|
this.refresh()
|
||||||
this.username = r.data.username
|
|
||||||
})
|
|
||||||
axios.get("apps").then(response => {
|
|
||||||
this.apps = response.data
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}).mount("#app")
|
}).mount("#app")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue