Skip to content

Commit

Permalink
[CE-437] Unable to find orderer service url
Browse files Browse the repository at this point in the history
Currently, the orderer service URL wasn't updated correctly after
the cluster was created, this patch is meant to fix this, with this
patch was merged, user dashboard could connect cluster hosted by
 kubernetes agent, but it still can't install chaincode on it, due
to the mismatch of certificates.

CE-437 #done

Change-Id: I30601cf57bdc306bf56d3ec825d930955ede8aa7
Signed-off-by: luke <jiahaochen1993@gmail.com>
  • Loading branch information
jiahaoc1993 committed Aug 27, 2018
1 parent d16f929 commit 3311ff7
Showing 1 changed file with 61 additions and 25 deletions.
86 changes: 61 additions & 25 deletions src/agent/k8s/cluster_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def _get_node_ip(self, node_name):
for addr in i.status.addresses:
if addr.type == "ExternalIP":
ip = addr.address
elif addr.type == "InternalIP":
ip = addr.address
else:
continue
return ip

def _get_node_ip_of_service(self, service_name):
Expand All @@ -173,21 +177,57 @@ def _get_node_ip_of_service(self, service_name):
if i.metadata.name.startswith(service_name):
return self._get_node_ip(i.spec.node_name)

def _get_service_external_port(self, service_name):
def _get_service_external_port(self, namespace, ip):
ret = self.corev1client.list_service_for_all_namespaces(watch=False)
results = {}
# result template
r_template = ip + ":" + "{}"
for i in ret.items:
if i.metadata.name == service_name:
external_port = ""
if i.metadata.namespace == namespace:
tmp_name = i.metadata.name.replace("-", "_")
if i.metadata.name.startswith("peer"):
for port in i.spec.ports:
# transfer port name which can be recognized.
if port.name == "externale-listen-endpoint":
external_port = port.node_port
else:
name = tmp_name + "_grpc"
value = r_template.format(external_port)

elif port.name == "listen":
event_port = port.node_port
name = tmp_name + "_event"
value = r_template.format(event_port)

else:
continue

results[name] = value

elif i.metadata.name.startswith("ca"):
name = tmp_name + "_ecap"
for port in i.spec.ports:
# these services only have one port
external_port = port.node_port
_port = port.node_port
value = r_template.format(_port)
results[name] = value

return external_port
elif i.metadata.name.startswith("orderer"):
name = "orderer"
for port in i.spec.ports:
_port = port.node_port
value = r_template.format(_port)
results[name] = value

elif i.metadata.name.startswith("fabric-explorer"):
name = "dashboard"
for port in i.spec.ports:
_port = port.node_port
value = r_template.format(_port)
results[name] = value

else:
continue

return results

def _create_deployment(self, namespace, data, **kwargs):
try:
Expand Down Expand Up @@ -377,20 +417,16 @@ def _setup_cluster(self, cluster_name):

def get_services_urls(self, cluster_name):
ret = self.corev1client.list_service_for_all_namespaces(watch=False)
service_url = {}
value = ""
service = ""
for i in ret.items:
if i.metadata.namespace == cluster_name:
service_name = i.metadata.name
value = self._get_node_ip_of_service(service_name) + ":" + \
str(self._get_service_external_port(service_name))
service_url[service_name] = value

# Use fabric-explorer as dashboard
if "fabric-explorer" in service_name:
service_url["dashboard"] = value
service = i.metadata.name
break

return service_url
service_ip = self._get_node_ip_of_service(service)
service_urls = self._get_service_external_port(cluster_name,
service_ip)
return service_urls

def _get_cluster_ports(self, ports_index):
logger.debug("Current exsiting cluster ports= {}".format(ports_index))
Expand All @@ -402,19 +438,19 @@ def _get_cluster_ports(self, ports_index):
current_path = os.path.dirname(__file__)
templates_path = os.path.join(current_path, "templates")
for (dir_path, dir_name, file_list) in os.walk(templates_path):
for file in file_list:
# pvc and namespace files do not have port mapping
if ("pvc" not in file and "namespace" not in file and
"cli" not in file):
if "peer" in file:
for f in file_list:
# pvc and namespace fs do not have port mapping
if ("pvc" not in f and "namespace" not in f and
"cli" not in f):
if "peer" in f:
peers_ports = {}
peers_ports["externalPort"] = str(current_port)
peers_ports["chaincodePort"] = str(current_port + 1)
peers_ports["nodePort"] = str(current_port + 2)
current_port = current_port + 3
cluster_ports[file] = peers_ports
cluster_ports[f] = peers_ports
else:
cluster_ports[file] = str(current_port)
cluster_ports[f] = str(current_port)
current_port = current_port + 1
logger.debug("return generated cluster ports= {}"
.format(cluster_ports))
Expand Down

0 comments on commit 3311ff7

Please sign in to comment.