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
1diff --git a/src/charm.py b/src/charm.py
2index 5be4cdc..f2fc8f4 100755
3--- a/src/charm.py
4+++ b/src/charm.py
5@@ -60,8 +60,10 @@ class MattermostCharmEvents(CharmEvents):
6
7
8 def check_ranges(ranges, name):
9- """If ranges, a string comprising a comma-separated list of CIDRs, has
10- one or more invalid elements, return a string describing the problem."""
11+ """If ranges has one or more invalid elements, return a string describing the problem.
12+
13+ ranges is a string containing a comma-separated list of CIDRs, a CIDR being the only kind of valid element.
14+ """
15 networks = ranges.split(',')
16 invalid_networks = []
17 for network in networks:
18@@ -74,8 +76,7 @@ def check_ranges(ranges, name):
19
20
21 def get_container(pod_spec, container_name):
22- """Find and return the first container in pod_spec whose name is
23- container_name, otherwise return None."""
24+ """Find and return the first container in pod_spec whose name is container_name, otherwise return None."""
25 for container in pod_spec['containers']:
26 if container['name'] == container_name:
27 return container
28@@ -83,9 +84,10 @@ def get_container(pod_spec, container_name):
29
30
31 def get_env_config(pod_spec, container_name):
32- """Return the envConfig of the container in pod_spec whose name is
33- container_name, otherwise return None. If the container exists
34- but has no envConfig, raise KeyError."""
35+ """Return the envConfig of the container in pod_spec whose name is container_name, otherwise return None.
36+
37+ If the container exists but has no envConfig, raise KeyError.
38+ """
39 container = get_container(pod_spec, container_name)
40 if 'envConfig' in container:
41 return container['envConfig']
42@@ -153,13 +155,12 @@ class MattermostK8sCharm(CharmBase):
43 # TODO(pjdc): Emit event when we add support for read replicas.
44
45 def _check_for_config_problems(self):
46- """Check for some simple configuration problems and return a
47- string describing them, otherwise return an empty string."""
48+ """Check for simple configuration problems and return a string describing them, otherwise an empty string."""
49 problems = []
50
51 missing = self._missing_charm_settings()
52 if missing:
53- problems.append('required setting(s) empty: {}'.format(', '.join(sorted(missing))))
54+ problems.append('required setting(s) empty: {}'.format(', '.join(missing)))
55
56 ranges = self.model.config['ingress_whitelist_source_range']
57 if ranges:
58@@ -228,32 +229,30 @@ class MattermostK8sCharm(CharmBase):
59 return pod_config
60
61 def _missing_charm_settings(self):
62- """Check configuration setting dependencies and return a list of
63- missing settings; otherwise return an empty list."""
64+ """Return a list of settings required to satisfy configuration dependencies, or else an empty list."""
65 config = self.model.config
66- missing = []
67
68- missing.extend([setting for setting in REQUIRED_SETTINGS if not config[setting]])
69+ missing = {setting for setting in REQUIRED_SETTINGS if not config[setting]}
70
71 if config['clustering'] and not config['licence']:
72- missing.append('licence')
73+ missing.add('licence')
74
75 if config['mattermost_image_username'] and not config['mattermost_image_password']:
76- missing.append('mattermost_image_password')
77+ missing.add('mattermost_image_password')
78
79 if config['performance_monitoring_enabled'] and not config['licence']:
80- missing.append('licence')
81+ missing.add('licence')
82
83 if config['s3_enabled']:
84- missing.extend([setting for setting in REQUIRED_S3_SETTINGS if not config[setting]])
85+ missing.update({setting for setting in REQUIRED_S3_SETTINGS if not config[setting]})
86
87 if config['s3_server_side_encryption'] and not config['licence']:
88- missing.append('licence')
89+ missing.add('licence')
90
91 if config['sso']:
92- missing.extend([setting for setting in REQUIRED_SSO_SETTINGS if not config[setting]])
93+ missing.update({setting for setting in REQUIRED_SSO_SETTINGS if not config[setting]})
94
95- return sorted(list(set(missing)))
96+ return sorted(missing)
97
98 def _make_s3_pod_config(self):
99 """Return an envConfig of S3 settings, if any."""
100@@ -323,9 +322,11 @@ class MattermostK8sCharm(CharmBase):
101
102 def _get_licence_secret_name(self):
103 """Compute a content-dependent name for the licence secret.
104+
105 The name is varied so that licence updates cause the pods to
106 be respawned. Mattermost reads the licence file on startup
107- and updates the copy in the database, if necessary."""
108+ and updates the copy in the database, if necessary.
109+ """
110 crc = '{:08x}'.format(crc32(self.model.config['licence'].encode('utf-8')))
111 return '{}-licence-{}'.format(self.app.name, crc)
112
113@@ -380,8 +381,10 @@ class MattermostK8sCharm(CharmBase):
114 )
115
116 def _update_pod_spec_for_canonical_defaults(self, pod_spec):
117- """Update pod_spec with various Mattermost settings particular to
118- Canonical's deployment that may also less generally useful."""
119+ """Update pod_spec with various Mattermost settings particular to Canonical's deployment.
120+
121+ These settings may be less generally useful, and so they are controlled here as a unit.
122+ """
123 config = self.model.config
124 if not config['use_canonical_defaults']:
125 return
126@@ -404,9 +407,10 @@ class MattermostK8sCharm(CharmBase):
127 )
128
129 def _update_pod_spec_for_clustering(self, pod_spec):
130- """Update pod_spec with clustering settings. Vary the cluster
131- name on the application name so that blue/green deployments in
132- the same model won't talk to each other."""
133+ """Update pod_spec with clustering settings, varying the cluster name on the application name.
134+
135+ This is done so that blue/green deployments in the same model won't talk to each other.
136+ """
137 config = self.model.config
138 if not config['clustering']:
139 return
140@@ -420,9 +424,10 @@ class MattermostK8sCharm(CharmBase):
141 )
142
143 def _update_pod_spec_for_sso(self, pod_spec):
144- """Update pod_spec with settings to use login.ubuntu.com via
145- SAML for single sign-on. SAML_IDP_CRT must be generated and
146- installed manually by a human (see README.md)."""
147+ """Update pod_spec with settings to use login.ubuntu.com via SAML for single sign-on.
148+
149+ SAML_IDP_CRT must be generated and installed manually by a human (see README.md).
150+ """
151 config = self.model.config
152 if not config['sso'] or [setting for setting in REQUIRED_SSO_SETTINGS if not config[setting]]:
153 return
154@@ -481,8 +486,7 @@ class MattermostK8sCharm(CharmBase):
155 # [ store annotations in pod_spec ]
156
157 def _update_pod_spec_for_push(self, pod_spec):
158- """Update pod_spec with settings for push notifications via
159- Mattermost HPNS (hosted push notification service)."""
160+ """Update pod_spec with settings for Mattermost HPNS (hosted push notification service)."""
161 config = self.model.config
162 if not config['push_notification_server']:
163 return

Subscribers

People subscribed via source and target branches