show pod status

This commit is contained in:
w-mj 2023-02-28 17:20:34 +08:00
parent ac7329479f
commit c523ef2a01
No known key found for this signature in database
GPG Key ID: 3A2CB5BE2F835897
5 changed files with 82 additions and 25 deletions

View File

@ -41,6 +41,8 @@ func main() {
r.POST("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment) r.POST("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
r.DELETE("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment) r.DELETE("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
r.GET("/pod", m.JWTAuthMiddleware, m.GetPodStatus)
r.GET("/login", LoginToken) r.GET("/login", LoginToken)
r.Any("/test_token", TestToken) r.Any("/test_token", TestToken)
r.GET("/username", m.JWTAuthMiddleware, m.GetUsername) r.GET("/username", m.JWTAuthMiddleware, m.GetUsername)

View File

@ -49,3 +49,20 @@ func CreateDeleteDeployment(c *gin.Context) {
} }
c.JSON(http.StatusOK, gin.H{"msg": "ok"}) 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)
}

View File

@ -109,30 +109,30 @@ func (c *K8sClient) UpdateDeployment(app *AppModel) {
Name: "URL_PREFIX", Name: "URL_PREFIX",
Value: app.ServiceName(), Value: app.ServiceName(),
}), }),
VolumeMounts: []v1.VolumeMount{ //VolumeMounts: []v1.VolumeMount{
{ // {
Name: app.PersistentVolumeMountName(), // Name: app.PersistentVolumeMountName(),
ReadOnly: false, // ReadOnly: false,
MountPath: app.PersistentPath, // MountPath: app.PersistentPath,
}, // },
}, //},
Ports: containerPorts, Ports: containerPorts,
SecurityContext: &v1.SecurityContext{ SecurityContext: &v1.SecurityContext{
RunAsUser: UnnamedPointer(int64(0)), RunAsUser: UnnamedPointer(int64(0)),
}, },
}}, }},
Volumes: []v1.Volume{ //Volumes: []v1.Volume{
{ // {
Name: app.PersistentVolumeMountName(), // Name: app.PersistentVolumeMountName(),
VolumeSource: v1.VolumeSource{ // VolumeSource: v1.VolumeSource{
NFS: &v1.NFSVolumeSource{ // NFS: &v1.NFSVolumeSource{
Server: config.NFSHost, // Server: config.NFSHost,
Path: app.NFSPath(), // Path: app.NFSPath(),
ReadOnly: false, // ReadOnly: false,
}, // },
}, // },
}, // },
}, //},
}, },
}, },
}, },

View File

@ -33,6 +33,9 @@ func opendb() *gorm.DB {
func checkdb(cnt int) *gorm.DB { func checkdb(cnt int) *gorm.DB {
ans := opendb() ans := opendb()
if ans == nil {
return nil
}
db, err := ans.DB() db, err := ans.DB()
if err != nil { if err != nil {
logrus.WithError(err).Error("Cannot get *sql.DB.") logrus.WithError(err).Error("Cannot get *sql.DB.")

View File

@ -48,7 +48,14 @@
<td> {{ item.Image }}</td> <td> {{ item.Image }}</td>
<td> {{ item.Command }}</td> <td> {{ item.Command }}</td>
<td> {{ item.Env }}</td> <td> {{ item.Env }}</td>
<td> {{ item.Status }}</td> <td>
<span v-if="item.Status == 'Halt'">
{{ item.Status }}
</span>
<span v-else>
<a href="javascript:void(0)" @click="showPodStatus(item)">{{ item.Status }}</a>
</span>
</td>
<td><a :href="'/' + item.ServiceDisplayName + '/'" target="_blank">{{ item.ServiceDisplayName }}</a></td> <td><a :href="'/' + item.ServiceDisplayName + '/'" target="_blank">{{ item.ServiceDisplayName }}</a></td>
<td> {{ item.Ports }}</td> <td> {{ item.Ports }}</td>
<td> <td>
@ -117,7 +124,8 @@
<div class="row"> <div class="row">
<label for="app-ports" class="form-label">持久化路径</label> <label for="app-ports" class="form-label">持久化路径</label>
<input type="text" id="app-persistent-path" class="form-control" v-model="selectApp.PersistentPath" <input type="text" id="app-persistent-path" class="form-control"
v-model="selectApp.PersistentPath"
placeholder="持久化路径"/> placeholder="持久化路径"/>
</div> </div>
@ -142,13 +150,27 @@
<strong class="me-auto">请求失败</strong> <strong class="me-auto">请求失败</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div> </div>
<div class="toast-body"> <div class="toast-body" v-html="toastText">
{{ toastText }}
</div> </div>
</div> </div>
</div> </div>
<div class="modal" tabindex="-1" id="pod-status-modal">
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-header">
Pod详情
</div>
<div class="modal-content">{{ podStatus }}</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div> </div>
</body> </body>
@ -173,7 +195,9 @@
SvcName: "", SvcName: "",
PersistentPath: "", PersistentPath: "",
Ports: "", Ports: "",
} },
timer: null,
podStatus: ""
} }
}, },
methods: { methods: {
@ -223,11 +247,22 @@
this.username = r.data.Username this.username = r.data.Username
this.apps = r.data.Apps 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() { mounted() {
this.blankApp = JSON.parse(JSON.stringify(this.selectApp)) this.blankApp = JSON.parse(JSON.stringify(this.selectApp))
this.refresh() this.refresh()
if (this.timer) {
clearInterval(this.timer)
this.timer = null
}
setInterval(this.timer, this.refresh, 5000)
} }
}).mount("#app") }).mount("#app")