diff --git a/main.go b/main.go index f0fb63a..bb6a127 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,8 @@ func main() { r.POST("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment) r.DELETE("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment) + r.GET("/pod", m.JWTAuthMiddleware, m.GetPodStatus) + r.GET("/login", LoginToken) r.Any("/test_token", TestToken) r.GET("/username", m.JWTAuthMiddleware, m.GetUsername) diff --git a/src/deployment_manager.go b/src/deployment_manager.go index f67ccf8..b86f0bf 100644 --- a/src/deployment_manager.go +++ b/src/deployment_manager.go @@ -49,3 +49,20 @@ func CreateDeleteDeployment(c *gin.Context) { } c.JSON(http.StatusOK, gin.H{"msg": "ok"}) } + +func GetPodStatus(c *gin.Context) { + id := c.Query("id") + if strings.TrimSpace(id) == "" { + c.JSON(http.StatusBadRequest, gin.H{"msg": "no app id"}) + return + } + appId, err := strconv.Atoi(id) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"msg": "wrong id"}) + return + } + app := AppModel{Id: appId} + app.Fill() + pod := K.GetPodFromDeployment(app.DeploymentName()) + c.JSON(http.StatusOK, pod.Status) +} diff --git a/src/k8s_client.go b/src/k8s_client.go index 61cb7cf..526b65f 100644 --- a/src/k8s_client.go +++ b/src/k8s_client.go @@ -109,30 +109,30 @@ func (c *K8sClient) UpdateDeployment(app *AppModel) { Name: "URL_PREFIX", Value: app.ServiceName(), }), - VolumeMounts: []v1.VolumeMount{ - { - Name: app.PersistentVolumeMountName(), - ReadOnly: false, - MountPath: app.PersistentPath, - }, - }, + //VolumeMounts: []v1.VolumeMount{ + // { + // Name: app.PersistentVolumeMountName(), + // ReadOnly: false, + // MountPath: app.PersistentPath, + // }, + //}, Ports: containerPorts, SecurityContext: &v1.SecurityContext{ RunAsUser: UnnamedPointer(int64(0)), }, }}, - Volumes: []v1.Volume{ - { - Name: app.PersistentVolumeMountName(), - VolumeSource: v1.VolumeSource{ - NFS: &v1.NFSVolumeSource{ - Server: config.NFSHost, - Path: app.NFSPath(), - ReadOnly: false, - }, - }, - }, - }, + //Volumes: []v1.Volume{ + // { + // Name: app.PersistentVolumeMountName(), + // VolumeSource: v1.VolumeSource{ + // NFS: &v1.NFSVolumeSource{ + // Server: config.NFSHost, + // Path: app.NFSPath(), + // ReadOnly: false, + // }, + // }, + // }, + //}, }, }, }, diff --git a/src/orm.go b/src/orm.go index d395699..1b25cb7 100644 --- a/src/orm.go +++ b/src/orm.go @@ -33,6 +33,9 @@ func opendb() *gorm.DB { func checkdb(cnt int) *gorm.DB { ans := opendb() + if ans == nil { + return nil + } db, err := ans.DB() if err != nil { logrus.WithError(err).Error("Cannot get *sql.DB.") diff --git a/template/app_view.html b/template/app_view.html index fa10ba3..0f5d874 100644 --- a/template/app_view.html +++ b/template/app_view.html @@ -48,8 +48,15 @@ {{ item.Image }} {{ item.Command }} {{ item.Env }} - {{ item.Status }} - {{ item.ServiceDisplayName }} + + + {{ item.Status }} + + + {{ item.Status }} + + + {{ item.ServiceDisplayName }} {{ item.Ports }}
@@ -117,7 +124,8 @@
-
@@ -142,13 +150,27 @@ 请求失败
-
- {{ toastText }} +
+ + + @@ -173,7 +195,9 @@ SvcName: "", PersistentPath: "", Ports: "", - } + }, + timer: null, + podStatus: "" } }, methods: { @@ -223,11 +247,22 @@ this.username = r.data.Username this.apps = r.data.Apps }) + }, + showPodStatus(app) { + axios.get("pod?id=" + app.Id).then(r => { + this.podStatus = JSON.stringify(r.data, null, 2); + (new bootstrap.Modal("#pod-status-modal")).show(); + }); } }, mounted() { this.blankApp = JSON.parse(JSON.stringify(this.selectApp)) this.refresh() + if (this.timer) { + clearInterval(this.timer) + this.timer = null + } + setInterval(this.timer, this.refresh, 5000) } }).mount("#app")