Exemplo n.º 1
0
 def test_apply_tls(self, tls, app_spec, spec_tls, tls_annotations):
     ingress = Ingress()
     ingress.metadata = ObjectMeta()
     ingress.spec = IngressSpec()
     tls.apply(ingress, app_spec, self.HOSTS)
     assert ingress.metadata.annotations == tls_annotations
     assert ingress.spec.tls == spec_tls
 def test_apply_tls(self, tls, app_spec, spec_tls, issuer_type,
                    tls_annotations):
     ingress = Ingress()
     ingress.metadata = ObjectMeta(name=app_spec.name)
     tls.apply(ingress, app_spec, self.HOSTS, issuer_type)
     assert ingress.metadata.annotations == tls_annotations
     assert ingress.spec.tls == spec_tls
Exemplo n.º 3
0
            def _check_two_ingresses():
                assert Ingress.get(name)
                assert Ingress.get("{}-1".format(name))

                for ingress_name, expected_dict in expected.items():
                    actual = Ingress.get(ingress_name)
                    assert_k8s_resource_matches(actual, expected_dict, IMAGE1, None, DEPLOYMENT_ID1, None, app_uid)
Exemplo n.º 4
0
 def delete(self, app_spec):
     LOG.info("Deleting ingresses for %s", app_spec.name)
     try:
         Ingress.delete_list(namespace=app_spec.namespace,
                             labels={
                                 "app": Equality(app_spec.name),
                                 "fiaas/deployment_id": Exists()
                             })
     except NotFound:
         pass
Exemplo n.º 5
0
def _get_ingresses():
    # The find method doesn't allow the query we need, so we do it outside
    resp = Ingress._client.get(Ingress._meta.list_url,
                               params={"labelSelector": "fiaas/deployed_by"})
    all_ingresses = [Ingress.from_dict(item) for item in resp.json()["items"]]
    tls_ingresses = [ing for ing in all_ingresses if ing.spec.tls]
    return tls_ingresses
    def test_apply_with_no_uid(self, app_spec, owner_references):
        ingress = Ingress(metadata=ObjectMeta())
        app_spec = app_spec._replace(uid=None)

        owner_references.apply(ingress, app_spec)

        assert ingress.metadata.ownerReferences == []
Exemplo n.º 7
0
    def _create(self, app_spec, labels):
        LOG.info("Creating/updating ingress for %s", app_spec.name)
        annotations = {
            u"fiaas/expose":
            u"true" if _has_explicitly_set_host(app_spec) else u"false"
        }

        custom_labels = merge_dicts(app_spec.labels.ingress, labels)
        custom_annotations = merge_dicts(app_spec.annotations.ingress,
                                         annotations)
        metadata = ObjectMeta(name=app_spec.name,
                              namespace=app_spec.namespace,
                              labels=custom_labels,
                              annotations=custom_annotations)

        per_host_ingress_rules = [
            IngressRule(host=self._apply_host_rewrite_rules(ingress_item.host),
                        http=self._make_http_ingress_rule_value(
                            app_spec, ingress_item.pathmappings))
            for ingress_item in app_spec.ingresses
            if ingress_item.host is not None
        ]
        default_host_ingress_rules = self._create_default_host_ingress_rules(
            app_spec)

        ingress_spec = IngressSpec(rules=per_host_ingress_rules +
                                   default_host_ingress_rules)

        ingress = Ingress.get_or_create(metadata=metadata, spec=ingress_spec)
        self._ingress_tls.apply(ingress, app_spec, self._get_hosts(app_spec))
        ingress.save()
Exemplo n.º 8
0
def _create_default_ingress():
    object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE, labels={"test": "true"})
    ingress_backend = IngressBackend(serviceName="dummy", servicePort="http")
    http_ingress_path = HTTPIngressPath(path="/", backend=ingress_backend)
    http_ingress_rule = HTTPIngressRuleValue(paths=[http_ingress_path])
    ingress_rule = IngressRule(host="dummy.example.com", http=http_ingress_rule)
    ingress_spec = IngressSpec(rules=[ingress_rule])
    ingress = Ingress(metadata=object_meta, spec=ingress_spec)
    return ingress
