mirror of
https://gitee.com/devstar/devstar-devcontainer-operator
synced 2025-09-16 03:31:07 +00:00
Replaced Nginx Ingress Controller with NodePort Service
This commit is contained in:
@@ -7,13 +7,19 @@ import (
|
||||
devcontainer_apps_v1 "devstar.cn/DevcontainerApp/api/v1"
|
||||
app_v1 "k8s.io/api/apps/v1"
|
||||
core_v1 "k8s.io/api/core/v1"
|
||||
networking_v1 "k8s.io/api/networking/v1"
|
||||
yaml_util "k8s.io/apimachinery/pkg/util/yaml"
|
||||
)
|
||||
|
||||
const (
|
||||
TemplatePath = "internal/controller/templates/"
|
||||
)
|
||||
|
||||
// parseTemplate 解析 Go Template 模板文件
|
||||
func parseTemplate(templateName string, app *devcontainer_apps_v1.DevcontainerApp) []byte {
|
||||
tmpl, err := template.ParseFiles("internal/controller/templates/" + templateName + ".yaml")
|
||||
tmpl, err := template.
|
||||
New(templateName + ".yaml").
|
||||
Funcs(template.FuncMap{"default": DefaultFunc}).
|
||||
ParseFiles(TemplatePath + templateName + ".yaml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -25,7 +31,7 @@ func parseTemplate(templateName string, app *devcontainer_apps_v1.DevcontainerAp
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
// NewStatefulSet 根据创建 StatefulSet
|
||||
// NewStatefulSet 创建 StatefulSet
|
||||
func NewStatefulSet(app *devcontainer_apps_v1.DevcontainerApp) *app_v1.StatefulSet {
|
||||
statefulSet := &app_v1.StatefulSet{}
|
||||
err := yaml_util.Unmarshal(parseTemplate("statefulset", app), statefulSet)
|
||||
@@ -45,12 +51,10 @@ func NewService(app *devcontainer_apps_v1.DevcontainerApp) *core_v1.Service {
|
||||
return service
|
||||
}
|
||||
|
||||
// NewIngress 创建新的 Ingress Controller 规则
|
||||
func NewIngress(app *devcontainer_apps_v1.DevcontainerApp) *networking_v1.Ingress {
|
||||
ingress := &networking_v1.Ingress{}
|
||||
err := yaml_util.Unmarshal(parseTemplate("ingress", app), ingress)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
// DefaultFunc 函数用于实现默认值
|
||||
func DefaultFunc(value interface{}, defaultValue interface{}) interface{} {
|
||||
if value == nil || value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
return ingress
|
||||
return value
|
||||
}
|
||||
|
Reference in New Issue
Block a user