This repository has been archived on 2026-05-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
educode-controller/internal/api/pvc.go
2025-07-17 18:55:34 +08:00

47 lines
1.3 KiB
Go

package api
import (
"net/http"
"gitea.starryskymeow.cn/xkm/educode-controller/internal/k8s"
"gitea.starryskymeow.cn/xkm/educode-controller/internal/types"
"github.com/gin-gonic/gin"
)
func (h *Handler) createPvc(c *gin.Context) {
var req types.Pvc
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": err.Error()})
return
}
if !isValidDNS1035Label(req.ID) {
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123')"})
return
}
err := k8s.CreatePvc(req, h.clientset)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "message": err.Error()})
return
}
c.JSON(http.StatusAccepted, gin.H{"success": true})
}
func (h *Handler) deletePvc(c *gin.Context) {
ID := c.Param("ID")
err := k8s.DeletePvc(ID, h.clientset)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "message": err.Error()})
return
}
c.JSON(http.StatusAccepted, gin.H{"success": true})
}
func (h *Handler) getPvcByID(c *gin.Context) {
// TODO
}
func (h *Handler) getPvc(c *gin.Context) {
// TODO
}