Browse Source

Merge "Refactor tiller commands to handle methods"

changes/83/632483/27
Zuul 2 months ago
parent
commit
24867f34db

+ 16
- 18
armada/api/controller/armada.py View File

@@ -69,29 +69,13 @@ class Apply(api.BaseResource):
69 69
                 "or application/json")
70 70
         try:
71 71
             with self.get_tiller(req, resp) as tiller:
72
-
73
-                armada = Armada(
74
-                    documents,
75
-                    disable_update_pre=req.get_param_as_bool(
76
-                        'disable_update_pre'),
77
-                    disable_update_post=req.get_param_as_bool(
78
-                        'disable_update_post'),
79
-                    enable_chart_cleanup=req.get_param_as_bool(
80
-                        'enable_chart_cleanup'),
81
-                    dry_run=req.get_param_as_bool('dry_run'),
82
-                    force_wait=req.get_param_as_bool('wait'),
83
-                    timeout=req.get_param_as_int('timeout'),
84
-                    tiller=tiller,
85
-                    target_manifest=req.get_param('target_manifest'))
86
-
87
-                msg = armada.sync()
88
-
72
+                msg = self.handle(req, documents, tiller)
89 73
                 resp.body = json.dumps({
90 74
                     'message': msg,
91 75
                 })
92
-
93 76
                 resp.content_type = 'application/json'
94 77
                 resp.status = falcon.HTTP_200
78
+
95 79
         except exceptions.ManifestException as e:
96 80
             self.return_error(resp, falcon.HTTP_400, message=str(e))
97 81
         except Exception as e:
@@ -99,3 +83,17 @@ class Apply(api.BaseResource):
99 83
             err_message = 'Failed to apply manifest: {}'.format(e)
100 84
             self.error(req.context, err_message)
101 85
             self.return_error(resp, falcon.HTTP_500, message=err_message)
86
+
87
+    def handle(self, req, documents, tiller):
88
+        armada = Armada(
89
+            documents,
90
+            disable_update_pre=req.get_param_as_bool('disable_update_pre'),
91
+            disable_update_post=req.get_param_as_bool('disable_update_post'),
92
+            enable_chart_cleanup=req.get_param_as_bool('enable_chart_cleanup'),
93
+            dry_run=req.get_param_as_bool('dry_run'),
94
+            force_wait=req.get_param_as_bool('wait'),
95
+            timeout=req.get_param_as_int('timeout'),
96
+            tiller=tiller,
97
+            target_manifest=req.get_param('target_manifest'))
98
+
99
+        return armada.sync()

+ 17
- 16
armada/api/controller/rollback.py View File

@@ -30,27 +30,28 @@ class Rollback(api.BaseResource):
30 30
     @policy.enforce('armada:rollback_release')
31 31
     def on_post(self, req, resp, release):
32 32
         try:
33
-            dry_run = req.get_param_as_bool('dry_run')
34
-
35 33
             with self.get_tiller(req, resp) as tiller:
36
-
37
-                tiller.rollback_release(
38
-                    release,
39
-                    req.get_param_as_int('version') or 0,
40
-                    wait=req.get_param_as_bool('wait'),
41
-                    timeout=req.get_param_as_int('timeout') or 0,
42
-                    force=req.get_param_as_bool('force'),
43
-                    recreate_pods=req.get_param_as_bool('recreate_pods'))
44
-
34
+                msg = self.handle(req, release, tiller)
45 35
                 resp.body = json.dumps({
46
-                    'message': ('(dry run) ' if dry_run else '') +
47
-                    'Rollback of {} complete.'.format(release),
36
+                    'message': msg,
48 37
                 })
49
-
50
-            resp.content_type = 'application/json'
51
-            resp.status = falcon.HTTP_200
38
+                resp.content_type = 'application/json'
39
+                resp.status = falcon.HTTP_200
52 40
         except Exception as e:
53 41
             self.logger.exception('Caught unexpected exception')
54 42
             err_message = 'Failed to rollback release: {}'.format(e)
55 43
             self.error(req.context, err_message)
56 44
             self.return_error(resp, falcon.HTTP_500, message=err_message)
