This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d10009  SCB-972 Using Sha1 signature key as UUID of k8s service (#461)
0d10009 is described below

commit 0d10009d5324043b58bdc7f7ee356259b800739d
Author: little-cui <[email protected]>
AuthorDate: Wed Oct 24 17:16:02 2018 +0800

    SCB-972 Using Sha1 signature key as UUID of k8s service (#461)
---
 docs/helm.md                                               |  2 +-
 server/plugin/pkg/discovery/k8s/adaptor/cacher_index.go    |  2 +-
 server/plugin/pkg/discovery/k8s/adaptor/cacher_instance.go |  7 ++++---
 server/plugin/pkg/discovery/k8s/adaptor/cacher_service.go  |  4 ++--
 server/plugin/pkg/discovery/k8s/adaptor/common.go          | 12 +++++++++++-
 server/plugin/pkg/discovery/k8s/adaptor/convertor.go       |  4 ++--
 6 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/docs/helm.md b/docs/helm.md
index 405ea11..dc8f760 100644
--- a/docs/helm.md
+++ b/docs/helm.md
@@ -136,7 +136,7 @@ helm delete --purge servicecomb
         `k8s,servicecenter`(for accessing distinct kubernetes clusters).
         - **`clusters`** (string: "sc-0=http://127.0.0.1:2380";) The cluster 
address managed by Service Center.
         If `type` is set to `etcd`, its format is 
`http(s)://{etcd-1},http(s)://{etcd-2}`. If `type` is
-        set to other value, its format is `{cluster name 
1}=http(s)://{cluster-1-1}|http(s)://{cluster-1-2},{cluster-2}=http(s)://{cluster-2-1}`
+        set to other value, its format is `{cluster name 
1}=http(s)://{cluster-1-1},http(s)://{cluster-1-2},{cluster-2}=http(s)://{cluster-2-1}`
     + **registry**
         - **`enabled`** (bool: false) Register Service Center itself or not.
         - **`type`** (string: "embeded_etcd") The class of backend storage 
provider, this decide how
diff --git a/server/plugin/pkg/discovery/k8s/adaptor/cacher_index.go 
b/server/plugin/pkg/discovery/k8s/adaptor/cacher_index.go
index 5958f31..73941ad 100644
--- a/server/plugin/pkg/discovery/k8s/adaptor/cacher_index.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/cacher_index.go
@@ -30,8 +30,8 @@ type ServiceIndexCacher struct {
 func (c *ServiceIndexCacher) onServiceEvent(evt K8sEvent) {
        svc := evt.Object.(*v1.Service)
        domainProject := Kubernetes().GetDomainProject()
-       serviceId := uuid(svc.UID)
        indexKey := 
core.GenerateServiceIndexKey(generateServiceKey(domainProject, svc))
+       serviceId := generateServiceId(domainProject, svc)
 
        if !ShouldRegisterService(svc) {
                kv := c.Cache().Get(indexKey)
diff --git a/server/plugin/pkg/discovery/k8s/adaptor/cacher_instance.go 
b/server/plugin/pkg/discovery/k8s/adaptor/cacher_instance.go
index 8147384..cecbe25 100644
--- a/server/plugin/pkg/discovery/k8s/adaptor/cacher_instance.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/cacher_instance.go
@@ -33,7 +33,7 @@ type InstanceCacher struct {
 func (c *InstanceCacher) onServiceEvent(evt K8sEvent) {
        svc := evt.Object.(*v1.Service)
        domainProject := Kubernetes().GetDomainProject()
-       serviceId := uuid(svc.UID)
+       serviceId := generateServiceId(domainProject, svc)
 
        switch evt.EventType {
        case pb.EVT_DELETE:
@@ -77,8 +77,9 @@ func (c *InstanceCacher) onEndpointsEvent(evt K8sEvent) {
                return
        }
 
-       serviceId := uuid(svc.UID)
        domainProject := Kubernetes().GetDomainProject()
+       serviceId := generateServiceId(domainProject, svc)
+
        oldKvs := c.getInstances(domainProject, serviceId)
        newKvs := make(map[string]*discovery.KeyValue)
        for _, ss := range ep.Subsets {
@@ -88,7 +89,7 @@ func (c *InstanceCacher) onEndpointsEvent(evt K8sEvent) {
                                continue
                        }
 
-                       instanceId := uuid(pod.UID)
+                       instanceId := UUID(pod.UID)
                        key := 
core.GenerateInstanceKey(Kubernetes().GetDomainProject(), serviceId, instanceId)
                        switch evt.EventType {
                        case pb.EVT_CREATE, pb.EVT_UPDATE:
diff --git a/server/plugin/pkg/discovery/k8s/adaptor/cacher_service.go 
b/server/plugin/pkg/discovery/k8s/adaptor/cacher_service.go
index f1df1ac..797b174 100644
--- a/server/plugin/pkg/discovery/k8s/adaptor/cacher_service.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/cacher_service.go
@@ -30,7 +30,7 @@ type ServiceCacher struct {
 func (c *ServiceCacher) onServiceEvent(evt K8sEvent) {
        svc := evt.Object.(*v1.Service)
        domainProject := Kubernetes().GetDomainProject()
-       serviceId := uuid(svc.UID)
+       serviceId := generateServiceId(domainProject, svc)
        key := core.GenerateServiceKey(domainProject, serviceId)
 
        if !ShouldRegisterService(svc) {
@@ -43,7 +43,7 @@ func (c *ServiceCacher) onServiceEvent(evt K8sEvent) {
 
        switch evt.EventType {
        case pb.EVT_CREATE, pb.EVT_UPDATE:
-               ms := FromK8sService(svc)
+               ms := FromK8sService(domainProject, svc)
                kv := AsKeyValue(key, ms, svc.ResourceVersion)
                if c.Cache().Get(key) == nil {
                        evt.EventType = pb.EVT_CREATE
diff --git a/server/plugin/pkg/discovery/k8s/adaptor/common.go 
b/server/plugin/pkg/discovery/k8s/adaptor/common.go
index 15ee29a..a9c629d 100644
--- a/server/plugin/pkg/discovery/k8s/adaptor/common.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/common.go
@@ -18,6 +18,10 @@ package adaptor
 import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/queue"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
+       "github.com/apache/incubator-servicecomb-service-center/server/core"
+       mgr 
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
+       
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/uuid"
+       "golang.org/x/net/context"
        "k8s.io/api/core/v1"
        meta "k8s.io/apimachinery/pkg/apis/meta/v1"
        "k8s.io/apimachinery/pkg/types"
@@ -98,6 +102,12 @@ func ShouldRegisterService(service *v1.Service) bool {
        return true
 }
 
-func uuid(id types.UID) string {
+func UUID(id types.UID) string {
        return strings.Replace(string(id), "-", "", -1)
 }
+
+func generateServiceId(domainProject string, svc *v1.Service) string {
+       indexKey := 
core.GenerateServiceIndexKey(generateServiceKey(domainProject, svc))
+       ctx := context.WithValue(context.Background(), uuid.ContextKey, 
indexKey)
+       return mgr.Plugins().UUID().GetServiceId(ctx)
+}
diff --git a/server/plugin/pkg/discovery/k8s/adaptor/convertor.go 
b/server/plugin/pkg/discovery/k8s/adaptor/convertor.go
index c5e2fda..8bc2a08 100644
--- a/server/plugin/pkg/discovery/k8s/adaptor/convertor.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/convertor.go
@@ -87,9 +87,9 @@ func generateServiceKey(domainProject string, svc 
*v1.Service) *pb.MicroServiceK
        }
 }
 
-func FromK8sService(svc *v1.Service) (ms *pb.MicroService) {
+func FromK8sService(domainProject string, svc *v1.Service) (ms 
*pb.MicroService) {
        ms = &pb.MicroService{
-               ServiceId:   uuid(svc.UID),
+               ServiceId:   generateServiceId(domainProject, svc),
                Environment: getLabel(svc.Labels, LabelEnvironment, ""),
                AppId:       getLabel(svc.Labels, LabelApp, pb.APP_ID),
                ServiceName: svc.Name,

Reply via email to