Merge pull request #1145 from yangkaa/560

Fix Bug: Repair SERVICE_NAME environment variable error
This commit is contained in:
yangkaa 2022-02-25 04:03:28 -06:00 committed by GitHub
commit ce00f55587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 38 additions and 18 deletions

View File

@ -643,9 +643,6 @@ func (a *ApplicationAction) SyncComponents(app *dbmodel.Application, components
if err := GetServiceManager().SyncComponentLabels(tx, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentScaleRules(tx, components); err != nil {
return err
}
if err := GetServiceManager().SyncComponentEndpoints(tx, components); err != nil {
return err
}

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

@ -366,7 +366,6 @@ func UpgradeIngress(clientset kubernetes.Interface,
ing, err), err); err != nil {
return err
}
continue
}
as.SetIngress(ing)
delete(oldMap, o.Name)
@ -387,7 +386,7 @@ func UpgradeIngress(clientset kubernetes.Interface,
}
for _, ing := range oldMap {
if ing != nil {
if err := clientset.ExtensionsV1beta1().Ingresses(ing.Namespace).Delete(context.Background(), ing.Name,
if err := clientset.NetworkingV1().Ingresses(ing.Namespace).Delete(context.Background(), ing.Name,
metav1.DeleteOptions{}); err != nil {
if err := handleErr(fmt.Sprintf("error deleting ingress: %+v: err: %v",
ing, err), err); err != nil {
@ -413,7 +412,6 @@ func UpgradeIngress(clientset kubernetes.Interface,
ing, err), err); err != nil {
return err
}
continue
}
as.SetIngress(ing)
delete(oldBetaMap, o.Name)
@ -466,7 +464,6 @@ func UpgradeSecrets(clientset kubernetes.Interface,
sec, err), err); err != nil {
return err
}
continue
}
as.SetSecret(sec)
delete(oldMap, 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++
}

View File

@ -119,7 +119,10 @@ func (g *GarbageCollector) DelKubernetesObjects(serviceGCReq model.ServiceGCTask
logrus.Warningf("[DelKubernetesObjects] delete statefulsets(%s): %v", serviceGCReq.ServiceID, err)
}
if err := g.clientset.ExtensionsV1beta1().Ingresses(namespace).DeleteCollection(context.Background(), deleteOpts, listOpts); err != nil {
logrus.Warningf("[DelKubernetesObjects] delete ingresses(%s): %v", serviceGCReq.ServiceID, err)
logrus.Warningf("[DelKubernetesObjects] delete extensions ingresses(%s): %v", serviceGCReq.ServiceID, err)
}
if err := g.clientset.NetworkingV1().Ingresses(namespace).DeleteCollection(context.Background(), deleteOpts, listOpts); err != nil {
logrus.Warningf("[DelKubernetesObjects] delete networking ingresses(%s): %v", serviceGCReq.ServiceID, err)
}
if err := g.clientset.CoreV1().Secrets(namespace).DeleteCollection(context.Background(), deleteOpts, listOpts); err != nil {
logrus.Warningf("[DelKubernetesObjects] delete secrets(%s): %v", serviceGCReq.ServiceID, err)