summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Eagan <sean.eagan@att.com>2019-01-11 13:44:13 -0600
committerSean Eagan <sean.eagan@att.com>2019-01-29 16:49:01 -0600
commit47ebd27cad70e1b3e83519b029aa0b7455252a69 (patch)
tree3fb631a1ed5ac8953810eccb1f45f3d09ae97b37
parent091dbd283dbd6e7d547af5f2a81a555c39d89167 (diff)
Add configurability of delete timeout
Previously the timeout for deleting chart releases was 300s and not configurable, this patchset makes it so via a new `delete.timeout` property in the `armada/Chart/v1` schema. Helm releases deleted which do not correspond to documents in this schema still do not use a configurable timeout. Those will be considered separately. This also includes a minor logging fix. Change-Id: Ia588faaafd18a3ac00eed3cda2f0556ffcec82c9
Notes
Notes (review): Code-Review+2: Bryan Strassner <strassner.bryan@gmail.com> Code-Review+2: Pete Birley <petebirley@gmail.com> Workflow+1: Pete Birley <petebirley@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 31 Jan 2019 21:26:18 +0000 Reviewed-on: https://review.openstack.org/630779 Project: openstack/airship-armada Branch: refs/heads/master
-rw-r--r--armada/cli/delete.py20
-rw-r--r--armada/const.py1
-rw-r--r--armada/handlers/chart_delete.py52
-rw-r--r--armada/handlers/chart_deploy.py5
-rw-r--r--armada/handlers/tiller.py19
-rw-r--r--armada/schemas/armada-chart-schema.yaml5
-rw-r--r--armada/tests/unit/handlers/test_armada.py5
-rw-r--r--doc/source/operations/guide-build-armada-yaml.rst10
8 files changed, 101 insertions, 16 deletions
diff --git a/armada/cli/delete.py b/armada/cli/delete.py
index c54d3b3..bb92d91 100644
--- a/armada/cli/delete.py
+++ b/armada/cli/delete.py
@@ -19,6 +19,7 @@ from oslo_config import cfg
19 19
20from armada.cli import CliAction 20from armada.cli import CliAction
21from armada import const 21from armada import const
22from armada.handlers.chart_delete import ChartDelete
22from armada.handlers.manifest import Manifest 23from armada.handlers.manifest import Manifest
23from armada.handlers.tiller import Tiller 24from armada.handlers.tiller import Tiller
24from armada.utils.release import release_prefixer 25from armada.utils.release import release_prefixer
@@ -108,13 +109,13 @@ class DeleteChartManifest(CliAction):
108 if not self.ctx.obj.get('api', False): 109 if not self.ctx.obj.get('api', False):
109 for r in target_releases: 110 for r in target_releases:
110 self.logger.info("Deleting release %s", r) 111 self.logger.info("Deleting release %s", r)
111 tiller.uninstall_release(r, purge=self.purge) 112 tiller.delete_release(r, purge=self.purge)
112 113
113 else: 114 else:
114 raise NotImplementedError() 115 raise NotImplementedError()
115 116
116 if self.manifest: 117 if self.manifest:
117 target_releases = [] 118 target_deletes = []
118 119
119 with open(self.manifest) as f: 120 with open(self.manifest) as f:
120 documents = list(yaml.safe_load_all(f.read())) 121 documents = list(yaml.safe_load_all(f.read()))
@@ -126,11 +127,11 @@ class DeleteChartManifest(CliAction):
126 for group in armada_obj.get(const.KEYWORD_ARMADA).get( 127 for group in armada_obj.get(const.KEYWORD_ARMADA).get(
127 const.KEYWORD_GROUPS): 128 const.KEYWORD_GROUPS):
128 for ch in group.get(const.KEYWORD_CHARTS): 129 for ch in group.get(const.KEYWORD_CHARTS):
130 chart = ch.get('chart')
129 release_name = release_prefixer( 131 release_name = release_prefixer(
130 prefix, 132 prefix, chart.get('release'))
131 ch.get('chart').get('release'))
132 if release_name in known_release_names: 133 if release_name in known_release_names:
133 target_releases.append(release_name) 134 target_deletes.append((chart, release_name))
134 except yaml.YAMLError as e: 135 except yaml.YAMLError as e:
135 mark = e.problem_mark 136 mark = e.problem_mark
136 self.logger.info( 137 self.logger.info(
@@ -138,14 +139,15 @@ class DeleteChartManifest(CliAction):
138 "Error position: (%s:%s)", e.problem, mark.line + 1, 139 "Error position: (%s:%s)", e.problem, mark.line + 1,
139 mark.column + 1) 140 mark.column + 1)
140 141
141 if not target_releases: 142 if not target_deletes:
142 self.logger.info("There's no release to delete.") 143 self.logger.info("There's no release to delete.")
143 return 144 return
144 145
145 if not self.ctx.obj.get('api', False): 146 if not self.ctx.obj.get('api', False):
146 for r in target_releases: 147 for chart, release in target_deletes:
147 self.logger.info("Deleting release %s", r) 148 chart_delete = ChartDelete(
148 tiller.uninstall_release(r, purge=self.purge) 149 chart, release, tiller, purge=self.purge)
150 chart_delete.delete()
149 151
150 else: 152 else:
151 raise NotImplementedError() 153 raise NotImplementedError()
diff --git a/armada/const.py b/armada/const.py
index e253881..03dd16b 100644
--- a/armada/const.py
+++ b/armada/const.py
@@ -27,6 +27,7 @@ DEFAULT_CHART_TIMEOUT = 900
27 27
28# Tiller 28# Tiller
29DEFAULT_TILLER_TIMEOUT = 300 29DEFAULT_TILLER_TIMEOUT = 300
30DEFAULT_DELETE_TIMEOUT = DEFAULT_TILLER_TIMEOUT
30STATUS_UNKNOWN = 'UNKNOWN' 31STATUS_UNKNOWN = 'UNKNOWN'
31STATUS_DEPLOYED = 'DEPLOYED' 32STATUS_DEPLOYED = 'DEPLOYED'
32STATUS_DELETED = 'DELETED' 33STATUS_DELETED = 'DELETED'
diff --git a/armada/handlers/chart_delete.py b/armada/handlers/chart_delete.py
new file mode 100644
index 0000000..efb8abc
--- /dev/null
+++ b/armada/handlers/chart_delete.py
@@ -0,0 +1,52 @@
1# Copyright 2019 The Armada Authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from armada import const
16
17
18class ChartDelete(object):
19
20 def __init__(self, chart, release_name, tiller, purge=True):
21 """Initialize a chart delete handler.
22
23 :param chart: The armada chart document
24 :param release_name: Name of a Helm release
25 :param tiller: Tiller object
26 :param purge: Whether to purge the release
27
28 :type chart: object
29 :type release_name: str
30 :type tiller: Tiller object
31 :type purge: bool
32 """
33
34 self.chart = chart
35 self.release_name = release_name
36 self.tiller = tiller
37 self.purge = purge
38 self.delete_config = self.chart.get('delete', {})
39 # TODO(seaneagan): Consider allowing this to be a percentage of the
40 # chart's `wait.timeout` so that the timeouts can scale together, and
41 # likely default to some reasonable value, e.g. "50%".
42 self.timeout = self.delete_config.get('timeout',
43 const.DEFAULT_DELETE_TIMEOUT)
44
45 def get_timeout(self):
46 return self.timeout
47
48 def delete(self):
49 """Delete the release associated with the chart"
50 """
51 self.tiller.uninstall_release(
52 self.release_name, timeout=self.get_timeout(), purge=self.purge)
diff --git a/armada/handlers/chart_deploy.py b/armada/handlers/chart_deploy.py
index b160f16..ba31b60 100644
--- a/armada/handlers/chart_deploy.py
+++ b/armada/handlers/chart_deploy.py
@@ -20,6 +20,7 @@ from armada import const
20from armada.exceptions import armada_exceptions 20from armada.exceptions import armada_exceptions
21from armada.handlers.chartbuilder import ChartBuilder 21from armada.handlers.chartbuilder import ChartBuilder
22from armada.handlers.release_diff import ReleaseDiff 22from armada.handlers.release_diff import ReleaseDiff
23from armada.handlers.chart_delete import ChartDelete
23from armada.handlers.test import Test 24from armada.handlers.test import Test
24from armada.handlers.wait import ChartWait 25from armada.handlers.wait import ChartWait
25from armada.exceptions import tiller_exceptions 26from armada.exceptions import tiller_exceptions
@@ -204,7 +205,9 @@ class ChartDeploy(object):
204 # Purge the release 205 # Purge the release
205 LOG.info('Purging release %s with status %s', release_name, 206 LOG.info('Purging release %s with status %s', release_name,
206 status) 207 status)
207 self.tiller.uninstall_release(release_name) 208 chart_delete = ChartDelete(chart, release_name,
209 self.tiller)
210 chart_delete.delete()
208 result['purge'] = release_name 211 result['purge'] = release_name
209 212
210 timer = int(round(deadline - time.time())) 213 timer = int(round(deadline - time.time()))
diff --git a/armada/handlers/tiller.py b/armada/handlers/tiller.py
index 29c2b6c..dc0a9bf 100644
--- a/armada/handlers/tiller.py
+++ b/armada/handlers/tiller.py
@@ -580,14 +580,22 @@ class Tiller(object):
580 LOG.exception('Failed to get Tiller version.') 580 LOG.exception('Failed to get Tiller version.')
581 raise ex.TillerVersionException() 581 raise ex.TillerVersionException()
582 582
583 def uninstall_release(self, release, disable_hooks=False, purge=True): 583 def uninstall_release(self,
584 release,
585 disable_hooks=False,
586 purge=True,
587 timeout=None):
584 ''' 588 '''
585 :param: release - Helm chart release name 589 :param: release - Helm chart release name
586 :param: purge - deep delete of chart 590 :param: purge - deep delete of chart
591 :param: timeout - timeout for the tiller call
587 592
588 Deletes a Helm chart from Tiller 593 Deletes a Helm chart from Tiller
589 ''' 594 '''
590 595
596 if timeout is None:
597 timeout = const.DEFAULT_DELETE_TIMEOUT
598
591 # Helm client calls ReleaseContent in Delete dry-run scenario 599 # Helm client calls ReleaseContent in Delete dry-run scenario
592 if self.dry_run: 600 if self.dry_run:
593 content = self.get_release_content(release) 601 content = self.get_release_content(release)
@@ -601,16 +609,17 @@ class Tiller(object):
601 try: 609 try:
602 stub = ReleaseServiceStub(self.channel) 610 stub = ReleaseServiceStub(self.channel)
603 LOG.info( 611 LOG.info(
604 "Uninstall %s release with disable_hooks=%s, " 612 "Delete %s release with disable_hooks=%s, "
605 "purge=%s flags", release, disable_hooks, purge) 613 "purge=%s, timeout=%s flags", release, disable_hooks, purge,
614 timeout)
606 release_request = UninstallReleaseRequest( 615 release_request = UninstallReleaseRequest(
607 name=release, disable_hooks=disable_hooks, purge=purge) 616 name=release, disable_hooks=disable_hooks, purge=purge)
608 617
609 return stub.UninstallRelease( 618 return stub.UninstallRelease(
610 release_request, self.timeout, metadata=self.metadata) 619 release_request, timeout, metadata=self.metadata)
611 620
612 except Exception: 621 except Exception:
613 LOG.exception('Error while uninstalling release %s', release) 622 LOG.exception('Error while deleting release %s', release)
614 status = self.get_release_status(release) 623 status = self.get_release_status(release)
615 raise ex.ReleaseException(release, status, 'Delete') 624 raise ex.ReleaseException(release, status, 'Delete')
616 625
diff --git a/armada/schemas/armada-chart-schema.yaml b/armada/schemas/armada-chart-schema.yaml
index cde8921..98018f4 100644
--- a/armada/schemas/armada-chart-schema.yaml
+++ b/armada/schemas/armada-chart-schema.yaml
@@ -126,6 +126,11 @@ data:
126 - location 126 - location
127 - subpath 127 - subpath
128 - type 128 - type
129 delete:
130 type: object
131 properties:
132 timeout:
133 type: integer
129 install: 134 install:
130 # NOTE(sh8121att) Not clear that this key is actually used 135 # NOTE(sh8121att) Not clear that this key is actually used
131 # in the code. Will leave it here for backward compatabilities 136 # in the code. Will leave it here for backward compatabilities
diff --git a/armada/tests/unit/handlers/test_armada.py b/armada/tests/unit/handlers/test_armada.py
index 110e78c..2be3068 100644
--- a/armada/tests/unit/handlers/test_armada.py
+++ b/armada/tests/unit/handlers/test_armada.py
@@ -412,7 +412,10 @@ class ArmadaHandlerTestCase(base.ArmadaTestCase):
412 protected = chart.get('protected', {}) 412 protected = chart.get('protected', {})
413 if not protected: 413 if not protected:
414 expected_uninstall_release_calls.append( 414 expected_uninstall_release_calls.append(
415 mock.call(release_name)) 415 mock.call(
416 release_name,
417 purge=True,
418 timeout=const.DEFAULT_DELETE_TIMEOUT))
416 expected_install_release_calls.append( 419 expected_install_release_calls.append(
417 mock.call( 420 mock.call(
418 mock_chartbuilder().get_helm_chart(), 421 mock_chartbuilder().get_helm_chart(),
diff --git a/doc/source/operations/guide-build-armada-yaml.rst b/doc/source/operations/guide-build-armada-yaml.rst
index 5898a97..2743cb5 100644
--- a/doc/source/operations/guide-build-armada-yaml.rst
+++ b/doc/source/operations/guide-build-armada-yaml.rst
@@ -110,6 +110,8 @@ Chart
110+-----------------+----------+---------------------------------------------------------------------------------------+ 110+-----------------+----------+---------------------------------------------------------------------------------------+
111| upgrade | object | upgrade the chart managed by the armada yaml | 111| upgrade | object | upgrade the chart managed by the armada yaml |
112+-----------------+----------+---------------------------------------------------------------------------------------+ 112+-----------------+----------+---------------------------------------------------------------------------------------+
113| delete | object | See Delete_. |
114+-----------------+----------+---------------------------------------------------------------------------------------+
113| values | object | override any default values in the charts | 115| values | object | override any default values in the charts |
114+-----------------+----------+---------------------------------------------------------------------------------------+ 116+-----------------+----------+---------------------------------------------------------------------------------------+
115| source | object | provide a path to a ``git repo``, ``local dir``, or ``tarball url`` chart | 117| source | object | provide a path to a ``git repo``, ``local dir``, or ``tarball url`` chart |
@@ -301,6 +303,14 @@ Chart Example
301 reference: master 303 reference: master
302 dependencies: [] 304 dependencies: []
303 305
306Delete
307^^^^^^
308
309+-------------+----------+-----------------------------------------------------------------------------------+
310| keyword | type | action |
311+=============+==========+===================================================================================+
312| timeout | integer | time (in seconds) to wait for chart to be deleted |
313+-------------+----------+-----------------------------------------------------------------------------------+
304 314
305Source 315Source
306^^^^^^ 316^^^^^^