[agent-go] - 去除本地环境信息的默认设置,优化启动逻辑

This commit is contained in:
zeaslity
2024-04-28 16:41:44 +08:00
parent 88d75a704e
commit f124972b84
7 changed files with 83 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/go-playground/validator/v10"
"os"
"wdd.io/agent-common/logger"
"wdd.io/agent-common/utils"
"wdd.io/agent-operator/deploy/z_dep"
)
@@ -55,7 +56,7 @@ func init() {
func (backend *CmiiBackendConfig) BackendDeploy(common *z_dep.CommonEnvironmentConfig) bool {
// copy
z_dep.CopySameFields(common, backend)
utils.CopySameFields(common, backend)
validate := validator.New()
err := validate.Struct(backend)
@@ -84,7 +85,7 @@ func (backend *CmiiBackendConfig) BackendDeploy(common *z_dep.CommonEnvironmentC
func (frontend *CmiiFrontendConfig) FrontendDeploy(common *z_dep.CommonEnvironmentConfig) bool {
// copy
z_dep.CopySameFields(common, frontend)
utils.CopySameFields(common, frontend)
validate := validator.New()
err := validate.Struct(frontend)
@@ -106,7 +107,7 @@ func (frontend *CmiiFrontendConfig) FrontendDeploy(common *z_dep.CommonEnvironme
func (frontend *CmiiFrontendConfig) ConfigMapDeploy(commonEnv *z_dep.CommonEnvironmentConfig) bool {
// copy
z_dep.CopySameFields(commonEnv, frontend)
utils.CopySameFields(commonEnv, frontend)
// manual validate
if frontend.ShortName == "" || frontend.ClientId == "" {

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"github.com/go-playground/validator/v10"
"reflect"
"runtime"
"text/template"
"wdd.io/agent-common/assert"
@@ -104,16 +103,3 @@ func ParseEnvToApplyFile(environment any, applyTemplate string, applyFilePath st
return true
}
// CopySameFields 利用反射将a中的所有同名字段的值 复制到b中的对应字段
func CopySameFields(a, b interface{}) {
va := reflect.ValueOf(a).Elem()
vb := reflect.ValueOf(b).Elem()
for i := 0; i < va.NumField(); i++ {
fieldName := va.Type().Field(i).Name
if vb.FieldByName(fieldName).IsValid() {
vb.FieldByName(fieldName).Set(va.Field(i))
}
}
}