You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/09/15 07:19:58 UTC
[incubator-servicecomb-service-center] branch master updated:
SCB-902 Support service discovery by Service Mesh (#440)
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 19ea8b0 SCB-902 Support service discovery by Service Mesh (#440)
19ea8b0 is described below
commit 19ea8b0110454bf2ac9ab870c0f14ab1b6f93a64
Author: little-cui <su...@qq.com>
AuthorDate: Sat Sep 15 15:19:54 2018 +0800
SCB-902 Support service discovery by Service Mesh (#440)
* SCB-902 Support service discovery by Service Mesh
* Do not check the consumer in discovery APIs
* Optimize the k8s deployment templates
---
integration/k8s/README.md | 62 +++++++-----
.../{service-center/charts => }/etcd/Chart.yaml | 0
.../etcd/charts/etcd-operator/.helmignore | 0
.../etcd/charts/etcd-operator/Chart.yaml | 0
.../charts => }/etcd/charts/etcd-operator/OWNERS | 0
.../etcd/charts/etcd-operator/README.md | 0
.../etcd/charts/etcd-operator/templates/NOTES.txt | 0
.../charts/etcd-operator/templates/_helpers.tpl | 0
.../etcd-operator/templates/backup-etcd-crd.yaml | 0
.../backup-operator-clusterrole-binding.yaml | 0
.../templates/backup-operator-deployment.yaml | 0
.../templates/backup-operator-service-account.yaml | 0
.../etcd-operator/templates/etcd-cluster-crd.yaml | 0
.../templates/operator-cluster-role.yaml | 0
.../templates/operator-clusterrole-binding.yaml | 0
.../templates/operator-deployment.yaml | 0
.../templates/operator-service-account.yaml | 0
.../etcd-operator/templates/restore-etcd-crd.yaml | 0
.../restore-operator-clusterrole-binding.yaml | 0
.../templates/restore-operator-deployment.yaml | 0
.../restore-operator-service-account.yaml | 0
.../templates/restore-operator-service.yaml | 0
.../etcd/charts/etcd-operator/values.yaml | 0
.../charts => }/etcd/templates/_helpers.tpl | 0
.../charts => }/etcd/templates/deployment.yaml | 0
.../{service-center/charts => }/etcd/values.yaml | 0
integration/k8s/service-center-k8s/.helmignore | 21 -----
integration/k8s/service-center-k8s/Chart.yaml | 4 -
.../k8s/service-center-k8s/templates/NOTES.txt | 19 ----
.../k8s/service-center-k8s/templates/_helpers.tpl | 16 ----
.../service-center-k8s/templates/deployment.yaml | 104 ---------------------
.../k8s/service-center-k8s/templates/ingress.yaml | 34 -------
.../k8s/service-center-k8s/templates/service.yaml | 49 ----------
integration/k8s/service-center-k8s/values.yaml | 51 ----------
.../templates/configmap.yaml | 14 +++
.../k8s/service-center/templates/deployment.yaml | 31 ++++--
.../k8s/service-center/templates/ingress.yaml | 2 +
.../templates/rbac.yaml | 4 +-
.../k8s/service-center/templates/service.yaml | 2 +
integration/k8s/service-center/values.yaml | 4 +
scripts/build/local.sh | 1 +
scripts/build/tools.sh | 6 +-
scripts/docker/build-frontend-image/start.sh | 2 +-
scripts/docker/build-image/start.sh | 2 +-
scripts/release/make_release.sh | 1 +
server/plugin/infra/discovery/k8s/common.go | 6 +-
server/plugin/infra/discovery/k8s/convertor.go | 17 +++-
server/plugin/infra/registry/etcd/etcd_test.go | 10 +-
server/service/cache/filter_instances.go | 2 +-
server/service/cache/filter_permission.go | 2 +-
server/service/cache/filter_tags.go | 2 +-
server/service/cache/filter_version.go | 2 +-
server/service/instance.go | 37 ++++----
server/service/instance_test.go | 6 +-
server/service/instance_validator.go | 4 +-
server/service/util/rule_util.go | 4 +
server/service/util/rule_util_test.go | 2 +-
57 files changed, 153 insertions(+), 370 deletions(-)
diff --git a/integration/k8s/README.md b/integration/k8s/README.md
index 1e32041..3186030 100644
--- a/integration/k8s/README.md
+++ b/integration/k8s/README.md
@@ -2,7 +2,7 @@ Integrate with Kubernetes
-------
A simple demo to deploy ServiceCenter Cluster in Kubernetes.
-ServiceCenter supports two deploy modes: `Self Registration` and `Platform Registration`
+ServiceCenter supports two deploy modes: `Platform Registration` and `Self Registration`
## Requirements
@@ -10,13 +10,13 @@ ServiceCenter supports two deploy modes: `Self Registration` and `Platform Regis
1. Already install `kubectl` and `helm client` in your local machine.
1. (Optional) Already deploy helm tiller on Kubernetes.
-## Self Registration
+## Platform Registration
-The self-registration representational ServiceCenter receives and
-processes registration requests from micro-service instances and
-stores instance information in `etcd`.
+The platform-registration indicates that the ServiceCenter automatically accesses `kubernetes` cluster,
+and micro-service instances can discover service and endpoints information through
+the ServiceCenter.
-Notes: After deployment, it create ServiceCenter cluster and etcd cluster in the `default` namespace.
+Notes: After deployment, it only create ServiceCenter cluster in the `default` namespace.
#### Use Kubectl
@@ -29,16 +29,21 @@ kubectl apply -f <(helm template --name servicecomb --namespace default service-
#### Use Helm Install
-You can also use the helm commands to deploy ServiceCenter cluster if
+You can also use the helm commands to deploy ServiceCenter cluster if
you already deploy helm tiller.
-## Platform Registration
+```bash
+cd ${PROJECT_ROOT}/integration/k8s
+helm install --name servicecomb --namespace default service-center/
+```
-The platform-registration indicates that the ServiceCenter automatically accesses `kubernetes` cluster,
-and micro-service instances can discover service and endpoints information through
-the ServiceCenter.
+## Self Registration
-Notes: After deployment, it only create ServiceCenter cluster in the `default` namespace.
+The self-registration representational ServiceCenter receives and
+processes registration requests from micro-service instances and
+stores instance information in `etcd`.
+
+Notes: After deployment, it create ServiceCenter cluster and etcd cluster in the `default` namespace.
#### Use Kubectl
@@ -46,18 +51,29 @@ You can use the command `kubectl apply` to deploy ServiceCenter cluster.
```bash
cd ${PROJECT_ROOT}/integration/k8s
-kubectl apply -f <(helm template --name servicecomb --namespace default service-center-k8s/)
+# install etcd cluster
+kubectl apply -f <(helm template --name coreos --namespace default etcd/)
+# install sc cluster
+kubectl apply -f <(helm template --name servicecomb --namespace default \
+ --set sc.discovery.type="etcd" \
+ --set sc.discovery.uris="http://coreos-etcd-client:2379" \
+ service-center/)
```
#### Use Helm Install
-You can also use the helm commands to deploy ServiceCenter cluster if
+You can also use the helm commands to deploy ServiceCenter cluster if
you already deploy helm tiller.
-
```bash
cd ${PROJECT_ROOT}/integration/k8s
-helm install --name servicecomb --namespace default service-center-k8s/
+# install etcd cluster
+helm install --name coreos --namespace default etcd/
+# install sc cluster
+helm install --name servicecomb --namespace default \
+ --set sc.discovery.type="etcd" \
+ --set sc.discovery.uris="http://coreos-etcd-client:2379" \
+ service-center/
```
## Confirm the deploy is ok
@@ -69,23 +85,23 @@ By default, the ServiceCenter frontend use `NodePort` service type to deploy in
1. (Recommended) You can use [`scctl`](/scctl) tool to list micro-service information.
```bash
-# ./scctl get svc --addr http://servicecomb-service-center-k8s:30100 -owide
- DOMAIN | NAME | APPID | VERSIONS | ENV | FRAMEWORK | ENDPOINTS | AGE
-+---------+-----------------------------------------+-----------------------------+----------+-----+------------+--------------------------+-----+
- default | servicecomb-service-center-k8s-frontend | service-center-k8s-frontend | 0.0.1 | | Kubernetes | http://172.0.1.101:30103 | 2m
- default | servicecomb-service-center-k8s | service-center-k8s | 0.0.1 | | Kubernetes | http://172.0.1.102:30100 | 2m
+# ./scctl get svc --addr http://servicecomb-service-center:30100 -owide
+ DOMAIN | NAME | APPID | VERSIONS | ENV | FRAMEWORK | ENDPOINTS | AGE
++---------+-------------------------------------+-------------------------+----------+-----+------------+--------------------------+-----+
+ default | servicecomb-service-center-frontend | service-center-frontend | 0.0.1 | | Kubernetes | http://172.0.1.101:30103 | 2m
+ default | servicecomb-service-center | service-center | 0.0.1 | | Kubernetes | http://172.0.1.102:30100 | 2m
```
## Clean up
-If you use the kubectl to deploy, take deploy mode `self registration` as example.
+If you use the kubectl to deploy, take deploy mode `platform registration` as example.
```bash
cd ${PROJECT_ROOT}/integration/k8s
kubectl delete -f <(helm template --name servicecomb --namespace default service-center/)
```
-If you use helm tiller to deploy, take deploy mode `self registration` as example.
+If you use helm tiller to deploy, take deploy mode `platform registration` as example.
```bash
cd ${PROJECT_ROOT}/k8s
diff --git a/integration/k8s/service-center/charts/etcd/Chart.yaml b/integration/k8s/etcd/Chart.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/Chart.yaml
rename to integration/k8s/etcd/Chart.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/.helmignore b/integration/k8s/etcd/charts/etcd-operator/.helmignore
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/.helmignore
rename to integration/k8s/etcd/charts/etcd-operator/.helmignore
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/Chart.yaml b/integration/k8s/etcd/charts/etcd-operator/Chart.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/Chart.yaml
rename to integration/k8s/etcd/charts/etcd-operator/Chart.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/OWNERS b/integration/k8s/etcd/charts/etcd-operator/OWNERS
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/OWNERS
rename to integration/k8s/etcd/charts/etcd-operator/OWNERS
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/README.md b/integration/k8s/etcd/charts/etcd-operator/README.md
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/README.md
rename to integration/k8s/etcd/charts/etcd-operator/README.md
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/NOTES.txt b/integration/k8s/etcd/charts/etcd-operator/templates/NOTES.txt
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/NOTES.txt
rename to integration/k8s/etcd/charts/etcd-operator/templates/NOTES.txt
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/_helpers.tpl b/integration/k8s/etcd/charts/etcd-operator/templates/_helpers.tpl
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/_helpers.tpl
rename to integration/k8s/etcd/charts/etcd-operator/templates/_helpers.tpl
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/backup-etcd-crd.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/backup-etcd-crd.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/backup-etcd-crd.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/backup-etcd-crd.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/backup-operator-clusterrole-binding.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-clusterrole-binding.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/backup-operator-clusterrole-binding.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-clusterrole-binding.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/backup-operator-deployment.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-deployment.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/backup-operator-deployment.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-deployment.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/backup-operator-service-account.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-service-account.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/backup-operator-service-account.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-service-account.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/etcd-cluster-crd.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/etcd-cluster-crd.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/etcd-cluster-crd.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/etcd-cluster-crd.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/operator-cluster-role.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/operator-cluster-role.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/operator-cluster-role.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/operator-cluster-role.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/operator-clusterrole-binding.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/operator-clusterrole-binding.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/operator-clusterrole-binding.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/operator-clusterrole-binding.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/operator-deployment.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/operator-deployment.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/operator-deployment.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/operator-deployment.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/operator-service-account.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/operator-service-account.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/operator-service-account.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/operator-service-account.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-etcd-crd.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/restore-etcd-crd.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-etcd-crd.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/restore-etcd-crd.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-operator-clusterrole-binding.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-clusterrole-binding.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-operator-clusterrole-binding.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-clusterrole-binding.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-operator-deployment.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-deployment.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-operator-deployment.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-deployment.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-operator-service-account.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-service-account.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-operator-service-account.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-service-account.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-operator-service.yaml b/integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-service.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/templates/restore-operator-service.yaml
rename to integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-service.yaml
diff --git a/integration/k8s/service-center/charts/etcd/charts/etcd-operator/values.yaml b/integration/k8s/etcd/charts/etcd-operator/values.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/charts/etcd-operator/values.yaml
rename to integration/k8s/etcd/charts/etcd-operator/values.yaml
diff --git a/integration/k8s/service-center/charts/etcd/templates/_helpers.tpl b/integration/k8s/etcd/templates/_helpers.tpl
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/templates/_helpers.tpl
rename to integration/k8s/etcd/templates/_helpers.tpl
diff --git a/integration/k8s/service-center/charts/etcd/templates/deployment.yaml b/integration/k8s/etcd/templates/deployment.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/templates/deployment.yaml
rename to integration/k8s/etcd/templates/deployment.yaml
diff --git a/integration/k8s/service-center/charts/etcd/values.yaml b/integration/k8s/etcd/values.yaml
similarity index 100%
rename from integration/k8s/service-center/charts/etcd/values.yaml
rename to integration/k8s/etcd/values.yaml
diff --git a/integration/k8s/service-center-k8s/.helmignore b/integration/k8s/service-center-k8s/.helmignore
deleted file mode 100644
index f0c1319..0000000
--- a/integration/k8s/service-center-k8s/.helmignore
+++ /dev/null
@@ -1,21 +0,0 @@
-# Patterns to ignore when building packages.
-# This supports shell glob matching, relative path matching, and
-# negation (prefixed with !). Only one pattern per line.
-.DS_Store
-# Common VCS dirs
-.git/
-.gitignore
-.bzr/
-.bzrignore
-.hg/
-.hgignore
-.svn/
-# Common backup files
-*.swp
-*.bak
-*.tmp
-*~
-# Various IDEs
-.project
-.idea/
-*.tmproj
diff --git a/integration/k8s/service-center-k8s/Chart.yaml b/integration/k8s/service-center-k8s/Chart.yaml
deleted file mode 100644
index f705360..0000000
--- a/integration/k8s/service-center-k8s/Chart.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-apiVersion: v1
-description: A Helm chart for Kubernetes
-name: service-center-k8s
-version: 0.1.0
diff --git a/integration/k8s/service-center-k8s/templates/NOTES.txt b/integration/k8s/service-center-k8s/templates/NOTES.txt
deleted file mode 100644
index 478cddb..0000000
--- a/integration/k8s/service-center-k8s/templates/NOTES.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-1. Get the application URL by running these commands:
-{{- if .Values.sc.ingress.enabled }}
-{{- range .Values.sc.ingress.hosts }}
- http://{{ . }}
-{{- end }}
-{{- else if contains "NodePort" .Values.sc.service.type }}
- export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "service-center.fullname" . }})
- export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
- echo http://$NODE_IP:$NODE_PORT
-{{- else if contains "LoadBalancer" .Values.sc.service.type }}
- NOTE: It may take a few minutes for the LoadBalancer IP to be available.
- You can watch the status of by running 'kubectl get svc -w {{ template "service-center.fullname" . }}'
- export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "service-center.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
- echo http://$SERVICE_IP:{{ .Values.sc.service.externalPort }}
-{{- else if contains "ClusterIP" .Values.sc.service.type }}
- export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "service-center.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
- echo "Visit http://127.0.0.1:8080 to use your application"
- kubectl port-forward $POD_NAME 8080:{{ .Values.sc.service.internalPort }}
-{{- end }}
diff --git a/integration/k8s/service-center-k8s/templates/_helpers.tpl b/integration/k8s/service-center-k8s/templates/_helpers.tpl
deleted file mode 100644
index 654de69..0000000
--- a/integration/k8s/service-center-k8s/templates/_helpers.tpl
+++ /dev/null
@@ -1,16 +0,0 @@
-{{/* vim: set filetype=mustache: */}}
-{{/*
-Expand the name of the chart.
-*/}}
-{{- define "service-center.name" -}}
-{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
-{{- end -}}
-
-{{/*
-Create a default fully qualified app name.
-We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
-*/}}
-{{- define "service-center.fullname" -}}
-{{- $name := default .Chart.Name .Values.nameOverride -}}
-{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
-{{- end -}}
diff --git a/integration/k8s/service-center-k8s/templates/deployment.yaml b/integration/k8s/service-center-k8s/templates/deployment.yaml
deleted file mode 100644
index f016f8a..0000000
--- a/integration/k8s/service-center-k8s/templates/deployment.yaml
+++ /dev/null
@@ -1,104 +0,0 @@
-{{- $serviceName := include "service-center.fullname" . -}}
-{{- $servicePort := .Values.sc.service.externalPort -}}
----
-apiVersion: extensions/v1beta1
-kind: Deployment
-metadata:
- name: {{ template "service-center.fullname" . }}
- namespace: {{ .Release.Namespace }}
- labels:
- app: {{ template "service-center.name" . }}
- chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
- release: {{ .Release.Name }}
- heritage: {{ .Release.Service }}
-spec:
- replicas: {{ .Values.sc.replicaCount }}
- template:
- metadata:
- labels:
- app: {{ template "service-center.name" . }}
- release: {{ .Release.Name }}
- spec:
- serviceAccountName: {{ template "service-center.fullname" . }}
- volumes:
- - name: config
- configMap:
- name: {{ template "service-center.fullname" . }}
- items:
- - key: app-config
- path: app.conf
- containers:
- - name: {{ .Chart.Name }}
- image: "{{ .Values.sc.image.repository }}:{{ .Values.sc.image.tag }}"
- imagePullPolicy: {{ .Values.sc.image.pullPolicy }}
- ports:
- - containerPort: {{ .Values.sc.service.internalPort }}
- volumeMounts:
- - name: config
- mountPath: /opt/service-center/conf
- readOnly: false
- livenessProbe:
- httpGet:
- path: /
- port: {{ .Values.sc.service.internalPort }}
- readinessProbe:
- httpGet:
- path: /
- port: {{ .Values.sc.service.internalPort }}
- resources:
-{{ toYaml .Values.sc.resources | indent 12 }}
- {{- if .Values.sc.nodeSelector }}
- nodeSelector:
-{{ toYaml .Values.sc.nodeSelector | indent 8 }}
- {{- end }}
-
----
-apiVersion: extensions/v1beta1
-kind: Deployment
-metadata:
- name: {{ template "service-center.fullname" . }}-frontend
- namespace: {{ .Release.Namespace }}
- labels:
- app: {{ template "service-center.name" . }}-frontend
- chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
- release: {{ .Release.Name }}
- heritage: {{ .Release.Service }}
-spec:
- replicas: {{ .Values.frontend.replicaCount }}
- template:
- metadata:
- labels:
- app: {{ template "service-center.name" . }}-frontend
- release: {{ .Release.Name }}
- spec:
- volumes:
- - name: config
- configMap:
- name: {{ template "service-center.fullname" . }}-frontend
- items:
- - key: app-config
- path: app.conf
- containers:
- - name: {{ .Chart.Name }}-frontend
- image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag }}"
- imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
- ports:
- - containerPort: {{ .Values.frontend.service.internalPort }}
- volumeMounts:
- - name: config
- mountPath: /opt/frontend/conf
- readOnly: false
- livenessProbe:
- httpGet:
- path: /
- port: {{ .Values.frontend.service.internalPort }}
- readinessProbe:
- httpGet:
- path: /
- port: {{ .Values.frontend.service.internalPort }}
- resources:
-{{ toYaml .Values.frontend.resources | indent 12 }}
- {{- if .Values.frontend.nodeSelector }}
- nodeSelector:
-{{ toYaml .Values.frontend.nodeSelector | indent 8 }}
- {{- end }}
diff --git a/integration/k8s/service-center-k8s/templates/ingress.yaml b/integration/k8s/service-center-k8s/templates/ingress.yaml
deleted file mode 100644
index 14b7fa0..0000000
--- a/integration/k8s/service-center-k8s/templates/ingress.yaml
+++ /dev/null
@@ -1,34 +0,0 @@
-{{- if .Values.sc.ingress.enabled -}}
-{{- $serviceName := include "service-center.fullname" . -}}
-{{- $servicePort := .Values.sc.service.externalPort -}}
----
-apiVersion: extensions/v1beta1
-kind: Ingress
-metadata:
- name: {{ template "service-center.fullname" . }}
- namespace: {{ .Release.Namespace }}
- labels:
- app: {{ template "service-center.name" . }}
- chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
- release: {{ .Release.Name }}
- heritage: {{ .Release.Service }}
- annotations:
- {{- range $key, $value := .Values.sc.ingress.annotations }}
- {{ $key }}: {{ $value | quote }}
- {{- end }}
-spec:
- rules:
- {{- range $host := .Values.sc.ingress.hosts }}
- - host: {{ $host }}
- http:
- paths:
- - path: /v4/
- backend:
- serviceName: {{ $serviceName }}
- servicePort: {{ $servicePort }}
- {{- end -}}
- {{- if .Values.sc.ingress.tls }}
- tls:
-{{ toYaml .Values.sc.ingress.tls | indent 4 }}
- {{- end -}}
-{{- end -}}
diff --git a/integration/k8s/service-center-k8s/templates/service.yaml b/integration/k8s/service-center-k8s/templates/service.yaml
deleted file mode 100644
index b907537..0000000
--- a/integration/k8s/service-center-k8s/templates/service.yaml
+++ /dev/null
@@ -1,49 +0,0 @@
----
-apiVersion: v1
-kind: Service
-metadata:
- name: {{ template "service-center.fullname" . }}
- namespace: {{ .Release.Namespace }}
- labels:
- app: {{ template "service-center.name" . }}
- chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
- release: {{ .Release.Name }}
- heritage: {{ .Release.Service }}
-spec:
- type: {{ .Values.sc.service.type }}
- ports:
- - port: {{ .Values.sc.service.externalPort }}
- targetPort: {{ .Values.sc.service.internalPort }}
- {{ if eq .Values.sc.service.type "NodePort" }}
- nodePort: {{ .Values.sc.service.externalPort }}
- {{ end }}
- protocol: TCP
- name: {{ .Values.sc.service.name }}
- selector:
- app: {{ template "service-center.name" . }}
- release: {{ .Release.Name }}
-
----
-apiVersion: v1
-kind: Service
-metadata:
- name: {{ template "service-center.fullname" . }}-frontend
- namespace: {{ .Release.Namespace }}
- labels:
- app: {{ template "service-center.name" . }}-frontend
- chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
- release: {{ .Release.Name }}
- heritage: {{ .Release.Service }}
-spec:
- type: {{ .Values.frontend.service.type }}
- ports:
- - port: {{ .Values.frontend.service.externalPort }}
- targetPort: {{ .Values.frontend.service.internalPort }}
- {{ if eq .Values.frontend.service.type "NodePort" }}
- nodePort: {{ .Values.frontend.service.externalPort }}
- {{ end }}
- protocol: TCP
- name: {{ .Values.frontend.service.name }}
- selector:
- app: {{ template "service-center.name" . }}-frontend
- release: {{ .Release.Name }}
diff --git a/integration/k8s/service-center-k8s/values.yaml b/integration/k8s/service-center-k8s/values.yaml
deleted file mode 100644
index 52e8cef..0000000
--- a/integration/k8s/service-center-k8s/values.yaml
+++ /dev/null
@@ -1,51 +0,0 @@
-# Default values for service-center.
-# This is a YAML-formatted file.
-# Declare variables to be passed into your templates.
-frontend:
- replicaCount: 2
- image:
- repository: servicecomb/scfrontend
- tag: latest
- pullPolicy: IfNotPresent
- service:
- name: scfrontend
- type: NodePort
- externalPort: 30103
- internalPort: 30103
-
-sc:
- replicaCount: 2
- image:
- repository: servicecomb/service-center
- tag: latest
- pullPolicy: IfNotPresent
- service:
- name: service-center
- type: ClusterIP
- externalPort: 30100
- internalPort: 30100
-
- ingress:
- enabled: false
- # Used to create an Ingress record.
- hosts:
- - service-center.local
- annotations:
- # kubernetes.io/ingress.class: nginx
- # kubernetes.io/tls-acme: "true"
- tls:
- # Secrets must be manually created in the namespace.
- # - secretName: chart-example-tls
- # hosts:
- # - chart-example.local
- resources: {}
- # We usually recommend not to specify default resources and to leave this as a conscious
- # choice for the user. This also increases chances charts run on environments with little
- # resources, such as Minikube. If you do want to specify resources, uncomment the following
- # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
- # limits:
- # cpu: 100m
- # memory: 128Mi
- # requests:
- # cpu: 100m
- # memory: 128Mi
diff --git a/integration/k8s/service-center-k8s/templates/configmap.yaml b/integration/k8s/service-center/templates/configmap.yaml
similarity index 70%
rename from integration/k8s/service-center-k8s/templates/configmap.yaml
rename to integration/k8s/service-center/templates/configmap.yaml
index 21120cf..94949be 100644
--- a/integration/k8s/service-center-k8s/templates/configmap.yaml
+++ b/integration/k8s/service-center/templates/configmap.yaml
@@ -13,9 +13,23 @@ data:
app-config: |
httpaddr = ${HOSTNAME}
httpport = {{ .Values.sc.service.internalPort }}
+ {{- if eq .Values.sc.discovery.type "k8s" }}
discovery_plugin = k8s
registry_plugin = buildin
self_register = 0
+ {{- else if eq .Values.sc.discovery.type "etcd" }}
+ discovery_plugin = etcd
+ registry_plugin = etcd
+ self_register = 1
+ manager_cluster = {{ .Values.sc.discovery.uris }}
+ {{- else }}
+ discovery_plugin = etcd
+ registry_plugin = embeded_etcd
+ self_register = 1
+ manager_name = "sr-0"
+ manager_addr = "http://127.0.0.1:2380"
+ manager_cluster = "sr-0=http://127.0.0.1:2380"
+ {{- end }}
ssl_mode = 0
enable_pprof = 1
diff --git a/integration/k8s/service-center/templates/deployment.yaml b/integration/k8s/service-center/templates/deployment.yaml
index f1ca9cf..f016f8a 100644
--- a/integration/k8s/service-center/templates/deployment.yaml
+++ b/integration/k8s/service-center/templates/deployment.yaml
@@ -5,6 +5,7 @@ apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "service-center.fullname" . }}
+ namespace: {{ .Release.Namespace }}
labels:
app: {{ template "service-center.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
@@ -18,15 +19,24 @@ spec:
app: {{ template "service-center.name" . }}
release: {{ .Release.Name }}
spec:
+ serviceAccountName: {{ template "service-center.fullname" . }}
+ volumes:
+ - name: config
+ configMap:
+ name: {{ template "service-center.fullname" . }}
+ items:
+ - key: app-config
+ path: app.conf
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.sc.image.repository }}:{{ .Values.sc.image.tag }}"
imagePullPolicy: {{ .Values.sc.image.pullPolicy }}
ports:
- containerPort: {{ .Values.sc.service.internalPort }}
- env:
- - name: BACKEND_ADDRESS
- value: http://{{ .Release.Name }}-etcd-client:2379
+ volumeMounts:
+ - name: config
+ mountPath: /opt/service-center/conf
+ readOnly: false
livenessProbe:
httpGet:
path: /
@@ -47,6 +57,7 @@ apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "service-center.fullname" . }}-frontend
+ namespace: {{ .Release.Namespace }}
labels:
app: {{ template "service-center.name" . }}-frontend
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
@@ -60,15 +71,23 @@ spec:
app: {{ template "service-center.name" . }}-frontend
release: {{ .Release.Name }}
spec:
+ volumes:
+ - name: config
+ configMap:
+ name: {{ template "service-center.fullname" . }}-frontend
+ items:
+ - key: app-config
+ path: app.conf
containers:
- name: {{ .Chart.Name }}-frontend
image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag }}"
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
ports:
- containerPort: {{ .Values.frontend.service.internalPort }}
- env:
- - name: SC_ADDRESS
- value: http://{{ $serviceName }}:{{ $servicePort }}
+ volumeMounts:
+ - name: config
+ mountPath: /opt/frontend/conf
+ readOnly: false
livenessProbe:
httpGet:
path: /
diff --git a/integration/k8s/service-center/templates/ingress.yaml b/integration/k8s/service-center/templates/ingress.yaml
index 58ca39e..14b7fa0 100644
--- a/integration/k8s/service-center/templates/ingress.yaml
+++ b/integration/k8s/service-center/templates/ingress.yaml
@@ -1,10 +1,12 @@
{{- if .Values.sc.ingress.enabled -}}
{{- $serviceName := include "service-center.fullname" . -}}
{{- $servicePort := .Values.sc.service.externalPort -}}
+---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ template "service-center.fullname" . }}
+ namespace: {{ .Release.Namespace }}
labels:
app: {{ template "service-center.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
diff --git a/integration/k8s/service-center-k8s/templates/rbac.yaml b/integration/k8s/service-center/templates/rbac.yaml
similarity index 96%
rename from integration/k8s/service-center-k8s/templates/rbac.yaml
rename to integration/k8s/service-center/templates/rbac.yaml
index c5c1112..fa1a0e9 100644
--- a/integration/k8s/service-center-k8s/templates/rbac.yaml
+++ b/integration/k8s/service-center/templates/rbac.yaml
@@ -1,3 +1,4 @@
+{{- if eq .Values.sc.discovery.type "k8s" -}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
@@ -44,6 +45,7 @@ subjects:
name: {{ template "service-center.fullname" . }}
namespace: {{ .Release.Namespace }}
+{{ end -}}
---
apiVersion: v1
kind: ServiceAccount
@@ -55,4 +57,4 @@ metadata:
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
- namespace: {{ .Release.Namespace }}
+
diff --git a/integration/k8s/service-center/templates/service.yaml b/integration/k8s/service-center/templates/service.yaml
index 1a0e9a4..b907537 100644
--- a/integration/k8s/service-center/templates/service.yaml
+++ b/integration/k8s/service-center/templates/service.yaml
@@ -3,6 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ template "service-center.fullname" . }}
+ namespace: {{ .Release.Namespace }}
labels:
app: {{ template "service-center.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
@@ -27,6 +28,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ template "service-center.fullname" . }}-frontend
+ namespace: {{ .Release.Namespace }}
labels:
app: {{ template "service-center.name" . }}-frontend
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
diff --git a/integration/k8s/service-center/values.yaml b/integration/k8s/service-center/values.yaml
index 52e8cef..1abad5a 100644
--- a/integration/k8s/service-center/values.yaml
+++ b/integration/k8s/service-center/values.yaml
@@ -12,9 +12,13 @@ frontend:
type: NodePort
externalPort: 30103
internalPort: 30103
+ resources: {}
sc:
replicaCount: 2
+ discovery:
+ type: k8s # support local, etcd and k8s discovery mode
+ uris: ""
image:
repository: servicecomb/service-center
tag: latest
diff --git a/scripts/build/local.sh b/scripts/build/local.sh
index 5fdeb9f..dec2147 100644
--- a/scripts/build/local.sh
+++ b/scripts/build/local.sh
@@ -19,6 +19,7 @@ set -e
export GOOS=${1:-"linux"}
export GOARCH=${4:-"amd64"}
+export GO_LDFLAGS=${GO_LDFLAGS:-"-linkmode 'external' -extldflags '-static' -s -w"}
RELEASE=${2:-"0.0.1"}
diff --git a/scripts/build/tools.sh b/scripts/build/tools.sh
index f80a616..51b7c01 100644
--- a/scripts/build/tools.sh
+++ b/scripts/build/tools.sh
@@ -61,7 +61,7 @@ build_service_center() {
## Build the Service-Center releases
export GIT_COMMIT=$(git log --pretty=format:'%h' -n 1)
export BUILD_NUMBER=$RELEASE
- local ldflags="${GO_LDFLAGS} -s -w -X 'github.com/apache/incubator-servicecomb-service-center/version.BUILD_TAG=$(date +%Y%m%d%H%M%S).$BUILD_NUMBER.$GIT_COMMIT'"
+ local ldflags="${GO_LDFLAGS} -X 'github.com/apache/incubator-servicecomb-service-center/version.BUILD_TAG=$(date +%Y%m%d%H%M%S).$BUILD_NUMBER.$GIT_COMMIT'"
ldflags="${ldflags} -X 'github.com/apache/incubator-servicecomb-service-center/version.VERSION=$BUILD_NUMBER'"
local BINARY_NAME=$app/service-center
@@ -78,7 +78,7 @@ build_frontend() {
if [ "$GOOS" == "windows" ]; then
BINARY_NAME=${BINARY_NAME}.exe
fi
- go build --ldflags "-s -w" -o ../$BINARY_NAME
+ go build --ldflags "${GO_LDFLAGS}" -o ../$BINARY_NAME
cd -
}
@@ -88,7 +88,7 @@ build_scctl() {
cd scctl
export GIT_COMMIT=$(git log --pretty=format:'%h' -n 1)
export BUILD_NUMBER=$RELEASE
- local ldflags="${GO_LDFLAGS} -s -w -X 'github.com/apache/incubator-servicecomb-service-center/scctl/pkg/version.BUILD_TAG=$(date +%Y%m%d%H%M%S).$BUILD_NUMBER.$GIT_COMMIT'"
+ local ldflags="${GO_LDFLAGS} -X 'github.com/apache/incubator-servicecomb-service-center/scctl/pkg/version.BUILD_TAG=$(date +%Y%m%d%H%M%S).$BUILD_NUMBER.$GIT_COMMIT'"
ldflags="${ldflags} -X 'github.com/apache/incubator-servicecomb-service-center/scctl/pkg/version.VERSION=$BUILD_NUMBER'"
local BINARY_NAME=$app/scctl
diff --git a/scripts/docker/build-frontend-image/start.sh b/scripts/docker/build-frontend-image/start.sh
index 7d2e295..269f357 100644
--- a/scripts/docker/build-frontend-image/start.sh
+++ b/scripts/docker/build-frontend-image/start.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
diff --git a/scripts/docker/build-image/start.sh b/scripts/docker/build-image/start.sh
index 937bc4f..a8d7c73 100644
--- a/scripts/docker/build-image/start.sh
+++ b/scripts/docker/build-image/start.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
diff --git a/scripts/release/make_release.sh b/scripts/release/make_release.sh
index 8767846..fe9e3c3 100755
--- a/scripts/release/make_release.sh
+++ b/scripts/release/make_release.sh
@@ -57,6 +57,7 @@ esac
## Get the arch type
export GOARCH=${4:-"amd64"}
+export GO_LDFLAGS=${GO_LDFLAGS:-"-linkmode 'external' -extldflags '-static' -s -w"}
root_path=$(cd "$(dirname "$0")"; pwd)
diff --git a/server/plugin/infra/discovery/k8s/common.go b/server/plugin/infra/discovery/k8s/common.go
index afca508..5c2353e 100644
--- a/server/plugin/infra/discovery/k8s/common.go
+++ b/server/plugin/infra/discovery/k8s/common.go
@@ -30,8 +30,10 @@ const (
TypeNode K8sType = "Node"
TypePod K8sType = "Pod"
- SchemaTCP = "TCP"
- SchemaHTTP = "http"
+ SchemaTCP = "TCP"
+ SchemaHTTP = "HTTP"
+ SchemaHTTPS = "HTTPS"
+ protocolRest = "rest"
defaultDomainProject = "default/default"
diff --git a/server/plugin/infra/discovery/k8s/convertor.go b/server/plugin/infra/discovery/k8s/convertor.go
index 2b84151..e0b8629 100644
--- a/server/plugin/infra/discovery/k8s/convertor.go
+++ b/server/plugin/infra/discovery/k8s/convertor.go
@@ -51,20 +51,29 @@ func getFullName(namespace, name string) string {
return name
}
-func getProtocol(port v1.EndpointPort) string {
+func getProtocol(port v1.EndpointPort) (string, bool) {
switch port.Protocol {
case SchemaTCP:
- return SchemaHTTP
+ switch strings.ToUpper(port.Name) {
+ case SchemaHTTPS:
+ return protocolRest, true
+ default:
+ return protocolRest, false
+ }
default:
- return strings.ToLower(string(port.Protocol))
+ return strings.ToLower(string(port.Protocol)), false
}
}
func generateEndpoint(ip string, port v1.EndpointPort) string {
+ protocol, secure := getProtocol(port)
u := url.URL{
- Scheme: getProtocol(port),
+ Scheme: protocol,
Host: ip + ":" + strconv.FormatInt(int64(port.Port), 10),
}
+ if secure {
+ u.RawQuery = "sslEnabled=true"
+ }
return u.String()
}
diff --git a/server/plugin/infra/registry/etcd/etcd_test.go b/server/plugin/infra/registry/etcd/etcd_test.go
index a6c7c6a..40a8e0d 100644
--- a/server/plugin/infra/registry/etcd/etcd_test.go
+++ b/server/plugin/infra/registry/etcd/etcd_test.go
@@ -36,7 +36,10 @@ import (
const (
dialTimeout = 500 * time.Millisecond
- endpoint = "127.0.0.1:2379"
+)
+
+var (
+ endpoint = registry.RegistryConfig().ClusterAddresses
)
func TestEtcdClient(t *testing.T) {
@@ -57,10 +60,9 @@ func TestEtcdClient(t *testing.T) {
}
// base test
- registry.RegistryConfig().ClusterAddresses = endpoint
inst := NewRegistry()
- if inst == nil || firstEndpoint != "http://"+endpoint {
- t.Fatalf("TestEtcdClient failed, %#v", firstEndpoint)
+ if inst == nil || firstEndpoint != endpoint {
+ t.Fatalf("TestEtcdClient failed, %s != %s", firstEndpoint, endpoint)
}
old1 := registry.RegistryConfig().ClusterAddresses
old2 := registry.RegistryConfig().DialTimeout
diff --git a/server/service/cache/filter_instances.go b/server/service/cache/filter_instances.go
index d82583b..94f77df 100644
--- a/server/service/cache/filter_instances.go
+++ b/server/service/cache/filter_instances.go
@@ -49,7 +49,7 @@ func (f *InstancesFilter) Init(ctx context.Context, parent *cache.Node) (node *c
resp, err := backend.Store().Instance().Search(ctx, opts...)
if err != nil {
consumer := ctx.Value(CTX_FIND_CONSUMER).(*pb.MicroService)
- findFlag := fmt.Sprintf("consumer %s find provider %s/%s/%s", consumer.ServiceId,
+ findFlag := fmt.Sprintf("consumer '%s' find provider %s/%s/%s", consumer.ServiceId,
provider.AppId, provider.ServiceName, provider.Version)
log.Errorf(err, "Instance().Search failed, %s", findFlag)
return nil, err
diff --git a/server/service/cache/filter_permission.go b/server/service/cache/filter_permission.go
index 3beae37..aead2b0 100644
--- a/server/service/cache/filter_permission.go
+++ b/server/service/cache/filter_permission.go
@@ -40,7 +40,7 @@ func (f *AccessibleFilter) Init(ctx context.Context, parent *cache.Node) (node *
for _, providerServiceId := range pCopy.ServiceIds {
if err := serviceUtil.Accessible(ctx, consumerId, providerServiceId); err != nil {
provider := ctx.Value(CTX_FIND_PROVIDER).(*pb.MicroServiceKey)
- findFlag := fmt.Sprintf("consumer %s find provider %s/%s/%s", consumerId,
+ findFlag := fmt.Sprintf("consumer '%s' find provider %s/%s/%s", consumerId,
provider.AppId, provider.ServiceName, provider.Version)
log.Errorf(err, "AccessibleFilter failed, %s", findFlag)
continue
diff --git a/server/service/cache/filter_tags.go b/server/service/cache/filter_tags.go
index 5139db1..066fc53 100644
--- a/server/service/cache/filter_tags.go
+++ b/server/service/cache/filter_tags.go
@@ -56,7 +56,7 @@ loopProviderIds:
if err != nil {
consumer := ctx.Value(CTX_FIND_CONSUMER).(*pb.MicroService)
provider := ctx.Value(CTX_FIND_PROVIDER).(*pb.MicroServiceKey)
- findFlag := fmt.Sprintf("consumer %s find provider %s/%s/%s", consumer.ServiceId,
+ findFlag := fmt.Sprintf("consumer '%s' find provider %s/%s/%s", consumer.ServiceId,
provider.AppId, provider.ServiceName, provider.Version)
log.Errorf(err, "TagsFilter failed, %s", findFlag)
return nil, err
diff --git a/server/service/cache/filter_version.go b/server/service/cache/filter_version.go
index b65d0ca..3f57fad 100644
--- a/server/service/cache/filter_version.go
+++ b/server/service/cache/filter_version.go
@@ -39,7 +39,7 @@ func (f *VersionRuleFilter) Init(ctx context.Context, parent *cache.Node) (node
ids, exist, err := serviceUtil.FindServiceIds(ctx, provider.Version, provider)
if err != nil {
consumer := ctx.Value(CTX_FIND_CONSUMER).(*pb.MicroService)
- findFlag := fmt.Sprintf("consumer %s find provider %s/%s/%s", consumer.ServiceId,
+ findFlag := fmt.Sprintf("consumer '%s' find provider %s/%s/%s", consumer.ServiceId,
provider.AppId, provider.ServiceName, provider.Version)
log.Errorf(err, "VersionRuleFilter failed, %s", findFlag)
return
diff --git a/server/service/instance.go b/server/service/instance.go
index 9e61229..b40dbee 100644
--- a/server/service/instance.go
+++ b/server/service/instance.go
@@ -504,20 +504,23 @@ func (s *InstanceService) Find(ctx context.Context, in *pb.FindInstancesRequest)
domainProject := util.ParseDomainProject(ctx)
- service, err := serviceUtil.GetService(ctx, domainProject, in.ConsumerServiceId)
- if err != nil {
- log.Errorf(err, "get consumer failed, consumer %s find provider %s/%s/%s",
- in.ConsumerServiceId, in.AppId, in.ServiceName, in.VersionRule)
- return &pb.FindInstancesResponse{
- Response: pb.CreateResponse(scerr.ErrInternal, err.Error()),
- }, err
- }
- if service == nil {
- log.Errorf(nil, "consumer not exist, consumer %s find provider %s/%s/%s",
- in.ConsumerServiceId, in.AppId, in.ServiceName, in.VersionRule)
- return &pb.FindInstancesResponse{
- Response: pb.CreateResponse(scerr.ErrServiceNotExists, "Consumer does not exist."),
- }, nil
+ service := &pb.MicroService{}
+ if len(in.ConsumerServiceId) > 0 {
+ service, err = serviceUtil.GetService(ctx, domainProject, in.ConsumerServiceId)
+ if err != nil {
+ log.Errorf(err, "get consumer failed, consumer %s find provider %s/%s/%s",
+ in.ConsumerServiceId, in.AppId, in.ServiceName, in.VersionRule)
+ return &pb.FindInstancesResponse{
+ Response: pb.CreateResponse(scerr.ErrInternal, err.Error()),
+ }, err
+ }
+ if service == nil {
+ log.Errorf(nil, "consumer not exist, consumer %s find provider %s/%s/%s",
+ in.ConsumerServiceId, in.AppId, in.ServiceName, in.VersionRule)
+ return &pb.FindInstancesResponse{
+ Response: pb.CreateResponse(scerr.ErrServiceNotExists, "Consumer does not exist."),
+ }, nil
+ }
}
var findFlag string
@@ -533,7 +536,7 @@ func (s *InstanceService) Find(ctx context.Context, in *pb.FindInstancesRequest)
// it means the shared micro-services must be the same env with SC.
provider.Environment = apt.Service.Environment
- findFlag = fmt.Sprintf("consumer %s find shared service %s/%s/%s/%s", in.ConsumerServiceId,
+ findFlag = fmt.Sprintf("consumer '%s' find shared service %s/%s/%s/%s", in.ConsumerServiceId,
service.Environment, in.AppId, in.ServiceName, in.VersionRule)
} else {
// provider is not a shared micro-service,
@@ -541,7 +544,7 @@ func (s *InstanceService) Find(ctx context.Context, in *pb.FindInstancesRequest)
util.SetTargetDomainProject(ctx, util.ParseDomain(ctx), util.ParseProject(ctx))
provider.Tenant = util.ParseTargetDomainProject(ctx)
- findFlag = fmt.Sprintf("consumer %s find service %s/%s/%s/%s", in.ConsumerServiceId,
+ findFlag = fmt.Sprintf("consumer '%s' find service %s/%s/%s/%s", in.ConsumerServiceId,
service.Environment, in.AppId, in.ServiceName, in.VersionRule)
}
@@ -583,7 +586,7 @@ func (s *InstanceService) Find(ctx context.Context, in *pb.FindInstancesRequest)
}
// add dependency queue
- if newVersionRule && len(item.ServiceIds) > 0 {
+ if len(in.ConsumerServiceId) > 0 && newVersionRule && len(item.ServiceIds) > 0 {
provider, err = s.reshapeProviderKey(ctx, provider, item.ServiceIds[0])
if provider != nil {
err = serviceUtil.AddServiceVersionRule(ctx, domainProject, service, provider)
diff --git a/server/service/instance_test.go b/server/service/instance_test.go
index 978d983..fb012d3 100644
--- a/server/service/instance_test.go
+++ b/server/service/instance_test.go
@@ -1064,7 +1064,7 @@ var _ = Describe("'Instance' service", func() {
VersionRule: "1.0.0+",
})
Expect(err).To(BeNil())
- Expect(respFind.Response.Code).ToNot(Equal(pb.Response_SUCCESS))
+ Expect(respFind.Response.Code).To(Equal(pb.Response_SUCCESS))
By("provider does not exist")
respFind, err = instanceResource.Find(getContext(), &pb.FindInstancesRequest{
@@ -1436,7 +1436,7 @@ var _ = Describe("'Instance' service", func() {
ProviderInstanceId: instanceId2,
})
Expect(err).To(BeNil())
- Expect(resp.Response.Code).ToNot(Equal(pb.Response_SUCCESS))
+ Expect(resp.Response.Code).To(Equal(pb.Response_SUCCESS))
By("consumer does not exist")
resp, err = instanceResource.GetOneInstance(getContext(), &pb.GetOneInstanceRequest{
@@ -1497,7 +1497,7 @@ var _ = Describe("'Instance' service", func() {
ProviderServiceId: serviceId2,
})
Expect(err).To(BeNil())
- Expect(resp.Response.Code).ToNot(Equal(pb.Response_SUCCESS))
+ Expect(resp.Response.Code).To(Equal(pb.Response_SUCCESS))
By("consumer does not exist")
resp, err = instanceResource.GetInstances(getContext(), &pb.GetInstancesRequest{
diff --git a/server/service/instance_validator.go b/server/service/instance_validator.go
index a343b9c..369b8aa 100644
--- a/server/service/instance_validator.go
+++ b/server/service/instance_validator.go
@@ -48,7 +48,7 @@ var (
func FindInstanceReqValidator() *validate.Validator {
return findInstanceReqValidator.Init(func(v *validate.Validator) {
- v.AddRule("ConsumerServiceId", GetServiceReqValidator().GetRule("ServiceId"))
+ v.AddRule("ConsumerServiceId", GetInstanceReqValidator().GetRule("ConsumerServiceId"))
v.AddRules(ExistenceReqValidator().GetRules())
v.AddRule("VersionRule", ExistenceReqValidator().GetRule("Version"))
v.AddRule("Tags", UpdateTagReqValidator().GetRule("Key"))
@@ -57,7 +57,7 @@ func FindInstanceReqValidator() *validate.Validator {
func GetInstanceReqValidator() *validate.Validator {
return getInstanceReqValidator.Init(func(v *validate.Validator) {
- v.AddRule("ConsumerServiceId", GetServiceReqValidator().GetRule("ServiceId"))
+ v.AddRule("ConsumerServiceId", &validate.ValidateRule{Max: 64, Regexp: serviceIdRegex})
v.AddRule("ProviderServiceId", GetServiceReqValidator().GetRule("ServiceId"))
v.AddRule("ProviderInstanceId", HeartbeatReqValidator().GetRule("InstanceId"))
v.AddRule("Tags", UpdateTagReqValidator().GetRule("Key"))
diff --git a/server/service/util/rule_util.go b/server/service/util/rule_util.go
index 82bbd54..aa671a0 100644
--- a/server/service/util/rule_util.go
+++ b/server/service/util/rule_util.go
@@ -245,6 +245,10 @@ func patternBlackList(rulesOfProvider []*pb.ServiceRule, tagsOfConsumer map[stri
}
func Accessible(ctx context.Context, consumerId string, providerId string) *scerr.Error {
+ if len(consumerId) == 0 {
+ return nil
+ }
+
domainProject := util.ParseDomainProject(ctx)
targetDomainProject := util.ParseTargetDomainProject(ctx)
diff --git a/server/service/util/rule_util_test.go b/server/service/util/rule_util_test.go
index baf9c0d..0c2e27a 100644
--- a/server/service/util/rule_util_test.go
+++ b/server/service/util/rule_util_test.go
@@ -296,7 +296,7 @@ func TestGetProvider(t *testing.T) {
}
func TestAccessible(t *testing.T) {
- err := Accessible(context.Background(), "", "")
+ err := Accessible(context.Background(), "xxx", "")
if err.StatusCode() != http.StatusBadRequest {
t.Fatalf("Accessible invalid failed")
}