diff --git a/api/handler/application_handler.go b/api/handler/application_handler.go index 84e9fba0a..48dc8c41c 100644 --- a/api/handler/application_handler.go +++ b/api/handler/application_handler.go @@ -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 } diff --git a/cmd/init-probe/healthy/depends_health.go b/cmd/init-probe/healthy/depends_health.go index e2f8f9edc..3f819d9b6 100644 --- a/cmd/init-probe/healthy/depends_health.go +++ b/cmd/init-probe/healthy/depends_health.go @@ -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, diff --git a/cmd/mesh-data-panel/sidecar.go b/cmd/mesh-data-panel/sidecar.go index c6d7d3718..e2ce209e5 100644 --- a/cmd/mesh-data-panel/sidecar.go +++ b/cmd/mesh-data-panel/sidecar.go @@ -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 { diff --git a/db/dao/dao.go b/db/dao/dao.go index 60727fcdf..4cdcc1745 100644 --- a/db/dao/dao.go +++ b/db/dao/dao.go @@ -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) diff --git a/db/model/tenant.go b/db/model/tenant.go index 3bb0b7906..0e237c88f 100644 --- a/db/model/tenant.go +++ b/db/model/tenant.go @@ -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 diff --git a/db/mysql/dao/tenants.go b/db/mysql/dao/tenants.go index 9b10a8ebe..5c6970271 100644 --- a/db/mysql/dao/tenants.go +++ b/db/mysql/dao/tenants.go @@ -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 diff --git a/hack/contrib/docker/mesh-data-panel/Makefile b/hack/contrib/docker/mesh-data-panel/Makefile index f11572eb5..b8705803e 100644 --- a/hack/contrib/docker/mesh-data-panel/Makefile +++ b/hack/contrib/docker/mesh-data-panel/Makefile @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/hack/contrib/docker/mesh-data-panel/start.sh b/hack/contrib/docker/mesh-data-panel/start.sh index cfc749f29..4957ac279 100755 --- a/hack/contrib/docker/mesh-data-panel/start.sh +++ b/hack/contrib/docker/mesh-data-panel/start.sh @@ -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 diff --git a/worker/appm/conversion/gateway.go b/worker/appm/conversion/gateway.go index 310049b48..6c1022d29 100644 --- a/worker/appm/conversion/gateway.go +++ b/worker/appm/conversion/gateway.go @@ -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, } diff --git a/worker/appm/conversion/version.go b/worker/appm/conversion/version.go index f3008715f..413d93a9e 100644 --- a/worker/appm/conversion/version.go +++ b/worker/appm/conversion/version.go @@ -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{ diff --git a/worker/appm/f/function.go b/worker/appm/f/function.go index 62e2af563..4a2bae10e 100644 --- a/worker/appm/f/function.go +++ b/worker/appm/f/function.go @@ -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) diff --git a/worker/appm/store/store.go b/worker/appm/store/store.go index 5c326c754..b8b482bb8 100644 --- a/worker/appm/store/store.go +++ b/worker/appm/store/store.go @@ -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++ } diff --git a/worker/gc/gc.go b/worker/gc/gc.go index d2a2af0a3..f1a03f97d 100644 --- a/worker/gc/gc.go +++ b/worker/gc/gc.go @@ -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)