Browse Source

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
Sean Eagan 3 months ago
parent
commit
47ebd27cad

+ 11
- 9
armada/cli/delete.py View File

@@ -19,6 +19,7 @@ from oslo_config import cfg
19 19
 
20 20
 from armada.cli import CliAction
21 21
 from armada import const
22
+from armada.handlers.chart_delete import ChartDelete
22 23
 from armada.handlers.manifest import Manifest
23 24
 from armada.handlers.tiller import Tiller
24 25
 from armada.utils.release import release_prefixer
@@ -108,13 +109,13 @@ class DeleteChartManifest(CliAction):
108 109
             if not self.ctx.obj.get('api', False):
109 110
                 for r in target_releases:
110 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 114
             else:
114 115
                 raise NotImplementedError()
115 116
 
116 117
         if self.manifest:
117
-            target_releases = []
118
+            target_deletes = []
118 119
 
119 120
             with open(self.manifest) as f:
120 121
                 documents = list(yaml.safe_load_all(f.read()))
@@ -126,11 +127,11 @@ class DeleteChartManifest(CliAction):
126 127
                 for group in armada_obj.get(const.KEYWORD_ARMADA).get(
127 128
                         const.KEYWORD_GROUPS):
128 129
                     for ch in group.get(const.KEYWORD_CHARTS):
130
+                        chart = ch.get('chart')
129 131
                         release_name = release_prefixer(
130
-                            prefix,
131
-                            ch.get('chart').get('release'))
132
+                            prefix, chart.get('release'))
132 133
                         if release_name in known_release_names:
133
-                            target_releases.append(release_name)
134
+                            target_deletes.append((chart, release_name))
134 135
             except yaml.YAMLError as e:
135 136
                 mark = e.problem_mark
136 137
                 self.logger.info(
@@ -138,14 +139,15 @@ class DeleteChartManifest(CliAction):
138 139
                     "Error position: (%s:%s)", e.problem, mark.line + 1,
139 140
                     mark.column + 1)
140 141
 
141
-            if not target_releases:
142
+            if not target_deletes:
142 143
                 self.logger.info("There's no release to delete.")
143 144
                 return
144 145
 
145 146
             if not self.ctx.obj.get('api', False):
146
-                for r in target_releases:
147
-                    self.logger.info("Deleting release %s", r)
148
-                    tiller.uninstall_release(r, purge=self.purge)
147
+                for chart, release in target_deletes:
148
+                    chart_delete = ChartDelete(
149
+                        chart, release, tiller, purge=self.purge)
150
+                    chart_delete.delete()
149 151
 
150 152
             else:
151 153
                 raise NotImplementedError()

+ 1
- 0
armada/const.py View File

@@ -27,6 +27,7 @@ DEFAULT_CHART_TIMEOUT = 900
27 27
 
28 28
 # Tiller
29 29
 DEFAULT_TILLER_TIMEOUT = 300
30
+DEFAULT_DELETE_TIMEOUT = DEFAULT_TILLER_TIMEOUT
30 31
 STATUS_UNKNOWN = 'UNKNOWN'
31 32
 STATUS_DEPLOYED = 'DEPLOYED'
32 33
 STATUS_DELETED = 'DELETED'

+ 52
- 0
armada/handlers/chart_delete.py View File

@@ -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
+
15
+from armada import const
16
+
17
+
18
+class 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)

+ 4
- 1
armada/handlers/chart_deploy.py View File

@@ -20,6 +20,7 @@ from armada import const
20 20
 from armada.exceptions import armada_exceptions
21 21
 from armada.handlers.chartbuilder import ChartBuilder
22 22
 from armada.handlers.release_diff import ReleaseDiff
23
+from armada.handlers.chart_delete import ChartDelete
23 24
 from armada.handlers.test import Test
24 25
 from armada.handlers.wait import ChartWait
25 26
 from armada.exceptions import tiller_exceptions
@@ -204,7 +205,9 @@ class ChartDeploy(object):
204 205
                     # Purge the release
205 206
                     LOG.info('Purging release %s with status %s', release_name,
206 207
                              status)
207
-                    self.tiller.uninstall_release(release_name)
208
+                    chart_delete = ChartDelete(chart, release_name,
209
+                                               self.tiller)
210
+                    chart_delete.delete()
208 211
                     result['purge'] = release_name
