Repair SERVICE_NAME environment variable error

This commit is contained in:
yangk 2022-01-20 22:14:50 +08:00
parent 0de2202a98
commit 3f367ed851
11 changed files with 33 additions and 11 deletions

View File

@ -58,7 +58,7 @@ type DependServiceHealthController struct {
func NewDependServiceHealthController() (*DependServiceHealthController, error) {
clusterID := os.Getenv("ENVOY_NODE_ID")
if clusterID == "" {
clusterID = fmt.Sprintf("%s_%s_%s", os.Getenv("NAMESPACE"), os.Getenv("PLUGIN_ID"), os.Getenv("SERVICE_NAME"))
clusterID = fmt.Sprintf("%s_%s_%s", os.Getenv("NAMESPACE"), os.Getenv("PLUGIN_ID"), os.Getenv("SERVICE_ALIAS"))
}
dsc := DependServiceHealthController{
interval: time.Second * 5,

View File

@ -138,7 +138,7 @@ func run() error {
}
func discoverConfig() *api_model.ResourceSpec {
discoverURL := fmt.Sprintf("http://%s:6100/v1/resources/%s/%s/%s", os.Getenv("XDS_HOST_IP"), os.Getenv("NAMESPACE"), os.Getenv("SERVICE_NAME"), os.Getenv("PLUGIN_ID"))
discoverURL := fmt.Sprintf("http://%s:6100/v1/resources/%s/%s/%s", os.Getenv("XDS_HOST_IP"), os.Getenv("NAMESPACE"), os.Getenv("SERVICE_ALIAS"), os.Getenv("PLUGIN_ID"))
http.DefaultClient.Timeout = time.Second * 5
res, err := http.Get(discoverURL)
if err != nil {

View File

@ -135,6 +135,7 @@ type TenantServiceDao interface {
GetServiceByServiceAlias(serviceAlias string) (*model.TenantServices, error)
GetServiceByIDs(serviceIDs []string) ([]*model.TenantServices, error)
GetServiceAliasByIDs(uids []string) ([]*model.TenantServices, error)
GetWorkloadNameByIDs(uids []string) ([]*model.ComponentWorkload, error)
GetServiceByTenantIDAndServiceAlias(tenantID, serviceName string) (*model.TenantServices, error)
SetTenantServiceStatus(serviceID, status string) error
GetServicesByTenantID(tenantID string) ([]*model.TenantServices, error)

View File

@ -205,6 +205,14 @@ type TenantServices struct {
K8sComponentName string `gorm:"column:k8s_component_name" json:"k8s_component_name"`
}
// ComponentWorkload -
type ComponentWorkload struct {
K8sApp string `gorm:"column:k8s_app"`
K8sComponentName string `gorm:"column:k8s_component_name"`
ComponentID string `gorm:"column:service_id"`
ServiceAlias string `gorm:"column:service_alias"`
}
//Image 镜像
type Image struct {
Host string

View File

@ -402,6 +402,19 @@ func (t *TenantServicesDaoImpl) GetServiceAliasByIDs(uids []string) ([]*model.Te
return services, nil
}
// GetWorkloadNameByIDs -
func (t *TenantServicesDaoImpl) GetWorkloadNameByIDs(uids []string) ([]*model.ComponentWorkload, error) {
var componentWorkload []*model.ComponentWorkload
if err := t.DB.Model(&model.TenantServices{}).
Select("applications.k8s_app, tenant_services.k8s_component_name, tenant_services.service_id, tenant_services.service_alias").
Joins("join applications on applications.app_id=tenant_services.app_id").
Where("service_id in (?)", uids).
Scan(&componentWorkload).Error; err != nil {
return nil, err
}
return componentWorkload, nil
}
//GetServiceByIDs get some service by service ids
func (t *TenantServicesDaoImpl) GetServiceByIDs(uids []string) ([]*model.TenantServices, error) {
var services []*model.TenantServices

View File

@ -2,4 +2,4 @@ VERSION=5.1
image:
docker build -t rainbond/plugin_mesh:${VERSION} .
test:
docker run -e XDS_HOST_IP=192.168.1.112 -e TENANT_ID=5dbea040f5cb437c82e3bf02943fb02e -e PLUGIN_ID=c5618104b2aa4c508390e4f18f316500 -e SERVICE_NAME=gr439125 --rm -it rainbond/plugin_mesh:5.1
docker run -e XDS_HOST_IP=192.168.1.112 -e TENANT_ID=5dbea040f5cb437c82e3bf02943fb02e -e PLUGIN_ID=c5618104b2aa4c508390e4f18f316500 -e SERVICE_ALIAS=gr439125 --rm -it rainbond/plugin_mesh:5.1

View File

@ -9,7 +9,7 @@ elif [ "$1" = "run" ]; then
/root/rainbond-mesh-data-panel run || exit 1
else
env2file conversion -f /root/envoy_config.yaml
cluster_name=${NAMESPACE}_${PLUGIN_ID}_${SERVICE_NAME}
cluster_name=${NAMESPACE}_${PLUGIN_ID}_${SERVICE_ALIAS}
# start sidecar process
/root/rainbond-mesh-data-panel &
# start envoy process

View File

@ -516,7 +516,7 @@ func (a *AppServiceBuild) createStatefulService(ports []*model.TenantServicesPor
}
spec := corev1.ServiceSpec{
Ports: serviceports,
Selector: map[string]string{"name": a.appService.GetK8sWorkloadName()},
Selector: map[string]string{"name": a.service.ServiceAlias},
ClusterIP: "None",
PublishNotReadyAddresses: true,
}

View File

@ -224,7 +224,7 @@ func createEnv(as *v1.AppService, dbmanager db.Manager, envVarSecrets []*corev1.
envsAll = append(envsAll, es...)
}
serviceAliases, err := dbmanager.TenantServiceDao().GetServiceAliasByIDs(relationIDs)
serviceAliases, err := dbmanager.TenantServiceDao().GetWorkloadNameByIDs(relationIDs)
if err != nil {
return nil, err
}
@ -234,9 +234,9 @@ func createEnv(as *v1.AppService, dbmanager db.Manager, envVarSecrets []*corev1.
if Depend != "" {
Depend += ","
}
Depend += fmt.Sprintf("%s:%s", sa.ServiceAlias, sa.ServiceID)
Depend += fmt.Sprintf("%s-%s:%s", sa.K8sApp, sa.K8sComponentName, sa.ComponentID)
if bootSeqDepServiceIDs != "" && strings.Contains(bootSeqDepServiceIDs, sa.ServiceID) {
if bootSeqDepServiceIDs != "" && strings.Contains(bootSeqDepServiceIDs, sa.ComponentID) {
startupSequenceDependencies = append(startupSequenceDependencies, sa.ServiceAlias)
}
}
@ -318,7 +318,8 @@ func createEnv(as *v1.AppService, dbmanager db.Manager, envVarSecrets []*corev1.
envs = append(envs, corev1.EnvVar{Name: "TENANT_ID", Value: as.TenantID})
envs = append(envs, corev1.EnvVar{Name: "SERVICE_ID", Value: as.ServiceID})
envs = append(envs, corev1.EnvVar{Name: "MEMORY_SIZE", Value: envutil.GetMemoryType(as.ContainerMemory)})
envs = append(envs, corev1.EnvVar{Name: "SERVICE_NAME", Value: as.ServiceAlias})
envs = append(envs, corev1.EnvVar{Name: "SERVICE_NAME", Value: as.GetK8sWorkloadName()})
envs = append(envs, corev1.EnvVar{Name: "SERVICE_ALIAS", Value: as.ServiceAlias})
envs = append(envs, corev1.EnvVar{Name: "SERVICE_POD_NUM", Value: strconv.Itoa(as.Replicas)})
envs = append(envs, corev1.EnvVar{Name: "HOST_IP", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{

View File

@ -412,7 +412,6 @@ func UpgradeIngress(clientset kubernetes.Interface,
ing, err), err); err != nil {
return err
}
continue
}
as.SetIngress(ing)
delete(oldBetaMap, o.Name)

View File

@ -1159,7 +1159,7 @@ func getServiceInfoFromPod(pod *corev1.Pod) v1.AbnormalInfo {
ai.ServiceID = env.Value
i++
}
if env.Name == "SERVICE_NAME" {
if env.Name == "SERVICE_ALIAS" {
ai.ServiceAlias = env.Value
i++
}