Fix get LoadBalancer IP implementation

For services of Type 'LoadBalancer'  Kuryr controller stores the
External IP at service.status.
In some cases, OpenShift may overwrite the service.status value.
This patch updates 'get_service_ip' to return the IP that was allocated by Kuryr controller.

Change-Id: Ia5f766ba938e2972c022fb1e7cbf3c0374a344f2
This commit is contained in:
Yossi Boaron 2018-07-12 10:14:37 +03:00
parent a4c8d8a4f4
commit 9a68b87704
1 changed files with 29 additions and 2 deletions

View File

@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import time
from oslo_log import log as logging
@ -34,6 +34,8 @@ LOG = logging.getLogger(__name__)
KURYR_NET_CRD_GROUP = 'openstack.org'
KURYR_NET_CRD_VERSION = 'v1'
KURYR_NET_CRD_PLURAL = 'kuryrnets'
K8S_ANNOTATION_PREFIX = 'openstack.org/kuryr'
K8S_ANNOTATION_LBAAS_STATE = K8S_ANNOTATION_PREFIX + '-lbaas-state'
class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
@ -202,7 +204,32 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
time.sleep(5)
service = api.read_namespaced_service(service_name, namespace)
if spec_type == "LoadBalancer":
# NOTE(yboaron): In some cases, OpenShift may overwrite
# LB's IP stored at service.status, we need to make sure that
# this function will return the IP that was annotated by
# Kuryr controller
if service.status.load_balancer.ingress:
endpoints = api.read_namespaced_endpoints(
service_name, namespace)
annotations = endpoints.metadata.annotations
try:
ann_dict = json.loads(
annotations[K8S_ANNOTATION_LBAAS_STATE])
ann_lb_ip = (
ann_dict["versioned_object.data"]
["service_pub_ip_info"]
["versioned_object.data"]
["ip_addr"])
except KeyError:
LOG.info("Waiting till LB's IP appears in annotation "
"(ingress.ip=%s)"
% service.status.load_balancer.ingress[0].ip)
continue
if ann_lb_ip != service.status.load_balancer.ingress[0].ip:
LOG.warning('Annotated pub_ip(%s) != ingress.ip(%s).'
% ann_lb_ip,
service.status.load_balancer.ingress[0].ip)
return ann_lb_ip
return service.status.load_balancer.ingress[0].ip
elif spec_type == "ClusterIP":
return service.spec.cluster_ip
@ -233,7 +260,7 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest):
cls.addClassResourceCleanup(cls.delete_pod, pod_name)
service_name, service_obj = cls.create_service(
pod_label=pod.metadata.labels, spec_type=spec_type)
cls.service_ip = cls.get_service_ip(service_name)
cls.service_ip = cls.get_service_ip(service_name, spec_type=spec_type)
cls.wait_service_status(
cls.service_ip, CONF.kuryr_kubernetes.lb_build_timeout)