209 212
 
210 213
             timer = int(round(deadline - time.time()))

+ 14
- 5
armada/handlers/tiller.py View File

@@ -580,14 +580,22 @@ class Tiller(object):
580 580
             LOG.exception('Failed to get Tiller version.')
581 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 589
         :param: release - Helm chart release name
586 590
         :param: purge - deep delete of chart
591
+        :param: timeout - timeout for the tiller call
587 592
 
588 593
         Deletes a Helm chart from Tiller
589 594
         '''
590 595
 
596
+        if timeout is None:
597
+            timeout = const.DEFAULT_DELETE_TIMEOUT
598
+
591 599
         # Helm client calls ReleaseContent in Delete dry-run scenario
592 600
         if self.dry_run:
593 601
             content = self.get_release_content(release)
@@ -601,16 +609,17 @@ class Tiller(object):
601 609
         try:
602 610
             stub = ReleaseServiceStub(self.channel)
603 611
             LOG.info(
604
-                "Uninstall %s release with disable_hooks=%s, "
605
-                "purge=%s flags", release, disable_hooks, purge)
612
+                "Delete %s release with disable_hooks=%s, "
613
+                "purge=%s, timeout=%s flags", release, disable_hooks, purge,
614
+                timeout)
606 615
             release_request = UninstallReleaseRequest(
607 616
                 name=release, disable_hooks=disable_hooks, purge=purge)
608 617
 
609 618
             return stub.UninstallRelease(
610
-                release_request, self.timeout, metadata=self.metadata)
619
+                release_request, timeout, metadata=self.metadata)
611 620
 
612 621
         except Exception:
613
-            LOG.exception('Error while uninstalling release %s', release)
622
+            LOG.exception('Error while deleting release %s', release)
614 623
             status = self.get_release_status(release)
615 624
             raise ex.ReleaseException(release, status, 'Delete')
616 625
 

+ 5
- 0
armada/schemas/armada-chart-schema.yaml View File

@@ -126,6 +126,11 @@ data:
126 126
         - location
127 127
         - subpath
128 128
         - type
129
+    delete:
130
+      type: object
131
+      properties:
132
+        timeout:
133
+          type: integer
129 134
     install:
130 135
       # NOTE(sh8121att) Not clear that this key is actually used
131 136
       # in the code. Will leave it here for backward compatabilities

+ 4
- 1
armada/tests/unit/handlers/test_armada.py View File

@@ -412,7 +412,10 @@ class ArmadaHandlerTestCase(base.ArmadaTestCase):
412 412
                             protected = chart.get('protected', {})
413 413
                             if not protected:
414 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 419
                                 expected_install_release_calls.append(
417 420
                                     mock.call(
418 421
                                         mock_chartbuilder().get_helm_chart(),

+ 10
- 0
doc/source/operations/guide-build-armada-yaml.rst View File

@@ -110,6 +110,8 @@ Chart
110 110
 +-----------------+----------+---------------------------------------------------------------------------------------+
111 111
 | upgrade         | object   | upgrade the chart managed by the armada yaml                                          |
112 112
 +-----------------+----------+---------------------------------------------------------------------------------------+
113
+| delete          | object   | See Delete_.                                                                          |
114
++-----------------+----------+---------------------------------------------------------------------------------------+
113 115
 | values          | object   | override any default values in the charts                                             |
114 116
 +-----------------+----------+---------------------------------------------------------------------------------------+
115 117
 | source          | object   | provide a path to a ``git repo``, ``local dir``, or ``tarball url`` chart             |
@@ -301,6 +303,14 @@ Chart Example
301 303
         reference: master
302 304
       dependencies: []
303 305
 
306
+Delete
307
+^^^^^^
308
+
309
++-------------+----------+-----------------------------------------------------------------------------------+
310
+| keyword     | type     | action                                                                            |
311
++=============+==========+===================================================================================+
312
+| timeout     | integer  | time (in seconds) to wait for chart to be deleted                                 |
313
++-------------+----------+-----------------------------------------------------------------------------------+
304 314
 
305 315
 Source
306 316
 ^^^^^^

Loading…
Cancel
Save