diff --git a/fiaas_deploy_daemon/crd/watcher.py b/fiaas_deploy_daemon/crd/watcher.py index f1f87e6d..824c9091 100644 --- a/fiaas_deploy_daemon/crd/watcher.py +++ b/fiaas_deploy_daemon/crd/watcher.py @@ -80,9 +80,7 @@ def _create(kind, plural, short_names, group): def _handle_watch_event(self, event): if event.type in (WatchEvent.ADDED, WatchEvent.MODIFIED): self._deploy(event.object) - elif event.type == WatchEvent.DELETED: - self._delete(event.object) - else: + elif event.type != WatchEvent.DELETED: raise ValueError("Unknown WatchEvent type {}".format(event.type)) def _deploy(self, application): @@ -127,23 +125,6 @@ def _deploy(self, application): LOG.exception("Failed to create app spec from fiaas config file") self._lifecycle.failed(lifecycle_subject) - def _delete(self, application): - app_spec = self._spec_factory( - uid=application.metadata.uid, - name=application.spec.application, - image=application.spec.image, - app_config=application.spec.config, - teams=[], - tags=[], - deployment_id="deletion", - namespace=application.metadata.namespace, - additional_labels=application.spec.additional_labels, - additional_annotations=application.spec.additional_annotations, - ) - set_extras(app_spec) - self._deploy_queue.put(DeployerEvent("DELETE", app_spec, lifecycle_subject=None)) - LOG.debug("Queued delete for %s", application.spec.application) - def _already_deployed(self, app_name, namespace, deployment_id): try: name = create_name(app_name, deployment_id) diff --git a/fiaas_deploy_daemon/deployer/kubernetes/adapter.py b/fiaas_deploy_daemon/deployer/kubernetes/adapter.py index d9057bef..0a89b897 100644 --- a/fiaas_deploy_daemon/deployer/kubernetes/adapter.py +++ b/fiaas_deploy_daemon/deployer/kubernetes/adapter.py @@ -47,12 +47,6 @@ def deploy(self, app_spec): self._deployment_deployer.deploy(app_spec, selector, labels, _besteffort_qos_is_required(app_spec)) self._autoscaler_deployer.deploy(app_spec, labels) - def delete(self, app_spec): - self._ingress_deployer.delete(app_spec) - self._autoscaler_deployer.delete(app_spec) - self._service_deployer.delete(app_spec) - self._deployment_deployer.delete(app_spec) - def _make_labels(self, app_spec): labels = { "app": app_spec.name, diff --git a/fiaas_deploy_daemon/deployer/kubernetes/autoscaler.py b/fiaas_deploy_daemon/deployer/kubernetes/autoscaler.py index b90eb92a..15ca2b42 100644 --- a/fiaas_deploy_daemon/deployer/kubernetes/autoscaler.py +++ b/fiaas_deploy_daemon/deployer/kubernetes/autoscaler.py @@ -55,13 +55,6 @@ def deploy(self, app_spec, labels): except NotFound: pass - def delete(self, app_spec): - LOG.info("Deleting autoscaler for %s", app_spec.name) - try: - HorizontalPodAutoscaler.delete(app_spec.name, app_spec.namespace) - except NotFound: - pass - def should_have_autoscaler(app_spec): if not _autoscaler_enabled(app_spec.autoscaler): diff --git a/fiaas_deploy_daemon/deployer/kubernetes/deployment/deployer.py b/fiaas_deploy_daemon/deployer/kubernetes/deployment/deployer.py index fbdd2fdf..7b09aa07 100644 --- a/fiaas_deploy_daemon/deployer/kubernetes/deployment/deployer.py +++ b/fiaas_deploy_daemon/deployer/kubernetes/deployment/deployer.py @@ -124,14 +124,6 @@ def deploy(self, app_spec, selector, labels, besteffort_qos_is_required): self._owner_references.apply(deployment, app_spec) deployment.save() - def delete(self, app_spec): - LOG.info("Deleting deployment for %s", app_spec.name) - try: - body = {"kind": "DeleteOptions", "apiVersion": "v1", "propagationPolicy": "Foreground"} - Deployment.delete(app_spec.name, app_spec.namespace, body=body) - except NotFound: - pass - def _make_volumes(self, app_spec): volumes = [] volumes.append(Volume(name="{}-config".format(app_spec.name), diff --git a/fiaas_deploy_daemon/deployer/kubernetes/ingress.py b/fiaas_deploy_daemon/deployer/kubernetes/ingress.py index 6a15d5c6..dcb7b6db 100644 --- a/fiaas_deploy_daemon/deployer/kubernetes/ingress.py +++ b/fiaas_deploy_daemon/deployer/kubernetes/ingress.py @@ -43,9 +43,9 @@ def deploy(self, app_spec, labels): if self._should_have_ingress(app_spec): self._create(app_spec, labels) else: - self.delete(app_spec) + self._delete(app_spec) - def delete(self, app_spec): + def _delete(self, app_spec): LOG.info("Deleting ingress for %s", app_spec.name) try: Ingress.delete(app_spec.name, app_spec.namespace) diff --git a/fiaas_deploy_daemon/deployer/kubernetes/service.py b/fiaas_deploy_daemon/deployer/kubernetes/service.py index ec202b20..a3fdf1f5 100644 --- a/fiaas_deploy_daemon/deployer/kubernetes/service.py +++ b/fiaas_deploy_daemon/deployer/kubernetes/service.py @@ -38,9 +38,9 @@ def deploy(self, app_spec, selector, labels): if self._should_have_service(app_spec): self._create(app_spec, selector, labels) else: - self.delete(app_spec) + self._delete(app_spec) - def delete(self, app_spec): + def _delete(self, app_spec): LOG.info("Deleting service for %s", app_spec.name) try: Service.delete(app_spec.name, app_spec.namespace) diff --git a/tests/fiaas_deploy_daemon/crd/test_crd_watcher.py b/tests/fiaas_deploy_daemon/crd/test_crd_watcher.py index 61abfee8..f6c48d98 100644 --- a/tests/fiaas_deploy_daemon/crd/test_crd_watcher.py +++ b/tests/fiaas_deploy_daemon/crd/test_crd_watcher.py @@ -63,11 +63,6 @@ "type": WatchEvent.MODIFIED, } -DELETED_EVENT = { - "object": ADD_EVENT["object"], - "type": WatchEvent.DELETED, -} - class TestWatcher(object): @@ -166,7 +161,6 @@ def test_is_able_to_watch_custom_resource_definition(self, crd_watcher, deploy_q (ADD_EVENT, "UPDATE", {"deployment": {"fiaas/source-repository": "xyz"}}, "xyz"), (MODIFIED_EVENT, "UPDATE", None, None), (MODIFIED_EVENT, "UPDATE", {"deployment": {"fiaas/source-repository": "xyz"}}, "xyz"), - (DELETED_EVENT, "DELETE", None, None), ]) def test_deploy(self, crd_watcher, deploy_queue, spec_factory, watcher, app_spec, event, deployer_event_type, lifecycle, annotations, repository): @@ -188,14 +182,13 @@ def test_deploy(self, crd_watcher, deploy_queue, spec_factory, watcher, app_spec crd_watcher._watch(None) - if event in [ADD_EVENT, MODIFIED_EVENT]: - lifecycle.initiate.assert_called_once_with(uid=event["object"]["metadata"]["uid"], - app_name=event["object"]["spec"]["application"], - namespace=event["object"]["metadata"]["namespace"], - deployment_id='deployment_id', - repository=repository, - labels=None, - annotations=None) + lifecycle.initiate.assert_called_once_with(uid=event["object"]["metadata"]["uid"], + app_name=event["object"]["spec"]["application"], + namespace=event["object"]["metadata"]["namespace"], + deployment_id='deployment_id', + repository=repository, + labels=None, + annotations=None) app_config = spec["config"] additional_labels = AdditionalLabelsOrAnnotations() @@ -210,10 +203,7 @@ def test_deploy(self, crd_watcher, deploy_queue, spec_factory, watcher, app_spec assert deploy_queue.qsize() == 1 deployer_event = deploy_queue.get_nowait() - if event in [ADD_EVENT, MODIFIED_EVENT]: - assert deployer_event == DeployerEvent(deployer_event_type, app_spec, lifecycle_subject) - else: - assert deployer_event == DeployerEvent(deployer_event_type, app_spec, None) + assert deployer_event == DeployerEvent(deployer_event_type, app_spec, lifecycle_subject) assert deploy_queue.empty() @pytest.mark.parametrize("namespace", [None, "default"])