wordpress-charmers team mailing list archive
-
wordpress-charmers team
-
Mailing list archive
-
Message #00244
[Merge] ~mthaddon/charm-k8s-wordpress/+git/charm-k8s-wordpress:configure-pod into charm-k8s-wordpress:master
Tom Haddon has proposed merging ~mthaddon/charm-k8s-wordpress/+git/charm-k8s-wordpress:configure-pod into charm-k8s-wordpress:master.
Commit message:
Always set pod spec to avoid race condition if leadership changes between configure_pods calls
Requested reviews:
Wordpress Charmers (wordpress-charmers)
For more details, see:
https://code.launchpad.net/~mthaddon/charm-k8s-wordpress/+git/charm-k8s-wordpress/+merge/383499
Always set pod spec to avoid race condition if leadership changes between configure_pods calls
--
Your team Wordpress Charmers is requested to review the proposed merge of ~mthaddon/charm-k8s-wordpress/+git/charm-k8s-wordpress:configure-pod into charm-k8s-wordpress:master.
diff --git a/src/charm.py b/src/charm.py
index 48396f1..ffe2caf 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -93,10 +93,10 @@ class WordpressK8sCharm(CharmBase):
self.framework.observe(self.on.update_status, self.on_config_changed)
self.framework.observe(self.on.wordpress_initialise, self.on_wordpress_initialise)
- self.state.set_default(initialised=False)
- self.state.set_default(valid=False)
-
- self.state.set_default(_spec=None)
+ self.state.set_default(
+ initialised=False,
+ valid=False,
+ )
self.wordpress = Wordpress(self.model.config)
@@ -142,22 +142,18 @@ class WordpressK8sCharm(CharmBase):
def configure_pod(self):
spec = self.make_pod_spec()
- if spec != self.state._spec:
- self.state._spec = spec
- # only the leader can set_spec()
- if self.model.unit.is_leader():
- spec = self.make_pod_spec()
-
- logger.info("Configuring pod")
- self.model.unit.status = MaintenanceStatus("Configuring pod")
- self.model.pod.set_spec(spec)
-
- logger.info("Pod configured")
- self.model.unit.status = MaintenanceStatus("Pod configured")
- else:
- logger.info("Spec changes ignored by non-leader")
+ # only the leader can set_spec()
+ if self.model.unit.is_leader():
+ spec = self.make_pod_spec()
+
+ logger.info("Configuring pod")
+ self.model.unit.status = MaintenanceStatus("Configuring pod")
+ self.model.pod.set_spec(spec)
+
+ logger.info("Pod configured")
+ self.model.unit.status = MaintenanceStatus("Pod configured")
else:
- logger.info("Pod spec unchanged")
+ logger.info("Spec changes ignored by non-leader")
def make_pod_spec(self):
config = self.model.config
Follow ups