← Back to team overview

wordpress-charmers team mailing list archive

[Merge] ~barryprice/charm-k8s-wordpress/+git/charm-k8s-wordpress:master into charm-k8s-wordpress:master

 

Barry Price has proposed merging ~barryprice/charm-k8s-wordpress/+git/charm-k8s-wordpress:master into charm-k8s-wordpress:master.

Commit message:
Add an Ingress resource to our pod spec, hard-coded port for now

Requested reviews:
  Wordpress Charmers (wordpress-charmers)

For more details, see:
https://code.launchpad.net/~barryprice/charm-k8s-wordpress/+git/charm-k8s-wordpress/+merge/384331
-- 
Your team Wordpress Charmers is requested to review the proposed merge of ~barryprice/charm-k8s-wordpress/+git/charm-k8s-wordpress:master into charm-k8s-wordpress:master.
diff --git a/src/charm.py b/src/charm.py
index 69c317d..9f2cb24 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -43,7 +43,7 @@ def generate_pod_config(config, secured=True):
     if config.get("wp_plugin_akismet_key"):
         pod_config["WP_PLUGIN_AKISMET_KEY"] = config["wp_plugin_akismet_key"]
     if config.get("wp_plugin_openstack-objectstorage_config"):
-        # Actual plugin name is 'openstack-objectstorage', but we're only
+        # actual plugin name is 'openstack-objectstorage', but we're only
         # implementing the 'swift' portion of it.
         wp_plugin_swift_config = safe_load(config.get("wp_plugin_openstack-objectstorage_config"))
         pod_config["SWIFT_AUTH_URL"] = wp_plugin_swift_config.get('auth-url')
@@ -141,14 +141,15 @@ class WordpressK8sCharm(CharmBase):
             self.model.unit.status = ActiveStatus()
 
     def configure_pod(self):
-        # Only the leader can set_spec().
+        # Only the leader can set_spec()
         if self.model.unit.is_leader():
             spec = self.make_pod_spec()
+            resources = self.make_pod_resources()
 
             msg = "Configuring pod"
             logger.info(msg)
             self.model.unit.status = MaintenanceStatus(msg)
-            self.model.pod.set_spec(spec)
+            self.model.pod.set_spec(spec, resources)
 
             msg = "Pod configured"
             logger.info(msg)
@@ -167,15 +168,25 @@ class WordpressK8sCharm(CharmBase):
         ]
 
         spec = {
-            "containers": [
-                {
-                    "name": self.app.name,
-                    "imageDetails": {"imagePath": config["image"]},
-                    "ports": ports,
-                    "config": secure_pod_config,
-                    "readinessProbe": {"exec": {"command": ["/bin/cat", "/srv/wordpress-helpers/.ready"]}},
+            "containers": [{
+                "name": self.app.name,
+                "imageDetails": {
+                    "imagePath": config["image"]
+                },
+                "ports": ports,
+                "config": secure_pod_config,
+                "startupProbe": {
+                    "exec": {
+                        "command": ["/bin/cat", "/srv/wordpress-helpers/.ready"]
+                    }
+                },
+                "livenessProbe": {
+                    "httpGet": {
+                        "path": "/",
+                        "port": 80,
+                    }
                 }
-            ]
+            }]
         }
 
         out = io.StringIO()
@@ -190,6 +201,30 @@ class WordpressK8sCharm(CharmBase):
 
         return spec
 
+    def make_pod_resources(self):
+        resources = {
+            "kubernetesResources": {
+                "ingressResources": [{
+                    "name": "{}-ingress".format(self.app.name),
+                    "spec": {
+                        "rules": [{
+                            "http": {
+                                "paths": [{
+                                    "path": "/",
+                                    "backend": {
+                                        "serviceName": self.app.name,
+                                        "servicePort": 80
+                                    }
+                                }]
+                            }
+                        }]
+                    }
+                }]
+            }
+        }
+
+        return resources
+
     def is_valid_config(self):
         is_valid = True
         config = self.model.config

References