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()
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)
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()