Skip to content

Commit 0d2a3b6

Browse files
committed
fix(certificates): only delete k8s secrets for certs when last domain associated is detached
Before the code would delete the secret on every detach but now instead it checks if there are any domains associated still with the certificate before deleting. It can do so before the association between domain and cert is nulled out a few lines up. This wasn't caught since the exception rule is to log the error instead of blowing up. There are tests that expose this behaviour but only against a real k8s cluster
1 parent 4f6b31b commit 0d2a3b6

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

rootfs/api/models/certificate.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,16 @@ def detach(self, *args, **kwargs):
202202

203203
name = '%s-cert' % self.name
204204
app = domain.app
205-
# only delete if it exists
206-
try:
207-
# We raise an exception when a secret doesn't exist
208-
self._scheduler._get_secret(app, name)
209-
self._scheduler._delete_secret(app, name)
210-
except KubeHTTPException as e:
211-
logger.critical(e)
205+
206+
# only delete if it exists and if no other domains depend on secret
207+
if len(self.domains):
208+
try:
209+
# We raise an exception when a secret doesn't exist
210+
self._scheduler._get_secret(app, name)
211+
self._scheduler._delete_secret(app, name)
212+
except KubeHTTPException as e:
213+
logger.critical(e)
214+
raise EnvironmentError("Could not delete certificate secret {} for application {}".format(name, app)) # noqa
212215

213216
# get config for the service
214217
config = self._load_service_config(app, 'router')

0 commit comments

Comments
 (0)