From 3d53d3a83c46628e71d0345029ef3fe33c4eaa43 Mon Sep 17 00:00:00 2001 From: w-mj Date: Wed, 22 Mar 2023 21:59:21 +0800 Subject: [PATCH] disable service name --- DESIGN.md | 1 + Makefile | 2 +- src/controller/app_controller.go | 2 +- src/model/app_model.go | 9 ++++++++- src/service/k8s_service.go | 4 ++-- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/DESIGN.md b/DESIGN.md index 008d7fd..ba5a97c 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -3,6 +3,7 @@ ## 数据管理 - 来自NFS的数据 - 来自数据库的数据 +- 我的数据 (WebDav挂载) ## 应用管理 ### 创建应用 - 通过在线实验工作台 diff --git a/Makefile b/Makefile index e8832f4..aa0fb31 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -TAG ?= v1.2.1 +TAG ?= v1.2.2 IMAGE_TAG ?= docker.educg.net/cg/k8s-manager:$(TAG) build: export CGO_ENABLED=0 diff --git a/src/controller/app_controller.go b/src/controller/app_controller.go index 81d2237..a4bc488 100644 --- a/src/controller/app_controller.go +++ b/src/controller/app_controller.go @@ -104,7 +104,7 @@ func GetAppsController(c *gin.Context) { for i := range appsvm { a := &appsvm[i] a.Status = statusString(a) - a.ServiceDisplayName = a.ServiceName() + a.ServiceDisplayName = a.URLPrefix() } vm := &AppsViewModel{ Username: username, diff --git a/src/model/app_model.go b/src/model/app_model.go index 9e9038f..b46d9d9 100644 --- a/src/model/app_model.go +++ b/src/model/app_model.go @@ -25,6 +25,7 @@ type AppModel struct { CreateTime time.Time UpdateTime time.Time IsPublished bool + AppType string } func (*AppModel) TableName() string { @@ -122,7 +123,9 @@ func (a *AppModel) DeploymentName() string { func (a *AppModel) GetCommandOrBlack() []string { if strings.TrimSpace(a.Command) != "" { - return []string{"/bin/sh", "-c", a.Command} + t := a.Command + t = strings.ReplaceAll(t, "$URL_PREFIX", a.URLPrefix()) + return []string{"/bin/sh", "-c", t} } else { return nil } @@ -169,6 +172,10 @@ func (a *AppModel) IngressName() string { return fmt.Sprintf("%s-ingress", a.NamePrefix()) } +func (a *AppModel) URLPrefix() string { + return a.ServiceName() +} + func (a *AppModel) PersistentVolumeName() string { return a.UserName + "-pv" } diff --git a/src/service/k8s_service.go b/src/service/k8s_service.go index a35ffea..c86d2e8 100644 --- a/src/service/k8s_service.go +++ b/src/service/k8s_service.go @@ -111,7 +111,7 @@ func (c *K8sClient) UpdateDeployment(app *model.AppModel) { Command: app.GetCommandOrBlack(), Env: append(app.GetEnv(), v1.EnvVar{ Name: "URL_PREFIX", - Value: app.ServiceName(), + Value: app.URLPrefix(), }), VolumeMounts: []v1.VolumeMount{ { @@ -322,7 +322,7 @@ func (c *K8sClient) UpdateIngress(a *model.AppModel) { HTTP: &netv1.HTTPIngressRuleValue{ Paths: []netv1.HTTPIngressPath{ { - Path: "/svc/" + a.ServiceName() + "(/|$)(.*)", + Path: "/svc/" + a.URLPrefix() + "(/|$)(.*)", PathType: k8s_manager.UnnamedPointer(netv1.PathTypePrefix), Backend: netv1.IngressBackend{ Service: &netv1.IngressServiceBackend{