From 175a6d52277d321a93310dbe78d81a4ff68d2a10 Mon Sep 17 00:00:00 2001 From: Jack Lucas Date: Fri, 19 Apr 2019 15:14:25 -0400 Subject: Fix DR subscriber failure Issue-ID: DCAEGEN2-1009 Change-Id: Ieb770b6562123dda78fd4b8c8c514d30767ad7fb Signed-off-by: Jack Lucas --- k8s/ChangeLog.md | 3 +++ k8s/k8s-node-type.yaml | 2 +- k8s/k8sclient/__init__.py | 2 +- k8s/k8sclient/k8sclient.py | 4 ++-- k8s/k8splugin/tasks.py | 23 ++++++++--------------- k8s/pom.xml | 2 +- k8s/setup.py | 2 +- k8s/tests/test_k8sclient.py | 8 ++++---- k8s/tests/test_tasks.py | 29 +++-------------------------- 9 files changed, 24 insertions(+), 51 deletions(-) diff --git a/k8s/ChangeLog.md b/k8s/ChangeLog.md index ee209ee..7a90f78 100644 --- a/k8s/ChangeLog.md +++ b/k8s/ChangeLog.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.4.13] + Fix bug related to setting the delivery URL for a DR subscriber. (DCAEGEN2-1009) + ## [1.4.12] Change location of kubeconfig file for multi-cluster support. Put the file in a subdirectory so that the k8s volume mount does not require a diff --git a/k8s/k8s-node-type.yaml b/k8s/k8s-node-type.yaml index b51a23f..273da7a 100644 --- a/k8s/k8s-node-type.yaml +++ b/k8s/k8s-node-type.yaml @@ -25,7 +25,7 @@ plugins: k8s: executor: 'central_deployment_agent' package_name: k8splugin - package_version: 1.4.12 + package_version: 1.4.13 data_types: diff --git a/k8s/k8sclient/__init__.py b/k8s/k8sclient/__init__.py index 3cc19f2..6a53440 100644 --- a/k8s/k8sclient/__init__.py +++ b/k8s/k8sclient/__init__.py @@ -17,4 +17,4 @@ # ============LICENSE_END========================================================= # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -from .k8sclient import deploy, undeploy, is_available, scale, upgrade, rollback, execute_command_in_deployment \ No newline at end of file +from .k8sclient import deploy, undeploy, is_available, scale, upgrade, rollback, execute_command_in_deployment, parse_ports \ No newline at end of file diff --git a/k8s/k8sclient/k8sclient.py b/k8s/k8sclient/k8sclient.py index f8a9ecc..681ea6b 100644 --- a/k8s/k8sclient/k8sclient.py +++ b/k8s/k8sclient/k8sclient.py @@ -237,7 +237,7 @@ def _create_service_object(service_name, component_name, service_ports, annotati ) return service -def _parse_ports(port_list): +def parse_ports(port_list): ''' Parse the port list into a list of container ports (needed to create the container) and to a set of port mappings to set up k8s services. @@ -425,7 +425,7 @@ def deploy(namespace, component_name, image, replicas, always_pull, k8sconfig, r ext = client.ExtensionsV1beta1Api() # Parse the port mapping - container_ports, port_map = _parse_ports(kwargs.get("ports", [])) + container_ports, port_map = parse_ports(kwargs.get("ports", [])) # Parse the volumes list into volumes and volume_mounts for the deployment volumes, volume_mounts = _parse_volumes(kwargs.get("volumes",[])) diff --git a/k8s/k8splugin/tasks.py b/k8s/k8splugin/tasks.py index b8669e2..ab72b57 100644 --- a/k8s/k8splugin/tasks.py +++ b/k8s/k8splugin/tasks.py @@ -231,20 +231,6 @@ def create_for_platforms(**create_inputs): **_setup_for_discovery( **create_inputs)) - -def _lookup_service(service_component_name, consul_host=CONSUL_HOST, - with_port=False): - conn = dis.create_kv_conn(consul_host) - results = dis.lookup_service(conn, service_component_name) - - if with_port: - # Just grab first - result = results[0] - return "{address}:{port}".format(address=result["ServiceAddress"], - port=result["ServicePort"]) - else: - return results[0]["ServiceAddress"] - def _verify_k8s_deployment(location, service_component_name, max_wait): """Verify that the k8s Deployment is ready @@ -490,7 +476,14 @@ def _update_delivery_url(**kwargs): # TODO: Should NOT be setting up the delivery url with ip addresses # because in the https case, this will not work because data router does # a certificate validation using the fqdn. - subscriber_host = _lookup_service(service_component_name, with_port=True) + ports,_ = k8sclient.parse_ports(kwargs["ports"]) + (dport, _) = ports[0] + # Using service_component_name as the host name in the subscriber URL + # will work in a single-cluster ONAP deployment. Whether it will also work + # in a multi-cluster ONAP deployment--with a central location and one or + # more remote ("edge") locations depends on how networking and DNS is set + # up in a multi-cluster deployment + subscriber_host = "{host}:{port}".format(host=service_component_name, port=dport) for dr_sub in dr_subs: scheme = dr_sub["scheme"] if "scheme" in dr_sub else DEFAULT_SCHEME diff --git a/k8s/pom.xml b/k8s/pom.xml index 6a12eac..b99816a 100644 --- a/k8s/pom.xml +++ b/k8s/pom.xml @@ -28,7 +28,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. org.onap.dcaegen2.platform.plugins k8s k8s-plugin - 1.4.12-SNAPSHOT + 1.4.13-SNAPSHOT http://maven.apache.org UTF-8 diff --git a/k8s/setup.py b/k8s/setup.py index c8fd2ef..6a9dcac 100644 --- a/k8s/setup.py +++ b/k8s/setup.py @@ -23,7 +23,7 @@ from setuptools import setup setup( name='k8splugin', description='Cloudify plugin for containerized components deployed using Kubernetes', - version="1.4.12", + version="1.4.13", author='J. F. Lucas, Michael Hwang, Tommy Carpenter', packages=['k8splugin','k8sclient','msb','configure'], zip_safe=False, diff --git a/k8s/tests/test_k8sclient.py b/k8s/tests/test_k8sclient.py index 43939ad..70ebf05 100644 --- a/k8s/tests/test_k8sclient.py +++ b/k8s/tests/test_k8sclient.py @@ -86,7 +86,7 @@ def test_parse_interval(): _parse_interval(interval) def test_parse_ports(): - from k8sclient.k8sclient import _parse_ports + from k8sclient.k8sclient import parse_ports good_ports = [{"in": input, "ex": expected} for (input, expected) in [ @@ -133,16 +133,16 @@ def test_parse_ports(): } for test_case in good_ports: - container_ports, port_map = _parse_ports([test_case["in"]]) + container_ports, port_map = parse_ports([test_case["in"]]) (cport, hport, proto) = test_case["ex"] assert container_ports == [(cport, proto)] assert port_map == {(cport, proto) : hport} for port in bad_ports: with pytest.raises(ValueError): - _parse_ports([port]) + parse_ports([port]) - container_ports, port_map = _parse_ports(port_list) + container_ports, port_map = parse_ports(port_list) assert port_map == expected_port_map def test_create_container(): diff --git a/k8s/tests/test_tasks.py b/k8s/tests/test_tasks.py index d56a443..933753a 100644 --- a/k8s/tests/test_tasks.py +++ b/k8s/tests/test_tasks.py @@ -174,21 +174,6 @@ def test_setup_for_discovery_streams(monkeypatch, mockconfig): with pytest.raises(NonRecoverableError): tasks._setup_for_discovery_streams(**test_input) - -def test_lookup_service(monkeypatch, mockconfig): - import k8splugin - from k8splugin import tasks - def fake_lookup(conn, scn): - return [{"ServiceAddress": "192.168.1.1", "ServicePort": "80"}] - - monkeypatch.setattr(k8splugin.discovery, "lookup_service", - fake_lookup) - - assert "192.168.1.1" == tasks._lookup_service("some-component") - assert "192.168.1.1:80" == tasks._lookup_service("some-component", - with_port=True) - - def test_verify_container(monkeypatch, mockconfig): import k8sclient from k8splugin import tasks @@ -222,20 +207,12 @@ def test_update_delivery_url(monkeypatch, mockconfig): {'type': 'data_router', 'name': 'feed01', 'username': 'hero', 'password': '123456', 'location': 'Bedminster', 'route': 'some-path'}], - 'topic01': {'type': 'message_router', 'name': 'topic01'}} + 'topic01': {'type': 'message_router', 'name': 'topic01'}, + 'ports': ['8080/tcp:0']} test_input["service_component_name"] = "some-foo-service-component" - def fake_lookup_service(name, with_port=False): - if with_port: - return "10.100.1.100:8080" - else: - return - - monkeypatch.setattr(k8splugin.tasks, "_lookup_service", - fake_lookup_service) - expected = copy.deepcopy(test_input) - expected["feed01"]["delivery_url"] = "http://10.100.1.100:8080/some-path" + expected["feed01"]["delivery_url"] = "http://some-foo-service-component:8080/some-path" assert tasks._update_delivery_url(**test_input) == expected -- cgit 1.2.3-korg