45
+
46
+    def handle(self, req, release, tiller):
47
+        dry_run = req.get_param_as_bool('dry_run')
48
+        tiller.rollback_release(
49
+            release,
50
+            req.get_param_as_int('version') or 0,
51
+            wait=req.get_param_as_bool('wait'),
52
+            timeout=req.get_param_as_int('timeout') or 0,
53
+            force=req.get_param_as_bool('force'),
54
+            recreate_pods=req.get_param_as_bool('recreate_pods'))
55
+
56
+        return ('(dry run) ' if dry_run else '') + \
57
+            'Rollback of {} complete.'.format(release)

+ 6
- 4
armada/api/controller/test.py View File

@@ -37,10 +37,7 @@ class TestReleasesReleaseNameController(api.BaseResource):
37 37
     @policy.enforce('armada:test_release')
38 38
     def on_get(self, req, resp, release):
39 39
         with self.get_tiller(req, resp) as tiller:
40
-            cleanup = req.get_param_as_bool('cleanup')
41
-
42
-            test_handler = Test({}, release, tiller, cleanup=cleanup)
43
-            success = test_handler.test_release_for_success()
40
+            success = self.handle(req, release, tiller)
44 41
 
45 42
         if success:
46 43
             msg = {
@@ -57,6 +54,11 @@ class TestReleasesReleaseNameController(api.BaseResource):
57 54
         resp.status = falcon.HTTP_200
58 55
         resp.content_type = 'application/json'
59 56
 
57
+    def handle(self, req, release, tiller):
58
+        cleanup = req.get_param_as_bool('cleanup')
59
+        test_handler = Test({}, release, tiller, cleanup=cleanup)
60
+        return test_handler.test_release_for_success()
61
+
60 62
 
61 63
 class TestReleasesManifestController(api.BaseResource):
62 64
     '''

+ 29
- 25
armada/api/controller/tiller.py View File

@@ -34,19 +34,7 @@ class Status(api.BaseResource):
34 34
         '''
35 35
         try:
36 36
             with self.get_tiller(req, resp) as tiller:
37
-
38
-                LOG.debug(
39
-                    'Tiller (Status) at: %s:%s, namespace=%s, '
40
-                    'timeout=%s', tiller.tiller_host, tiller.tiller_port,
41
-                    tiller.tiller_namespace, tiller.timeout)
42
-
43
-                message = {
44
-                    'tiller': {
45
-                        'state': tiller.tiller_status(),
46
-                        'version': tiller.tiller_version()
47
-                    }
48
-                }
49
-
37
+                message = self.handle(tiller)
50 38
                 resp.status = falcon.HTTP_200
51 39
                 resp.body = json.dumps(message)
52 40
                 resp.content_type = 'application/json'
@@ -56,6 +44,19 @@ class Status(api.BaseResource):
56 44
             self.error(req.context, err_message)
57 45
             self.return_error(resp, falcon.HTTP_500, message=err_message)
58 46
 
47
+    def handle(self, tiller):
48
+        LOG.debug('Tiller (Status) at: %s:%s, namespace=%s, '
49
+                  'timeout=%s', tiller.tiller_host, tiller.tiller_port,
50
+                  tiller.tiller_namespace, tiller.timeout)
51
+
52
+        message = {
53
+            'tiller': {
54
+                'state': tiller.tiller_status(),
55
+                'version': tiller.tiller_version()
56
+            }
57
+        }
58
+        return message
59
+
59 60
 
60 61
 class Release(api.BaseResource):
61 62
 
@@ -65,18 +66,10 @@ class Release(api.BaseResource):
65 66
         '''
66 67
         try:
67 68
             with self.get_tiller(req, resp) as tiller:
68
-
69
-                LOG.debug(
70
-                    'Tiller (Release) at: %s:%s, namespace=%s, '
71
-                    'timeout=%s', tiller.tiller_host, tiller.tiller_port,
72
-                    tiller.tiller_namespace, tiller.timeout)
73
-
74
-                releases = {}
75
-                for release in tiller.list_releases():
76
-                    releases.setdefault(release.namespace, [])
77
-                    releases[release.namespace].append(release.name)
78
-
79
-                resp.body = json.dumps({'releases': releases})
69
+                releases = self.handle(tiller)
70
+                resp.body = json.dumps({
71
+                    'releases': releases,
72
+                })
80 73
                 resp.content_type = 'application/json'
81 74
                 resp.status = falcon.HTTP_200
82 75
 
@@ -84,3 +77,14 @@ class Release(api.BaseResource):
84 77
             err_message = 'Unable to find Tiller Releases: {}'.format(e)
85 78
             self.error(req.context, err_message)
86 79
             self.return_error(resp, falcon.HTTP_500, message=err_message)
80
+
81
+    def handle(self, tiller):
82
+        LOG.debug('Tiller (Release) at: %s:%s, namespace=%s, '
83
+                  'timeout=%s', tiller.tiller_host, tiller.tiller_port,
84
+                  tiller.tiller_namespace, tiller.timeout)
85
+
86
+        releases = {}
87
+        for release in tiller.list_releases():
88
+            releases.setdefault(release.namespace, [])
89
+            releases[release.namespace].append(release.name)
90
+        return releases

+ 17
- 14
armada/cli/apply.py View File

@@ -207,20 +207,8 @@ class ApplyManifest(CliAction):
207 207
                     tiller_namespace=self.tiller_namespace,
208 208
                     bearer_token=self.bearer_token,
209 209
                     dry_run=self.dry_run) as tiller:
210
-                armada = Armada(
211
-                    documents,
212
-                    disable_update_pre=self.disable_update_pre,
213
-                    disable_update_post=self.disable_update_post,
214
-                    enable_chart_cleanup=self.enable_chart_cleanup,
215
-                    dry_run=self.dry_run,
216
-                    set_ovr=self.set,
217
-                    force_wait=self.wait,
218
-                    timeout=self.timeout,
219
-                    tiller=tiller,
220
-                    values=self.values,
221
-                    target_manifest=self.target_manifest)
222
-
223
-                resp = armada.sync()
210
+
211
+                resp = self.handle(documents, tiller)
224 212
                 self.output(resp)
225 213
         else:
226 214
             if len(self.values) > 0:
@@ -248,3 +236,18 @@ class ApplyManifest(CliAction):
248 236
                 resp = client.post_apply(
249 237
                     manifest=documents, set=self.set, query=query)
250 238
             self.output(resp.get('message'))
239
+
240
+    def handle(self, documents, tiller):
241
+        armada = Armada(
242
+            documents,
243
+            disable_update_pre=self.disable_update_pre,
244
+            disable_update_post=self.disable_update_post,
245
+            enable_chart_cleanup=self.enable_chart_cleanup,
246
+            dry_run=self.dry_run,
247
+            set_ovr=self.set,
248
+            force_wait=self.wait,
249
+            timeout=self.timeout,
250
+            tiller=tiller,
251
+            values=self.values,
252
+            target_manifest=self.target_manifest)
253
+        return armada.sync()

+ 10
- 7
armada/cli/rollback.py View File

@@ -119,16 +119,19 @@ class Rollback(CliAction):
119 119
                 bearer_token=self.bearer_token,
120 120
                 dry_run=self.dry_run) as tiller:
121 121
 
122
-            response = tiller.rollback_release(
123
-                self.release,
124
-                self.version,
125
-                wait=self.wait,
126
-                timeout=self.timeout,
127
-                force=self.force,
128
-                recreate_pods=self.recreate_pods)
122
+            response = self.handle(tiller)
129 123
 
130 124
             self.output(response)
131 125
 
126
+    def handle(self, tiller):
127
+        return tiller.rollback_release(
128
+            self.release,
129
+            self.version,
130
+            wait=self.wait,
131
+            timeout=self.timeout,
132
+            force=self.force,
133
+            recreate_pods=self.recreate_pods)
134
+
132 135
     def output(self, response):
133 136
         self.logger.info(('(dry run) ' if self.dry_run else '') +
134 137
                          'Rollback of %s complete.', self.release)

Loading…
Cancel
Save