Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove code-path for responding to Delete events #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions fiaas_deploy_daemon/crd/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions fiaas_deploy_daemon/deployer/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def __call__(self):
LOG.info("Received %r for %s", event.app_spec, event.action)
if event.action == "UPDATE":
self._update(event.app_spec, event.lifecycle_subject)
elif event.action == "DELETE":
self._delete(event.app_spec)
else:
raise ValueError("Unknown DeployerEvent action {}".format(event.action))

Expand All @@ -69,10 +67,6 @@ def _update(self, app_spec, lifecycle_subject):
self._lifecycle.failed(lifecycle_subject)
self._bookkeeper.failed(app_spec)

def _delete(self, app_spec):
self._adapter.delete(app_spec)
LOG.info("Completed removal of %r", app_spec)


def _make_gen(func):
while True:
Expand Down
6 changes: 0 additions & 6 deletions fiaas_deploy_daemon/deployer/kubernetes/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions fiaas_deploy_daemon/deployer/kubernetes/autoscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions fiaas_deploy_daemon/deployer/kubernetes/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions fiaas_deploy_daemon/deployer/kubernetes/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 8 additions & 18 deletions tests/fiaas_deploy_daemon/crd/test_crd_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
"type": WatchEvent.MODIFIED,
}

DELETED_EVENT = {
"object": ADD_EVENT["object"],
"type": WatchEvent.DELETED,
}


class TestWatcher(object):

Expand Down Expand Up @@ -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):
Expand All @@ -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()
Expand All @@ -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"])
Expand Down