139 lines
4.2 KiB
Go
139 lines
4.2 KiB
Go
package c_app
|
|
|
|
import (
|
|
"github.com/go-playground/validator/v10"
|
|
"wdd.io/agent-common/logger"
|
|
"wdd.io/agent-operator/deploy/z_dep"
|
|
)
|
|
|
|
var log = logger.Log
|
|
|
|
type CmiiBackendConfig struct {
|
|
z_dep.CommonEnvironmentConfig
|
|
AppName string `json:"app_name,omitempty" validate:"required"`
|
|
ImageTag string `json:"image_tag,omitempty" validate:"required"`
|
|
Replicas string `json:"replicas,omitempty" validate:"required" default:"1"`
|
|
NodePort string `json:"node_port,omitempty"`
|
|
NeedPvcCache bool `json:"need_pvc_cache,omitempty"`
|
|
CustomJvmOpt string `json:"custom_jvm_opt,omitempty"`
|
|
}
|
|
|
|
type CmiiFrontendConfig struct {
|
|
z_dep.CommonEnvironmentConfig `json:"z___dep_._common_environment_config"`
|
|
AppName string `json:"app_name,omitempty" validate:"required"`
|
|
ImageTag string `json:"image_tag,omitempty" validate:"required"`
|
|
Replicas string `json:"replicas,omitempty" validate:"required" default:"1"`
|
|
ShortName string `json:"short_name,omitempty"`
|
|
ClientId string
|
|
}
|
|
|
|
var (
|
|
DefaultCmiiBackendConfig = &CmiiBackendConfig{}
|
|
DefaultCmiiFrontendConfig = &CmiiFrontendConfig{}
|
|
BackendApplyFilePath = ""
|
|
FrontendApplyFilePath = ""
|
|
SRSApplyFilePath = ""
|
|
IngresApplyFilePath = ""
|
|
ConfigMapApplyFilePath = ""
|
|
)
|
|
|
|
func init() {
|
|
BackendApplyFilePath = z_dep.ApplyFilePrefix + "k8s-backend.yaml"
|
|
FrontendApplyFilePath = z_dep.ApplyFilePrefix + "k8s-frontend.yaml"
|
|
SRSApplyFilePath = z_dep.ApplyFilePrefix + "k8s-srs.yaml"
|
|
IngresApplyFilePath = z_dep.ApplyFilePrefix + "k8s-ingress.yaml"
|
|
ConfigMapApplyFilePath = z_dep.ApplyFilePrefix + "k8s-configmap.yaml"
|
|
|
|
log.DebugF("backend apply file path: %s\n", BackendApplyFilePath)
|
|
log.DebugF("frontend apply file path: %s\n", FrontendApplyFilePath)
|
|
log.DebugF("srs apply file path: %s\n", SRSApplyFilePath)
|
|
log.DebugF("ingress apply file path: %s\n", IngresApplyFilePath)
|
|
log.DebugF("config map apply file path: %s\n", ConfigMapApplyFilePath)
|
|
}
|
|
|
|
func (backend *CmiiBackendConfig) BackendDeploy(common *z_dep.CommonEnvironmentConfig) bool {
|
|
|
|
// copy
|
|
z_dep.CopySameFields(common, backend)
|
|
|
|
validate := validator.New()
|
|
err := validate.Struct(backend)
|
|
if err != nil {
|
|
log.ErrorF("backend config validate error: %v\n", err)
|
|
return false
|
|
}
|
|
|
|
if !z_dep.ParseEnvToApplyFile(backend, CmiiBackendDeploymentTemplate, BackendApplyFilePath) {
|
|
return false
|
|
}
|
|
if !z_dep.ParseEnvToApplyFile(backend, CmiiBackendServiceTemplate, BackendApplyFilePath) {
|
|
return false
|
|
}
|
|
|
|
// pvc
|
|
if backend.NeedPvcCache {
|
|
if !z_dep.ParseEnvToApplyFile(backend, CmiiBackendPVCTemplate, BackendApplyFilePath) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func (frontend *CmiiFrontendConfig) FrontendDeploy(common *z_dep.CommonEnvironmentConfig) bool {
|
|
|
|
// copy
|
|
z_dep.CopySameFields(common, frontend)
|
|
|
|
validate := validator.New()
|
|
err := validate.Struct(frontend)
|
|
if err != nil {
|
|
log.ErrorF("backend config validate error: %v\n", err)
|
|
return false
|
|
}
|
|
|
|
if !z_dep.ParseEnvToApplyFile(frontend, CmiiFrontendDeploymentTemplate, FrontendApplyFilePath) {
|
|
return false
|
|
}
|
|
if !z_dep.ParseEnvToApplyFile(frontend, CmiiFrontendServiceTemplate, FrontendApplyFilePath) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func (frontend *CmiiFrontendConfig) ConfigMapDeploy(commonEnv *z_dep.CommonEnvironmentConfig) bool {
|
|
|
|
// copy
|
|
z_dep.CopySameFields(commonEnv, frontend)
|
|
|
|
// manual validate
|
|
if frontend.ShortName == "" || frontend.ClientId == "" {
|
|
log.ErrorF("short name or client id is empty !")
|
|
return false
|
|
}
|
|
|
|
return z_dep.ParseEnvToApplyFile(frontend, CmiiFrontendConfigMapTemplate, ConfigMapApplyFilePath)
|
|
}
|
|
|
|
func IngressDeploy(commonEnv *z_dep.CommonEnvironmentConfig) bool {
|
|
if !commonEnv.ParseCommonEnvToApplyFile(CmiiFrontendIngressTemplate, IngresApplyFilePath) {
|
|
return false
|
|
}
|
|
|
|
if !commonEnv.ParseCommonEnvToApplyFile(CmiiBackendIngressTemplate, IngresApplyFilePath) {
|
|
return false
|
|
}
|
|
|
|
if !commonEnv.ParseCommonEnvToApplyFile(CmiiGatewayIngressTemplate, IngresApplyFilePath) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func SrsDeploy(commonEnv *z_dep.CommonEnvironmentConfig) bool {
|
|
|
|
return commonEnv.ParseCommonEnvToApplyFile(CmiiSrsTemplate, SRSApplyFilePath)
|
|
}
|