Merge ~pjdc/charm-k8s-mattermost/+git/charm-k8s-mattermost:various-cleanups into charm-k8s-mattermost:master

Proposed by Paul Collins
Status: Merged
Approved by: Paul Collins
Approved revision: de3f4d612b8668a820ddcc3be6d24c8b92da8248
Merged at revision: 904d31aeb68eccb664ee48a3b9e51cfebcecfe0c
Proposed branch: ~pjdc/charm-k8s-mattermost/+git/charm-k8s-mattermost:various-cleanups
Merge into: charm-k8s-mattermost:master
Diff against target: 163 lines (+36/-32)
1 file modified
src/charm.py (+36/-32)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+392202@code.launchpad.net

Commit message

simplify _missing_charm_settings, don't sort twice, and rework some docstrings

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Stuart Bishop (stub) wrote :

This all looks good. One docstring can be improved, per inline comments.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 904d31aeb68eccb664ee48a3b9e51cfebcecfe0c

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/charm.py b/src/charm.py
index 5be4cdc..f2fc8f4 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -60,8 +60,10 @@ class MattermostCharmEvents(CharmEvents):
6060
6161
62def check_ranges(ranges, name):62def check_ranges(ranges, name):
63 """If ranges, a string comprising a comma-separated list of CIDRs, has63 """If ranges has one or more invalid elements, return a string describing the problem.
64 one or more invalid elements, return a string describing the problem."""64
65 ranges is a string containing a comma-separated list of CIDRs, a CIDR being the only kind of valid element.
66 """
65 networks = ranges.split(',')67 networks = ranges.split(',')
66 invalid_networks = []68 invalid_networks = []
67 for network in networks:69 for network in networks:
@@ -74,8 +76,7 @@ def check_ranges(ranges, name):
7476
7577
76def get_container(pod_spec, container_name):78def get_container(pod_spec, container_name):
77 """Find and return the first container in pod_spec whose name is79 """Find and return the first container in pod_spec whose name is container_name, otherwise return None."""
78 container_name, otherwise return None."""
79 for container in pod_spec['containers']:80 for container in pod_spec['containers']:
80 if container['name'] == container_name:81 if container['name'] == container_name:
81 return container82 return container
@@ -83,9 +84,10 @@ def get_container(pod_spec, container_name):
8384
8485
85def get_env_config(pod_spec, container_name):86def get_env_config(pod_spec, container_name):
86 """Return the envConfig of the container in pod_spec whose name is87 """Return the envConfig of the container in pod_spec whose name is container_name, otherwise return None.
87 container_name, otherwise return None. If the container exists88
88 but has no envConfig, raise KeyError."""89 If the container exists but has no envConfig, raise KeyError.
90 """
89 container = get_container(pod_spec, container_name)91 container = get_container(pod_spec, container_name)
90 if 'envConfig' in container:92 if 'envConfig' in container:
91 return container['envConfig']93 return container['envConfig']
@@ -153,13 +155,12 @@ class MattermostK8sCharm(CharmBase):
153 # TODO(pjdc): Emit event when we add support for read replicas.155 # TODO(pjdc): Emit event when we add support for read replicas.
154156
155 def _check_for_config_problems(self):157 def _check_for_config_problems(self):
156 """Check for some simple configuration problems and return a158 """Check for simple configuration problems and return a string describing them, otherwise an empty string."""
157 string describing them, otherwise return an empty string."""
158 problems = []159 problems = []
159160
160 missing = self._missing_charm_settings()161 missing = self._missing_charm_settings()
161 if missing:162 if missing:
162 problems.append('required setting(s) empty: {}'.format(', '.join(sorted(missing))))163 problems.append('required setting(s) empty: {}'.format(', '.join(missing)))
163164
164 ranges = self.model.config['ingress_whitelist_source_range']165 ranges = self.model.config['ingress_whitelist_source_range']
165 if ranges:166 if ranges:
@@ -228,32 +229,30 @@ class MattermostK8sCharm(CharmBase):
228 return pod_config229 return pod_config
229230
230 def _missing_charm_settings(self):231 def _missing_charm_settings(self):
231 """Check configuration setting dependencies and return a list of232 """Return a list of settings required to satisfy configuration dependencies, or else an empty list."""
232 missing settings; otherwise return an empty list."""
233 config = self.model.config233 config = self.model.config
234 missing = []
235234
236 missing.extend([setting for setting in REQUIRED_SETTINGS if not config[setting]])235 missing = {setting for setting in REQUIRED_SETTINGS if not config[setting]}
237236
238 if config['clustering'] and not config['licence']:237 if config['clustering'] and not config['licence']:
239 missing.append('licence')238 missing.add('licence')
240239
241 if config['mattermost_image_username'] and not config['mattermost_image_password']:240 if config['mattermost_image_username'] and not config['mattermost_image_password']:
242 missing.append('mattermost_image_password')241 missing.add('mattermost_image_password')
243242
244 if config['performance_monitoring_enabled'] and not config['licence']:243 if config['performance_monitoring_enabled'] and not config['licence']:
245 missing.append('licence')244 missing.add('licence')
246245
247 if config['s3_enabled']:246 if config['s3_enabled']:
248 missing.extend([setting for setting in REQUIRED_S3_SETTINGS if not config[setting]])247 missing.update({setting for setting in REQUIRED_S3_SETTINGS if not config[setting]})
249248
250 if config['s3_server_side_encryption'] and not config['licence']:249 if config['s3_server_side_encryption'] and not config['licence']:
251 missing.append('licence')250 missing.add('licence')
252251
253 if config['sso']:252 if config['sso']:
254 missing.extend([setting for setting in REQUIRED_SSO_SETTINGS if not config[setting]])253 missing.update({setting for setting in REQUIRED_SSO_SETTINGS if not config[setting]})
255254
256 return sorted(list(set(missing)))255 return sorted(missing)
257256
258 def _make_s3_pod_config(self):257 def _make_s3_pod_config(self):
259 """Return an envConfig of S3 settings, if any."""258 """Return an envConfig of S3 settings, if any."""
@@ -323,9 +322,11 @@ class MattermostK8sCharm(CharmBase):
323322
324 def _get_licence_secret_name(self):323 def _get_licence_secret_name(self):
325 """Compute a content-dependent name for the licence secret.324 """Compute a content-dependent name for the licence secret.
325
326 The name is varied so that licence updates cause the pods to326 The name is varied so that licence updates cause the pods to
327 be respawned. Mattermost reads the licence file on startup327 be respawned. Mattermost reads the licence file on startup
328 and updates the copy in the database, if necessary."""328 and updates the copy in the database, if necessary.
329 """
329 crc = '{:08x}'.format(crc32(self.model.config['licence'].encode('utf-8')))330 crc = '{:08x}'.format(crc32(self.model.config['licence'].encode('utf-8')))
330 return '{}-licence-{}'.format(self.app.name, crc)331 return '{}-licence-{}'.format(self.app.name, crc)
331332
@@ -380,8 +381,10 @@ class MattermostK8sCharm(CharmBase):
380 )381 )
381382
382 def _update_pod_spec_for_canonical_defaults(self, pod_spec):383 def _update_pod_spec_for_canonical_defaults(self, pod_spec):
383 """Update pod_spec with various Mattermost settings particular to384 """Update pod_spec with various Mattermost settings particular to Canonical's deployment.
384 Canonical's deployment that may also less generally useful."""385
386 These settings may be less generally useful, and so they are controlled here as a unit.
387 """
385 config = self.model.config388 config = self.model.config
386 if not config['use_canonical_defaults']:389 if not config['use_canonical_defaults']:
387 return390 return
@@ -404,9 +407,10 @@ class MattermostK8sCharm(CharmBase):
404 )407 )
405408
406 def _update_pod_spec_for_clustering(self, pod_spec):409 def _update_pod_spec_for_clustering(self, pod_spec):
407 """Update pod_spec with clustering settings. Vary the cluster410 """Update pod_spec with clustering settings, varying the cluster name on the application name.
408 name on the application name so that blue/green deployments in411
409 the same model won't talk to each other."""412 This is done so that blue/green deployments in the same model won't talk to each other.
413 """
410 config = self.model.config414 config = self.model.config
411 if not config['clustering']:415 if not config['clustering']:
412 return416 return
@@ -420,9 +424,10 @@ class MattermostK8sCharm(CharmBase):
420 )424 )
421425
422 def _update_pod_spec_for_sso(self, pod_spec):426 def _update_pod_spec_for_sso(self, pod_spec):
423 """Update pod_spec with settings to use login.ubuntu.com via427 """Update pod_spec with settings to use login.ubuntu.com via SAML for single sign-on.
424 SAML for single sign-on. SAML_IDP_CRT must be generated and428
425 installed manually by a human (see README.md)."""429 SAML_IDP_CRT must be generated and installed manually by a human (see README.md).
430 """
426 config = self.model.config431 config = self.model.config
427 if not config['sso'] or [setting for setting in REQUIRED_SSO_SETTINGS if not config[setting]]:432 if not config['sso'] or [setting for setting in REQUIRED_SSO_SETTINGS if not config[setting]]:
428 return433 return
@@ -481,8 +486,7 @@ class MattermostK8sCharm(CharmBase):
481 # [ store annotations in pod_spec ]486 # [ store annotations in pod_spec ]
482487
483 def _update_pod_spec_for_push(self, pod_spec):488 def _update_pod_spec_for_push(self, pod_spec):
484 """Update pod_spec with settings for push notifications via489 """Update pod_spec with settings for Mattermost HPNS (hosted push notification service)."""
485 Mattermost HPNS (hosted push notification service)."""
486 config = self.model.config490 config = self.model.config
487 if not config['push_notification_server']:491 if not config['push_notification_server']:
488 return492 return

Subscribers

People subscribed via source and target branches