[
https://issues.apache.org/jira/browse/SCB-972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16661977#comment-16661977
]
ASF GitHub Bot commented on SCB-972:
------------------------------------
little-cui closed pull request #461: SCB-972 Using Sha1 signature key as UUID
of k8s service
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/461
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/docs/helm.md b/docs/helm.md
index 405ea11f..dc8f7602 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 5958f31d..73941ad5 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 8147384b..cecbe253 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 f1df1ac7..797b174e 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 15ee29ab..a9c629d2 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 c5e2fda3..8bc2a08d 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,
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Using SHA1 signature key as UUID of micro service
> -------------------------------------------------
>
> Key: SCB-972
> URL: https://issues.apache.org/jira/browse/SCB-972
> Project: Apache ServiceComb
> Issue Type: Bug
> Components: Service-Center
> Reporter: little-cui
> Assignee: little-cui
> Priority: Major
> Fix For: java-chassis-1.1.0
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)