Ejemplo n.º 1
0
 def _enqueue_delete_ingress(self, ingress_meta):
     ingress_spec = {'type': None}
     ingress_del_event = self.create_event('Ingress', ingress_spec,
                                           ingress_meta, 'DELETED')
     IngressKM.delete(ingress_meta['uid'])
     self.enqueue_event(ingress_del_event)
     self.wait_for_all_tasks_done()
    def _enqueue_add_ingress(self, namespace_name):
        ingress_uuid = str(uuid.uuid4())
        ingress_name = 'test-ingress'
        ingress_meta = {'name': ingress_name, 'uid': ingress_uuid,
                        'namespace': namespace_name}
        ingress_spec = {
            'rules': [{
                'http': {
                    'paths': [{
                        'path': '/testpath',
                        'backend': {
                            'serviceName': 'test-service',
                            'servicePort': SERVICE_PORT}
                    }]
                }
            }]
        }
        annotations = {'ingress.kubernetes.io/rewrite-target': '/'}
        ingress_add_event = self.create_event('Ingress', ingress_spec,
                                              ingress_meta,
                                              'ADDED')
        ingress_add_event['object']['metadata']['annotations'] = annotations
        IngressKM.locate(ingress_uuid, ingress_add_event['object'])

        self.kube_mock.get_resource.return_value = {'spec': {
            "clusterIP": self.cluster_ip,
        }}

        self.enqueue_event(ingress_add_event)
        self.wait_for_all_tasks_done()
        return ingress_meta, ingress_uuid
    def _enqueue_add_ingress(self, namespace_name):
        ingress_uuid = str(uuid.uuid4())
        ingress_name = 'test-ingress'
        ingress_meta = {'name': ingress_name, 'uid': ingress_uuid,
                        'namespace': namespace_name}
        ingress_spec = {
            'rules': [{
                'http': {
                    'paths': [{
                        'path': '/testpath',
                        'backend': {
                            'serviceName': 'test-service',
                            'servicePort': SERVICE_PORT}
                    }]
                }
            }]
        }
        annotations = {'ingress.kubernetes.io/rewrite-target': '/'}
        ingress_add_event = self.create_event('Ingress', ingress_spec,
                                              ingress_meta,
                                              'ADDED')
        ingress_add_event['object']['metadata']['annotations'] = annotations
        IngressKM.locate(ingress_uuid, ingress_add_event['object'])

        self.kube_mock.get_resource.return_value = {'spec': {
            "clusterIP": self.cluster_ip,
        }}

        self.enqueue_event(ingress_add_event)
        return ingress_meta, ingress_uuid
 def _enqueue_delete_ingress(self, ingress_meta):
     ingress_spec = {'type': None}
     ingress_del_event = self.create_event(
         'Ingress', ingress_spec, ingress_meta, 'DELETED')
     IngressKM.delete(ingress_meta['uid'])
     self.enqueue_event(ingress_del_event)
     self.wait_for_all_tasks_done()
    def _sync_ingress_lb(self):
        lb_uuid_set = set(LoadbalancerKM.keys())
        ingress_uuid_set = set(IngressKM.keys())
        deleted_ingress_set = lb_uuid_set - ingress_uuid_set
        for uuid in deleted_ingress_set:
            lb = LoadbalancerKM.get(uuid)
            if not lb:
                continue
            if not lb.annotations:
                continue
            owner = None
            kind = None
            cluster = None
            for kvp in lb.annotations['key_value_pair'] or []:
                if kvp['key'] == 'cluster':
                    cluster = kvp['value']
                elif kvp['key'] == 'owner':
                    owner = kvp['value']
                elif kvp['key'] == 'kind':
                    kind = kvp['value']

                if cluster == vnc_kube_config.cluster_name() and \
                   owner == 'k8s' and \
                   kind == self._k8s_event_type:
                    self._create_ingress_event('delete', uuid, lb)
                    break
        return
    def update_ingress_backend(self, ns_name, service_name, oper):
        ingress_ids = self._find_ingress(self._ingress_label_cache, ns_name,
                                         service_name)
        for ingress_id in ingress_ids or []:
            ingress = IngressKM.get(ingress_id)
            lb = LoadbalancerKM.get(ingress_id)
            if not ingress or not lb:
                continue
            if oper == 'ADD':
                new_backend_list = self._get_new_backend_list(
                    ingress.spec, ns_name)
                for new_backend in new_backend_list[:] or []:
                    if new_backend['member']['serviceName'] == service_name:

                        # Create a firewall rule for ingress to this service.
                        fw_uuid = VncIngress.add_ingress_to_service_rule(
                            ns_name, ingress.name, service_name)
                        lb.add_firewall_rule(fw_uuid)

                        self._create_listener_pool_member(
                            ns_name, lb, new_backend)
            else:
                old_backend_list = self._get_old_backend_list(lb)
                for old_backend in old_backend_list[:] or []:
                    if old_backend['member']['serviceName'] == service_name:
                        self._delete_listener(old_backend['listener_id'])

                        # Delete rules created for this ingress to service.
                        deleted_fw_rule_uuid =\
                            VncIngress.delete_ingress_to_service_rule(ns_name,
                                                                  ingress.name,
                                                                  service_name)
                        lb.remove_firewall_rule(deleted_fw_rule_uuid)
Ejemplo n.º 7
0
 def _sync_ingress_lb(self):
     lb_uuid_list = list(LoadbalancerKM.keys())
     ingress_uuid_list = list(IngressKM.keys())
     for uuid in lb_uuid_list:
         if uuid in ingress_uuid_list:
             continue
         lb = LoadbalancerKM.get(uuid)
         if not lb:
             continue
         if not lb.annotations:
             continue
         for kvp in lb.annotations['key_value_pair'] or []:
             if kvp['key'] == 'owner' \
                and kvp['value'] == 'k8s':
                 self._create_ingress_event('delete', uuid, lb)
                 break
     return
 def update_ingress_backend(self, ns_name, service_name, oper):
     ingress_ids = self._find_ingress(
         self._ingress_label_cache, ns_name, service_name)
     for ingress_id in ingress_ids or []:
         ingress = IngressKM.get(ingress_id)
         lb = LoadbalancerKM.get(ingress_id)
         if not ingress or not lb:
             continue
         if oper == 'ADD':
             new_backend_list = self._get_new_backend_list(ingress.spec, ns_name)
             for new_backend in new_backend_list[:] or []:
                 if new_backend['member']['serviceName'] == service_name:
                     self._create_listener_pool_member(
                         ns_name, lb, new_backend)
         else:
             old_backend_list = self._get_old_backend_list(lb)
             for old_backend in old_backend_list[:] or []:
                 if old_backend['member']['serviceName'] == service_name:
                     self._delete_listener(old_backend['listener_id'])
Ejemplo n.º 9
0
 def _sync_ingress_lb(self):
     lb_uuid_set = set(LoadbalancerKM.keys())
     ingress_uuid_set = set(IngressKM.keys())
     deleted_ingress_set = lb_uuid_set - ingress_uuid_set
     for uuid in deleted_ingress_set:
         lb = LoadbalancerKM.get(uuid)
         if not lb:
             continue
         if not lb.annotations:
             continue
         owner = None
         kind = None
         for kvp in lb.annotations['key_value_pair'] or []:
             if kvp['key'] == 'owner':
                 owner = kvp['value']
             elif kvp['key'] == 'kind':
                 kind = kvp['value']
             if owner == 'k8s' and kind == self._k8s_event_type:
                 self._create_ingress_event('delete', uuid, lb)
                 break
     return