This commit is contained in:
w-mj 2023-02-28 15:02:06 +08:00
parent ae28a70c71
commit ac7329479f
No known key found for this signature in database
GPG Key ID: 3A2CB5BE2F835897
3 changed files with 34 additions and 19 deletions

View File

@ -37,6 +37,14 @@ spec:
value: 192.168.252.250
- name: NFS_PATH
value: /mnt/CGdata/ms
volumeMounts:
- name: k8s-manager-nfs-volume
mountPath: /mnt/CGdata/ms
volumes:
- name: k8s-manager-nfs-volume
nfs:
server: 192.168.252.250
path: /mnt/CGdata/ms
---
apiVersion: v1
kind: Service

10
main.go
View File

@ -41,7 +41,7 @@ func main() {
r.POST("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
r.DELETE("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment)
r.GET("/login", Test)
r.GET("/login", LoginToken)
r.Any("/test_token", TestToken)
r.GET("/username", m.JWTAuthMiddleware, m.GetUsername)
err := r.Run(":8000")
@ -135,7 +135,7 @@ func AesDecrypt(data []byte, key []byte) ([]byte, error) {
return crypted, nil
}
func Test(c *gin.Context) {
func LoginToken(c *gin.Context) {
username := c.Request.URL.Query().Get("username")
var err error
if username == "" {
@ -147,6 +147,11 @@ func Test(c *gin.Context) {
"msg": "user name error",
})
} else {
Login(c, username)
}
}
func Login(c *gin.Context, username string) {
token, err := m.GenerateToken(username)
if err != nil {
log.Error(err)
@ -164,7 +169,6 @@ func Test(c *gin.Context) {
redirectUrl = fmt.Sprintf("/%s/index", os.Getenv("URL_PREFIX"))
}
c.Redirect(http.StatusTemporaryRedirect, redirectUrl)
}
}
func TestToken(c *gin.Context) {

View File

@ -74,6 +74,9 @@ func (c *K8sClient) DeploymentExists(deploymentName string) bool {
func (c *K8sClient) UpdateDeployment(app *AppModel) {
labelKey, labelValue := app.GetLabel()
l := map[string]string{labelKey: labelValue}
if _, err := os.Stat(app.NFSPath()); os.IsNotExist(err) {
os.MkdirAll(app.NFSPath(), os.ModeDir)
}
podLabels := map[string]string{
labelKey: labelValue,
"cg-deployment": app.DeploymentName(),