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.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)

View File

@ -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)
}

View File

@ -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,
// },
// },
// },
//},
},
},
},

View File

@ -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.")

View File

@ -48,8 +48,15 @@
<td> {{ item.Image }}</td>
<td> {{ item.Command }}</td>
<td> {{ item.Env }}</td>
<td> {{ item.Status }}</td>
<td> <a :href="'/' + item.ServiceDisplayName + '/'" target="_blank">{{ item.ServiceDisplayName }}</a></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> {{ item.Ports }}</td>
<td>
<div class="btn-group">
@ -117,7 +124,8 @@
<div class="row">
<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="持久化路径"/>
</div>
@ -142,13 +150,27 @@
<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 class="toast-body" v-html="toastText">
</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>
</body>
@ -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")