Exemplo n.º 9
0
    def test_updated_if_exists(self, get, put):
        mock_response = _create_mock_response()
        get.return_value = mock_response
        ingress = _create_default_ingress()

        from_api = Ingress.get_or_create(metadata=ingress.metadata, spec=ingress.spec)
        assert not from_api._new
        assert from_api.spec.rules[0].host == "dummy.example.com"
        call_params = from_api.as_dict()

        from_api.save()
        pytest.helpers.assert_any_call(put, _uri(NAMESPACE, NAME), call_params)
Exemplo n.º 10
0
    def _create_ingress(self, app_spec, annotated_ingress, labels):
        default_annotations = {
            u"fiaas/expose":
            u"true" if _has_explicitly_set_host(
                annotated_ingress.ingress_items) else u"false"
        }
        annotations = merge_dicts(app_spec.annotations.ingress,
                                  annotated_ingress.annotations,
                                  default_annotations)

        metadata = ObjectMeta(name=annotated_ingress.name,
                              namespace=app_spec.namespace,
                              labels=labels,
                              annotations=annotations)

        per_host_ingress_rules = [
            IngressRule(host=self._apply_host_rewrite_rules(ingress_item.host),
                        http=self._make_http_ingress_rule_value(
                            app_spec, ingress_item.pathmappings))
            for ingress_item in annotated_ingress.ingress_items
            if ingress_item.host is not None
        ]
        if annotated_ingress.annotations:
            use_suffixes = False
            host_ingress_rules = per_host_ingress_rules
        else:
            use_suffixes = True
            host_ingress_rules = per_host_ingress_rules + self._create_default_host_ingress_rules(
                app_spec)

        ingress_spec = IngressSpec(rules=host_ingress_rules)

        ingress = Ingress.get_or_create(metadata=metadata, spec=ingress_spec)

        hosts_for_tls = [rule.host for rule in host_ingress_rules]
        self._ingress_tls.apply(ingress,
                                app_spec,
                                hosts_for_tls,
                                use_suffixes=use_suffixes)
        self._owner_references.apply(ingress, app_spec)
        ingress.save()
Exemplo n.º 11
0
 def test_create_blank(self):
     object_meta = ObjectMeta(name=NAME,
                              namespace=NAMESPACE,
                              labels={"test": "true"})
     ingress = Ingress(metadata=object_meta)
     assert ingress.as_dict()[u"metadata"][u"name"] == NAME
    def test_apply(self, app_spec, owner_references, expected):
        ingress = Ingress(metadata=ObjectMeta())

        owner_references.apply(ingress, app_spec)

        assert ingress.metadata.ownerReferences == [expected]
Exemplo n.º 13
0
 def _delete_unused(self, app_spec, labels):
     filter_labels = [("app", Equality(labels["app"])),
                      ("fiaas/deployment_id", Exists()),
                      ("fiaas/deployment_id",
                       Inequality(labels["fiaas/deployment_id"]))]
     Ingress.delete_list(namespace=app_spec.namespace, labels=filter_labels)
Exemplo n.º 14
0
 def delete(self, app_spec):
     LOG.info("Deleting ingress for %s", app_spec.name)
     try:
         Ingress.delete(app_spec.name, app_spec.namespace)
     except NotFound:
         pass
Exemplo n.º 15
0
 def cleanup_complete():
     for name, _ in expected.items():
         with pytest.raises(NotFound):
             Ingress.get(name)
Exemplo n.º 16
0
 def _check_one_ingress():
     assert Ingress.get(name)
     with pytest.raises(NotFound):
         Ingress.get("{}-1".format(name))