wordpress-charmers team mailing list archive
-
wordpress-charmers team
-
Mailing list archive
-
Message #00312
[Merge] ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:master into charm-k8s-wordpress:master
Thomas Cuthbert has proposed merging ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:master into charm-k8s-wordpress:master.
Commit message:
Configure ingress resource
Requested reviews:
Canonical IS Reviewers (canonical-is-reviewers)
Wordpress Charmers (wordpress-charmers)
For more details, see:
https://code.launchpad.net/~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress/+merge/384611
--
Your team Wordpress Charmers is requested to review the proposed merge of ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:master into charm-k8s-wordpress:master.
diff --git a/config.yaml b/config.yaml
index 7bc9cb2..b426487 100644
--- a/config.yaml
+++ b/config.yaml
@@ -17,6 +17,10 @@ options:
Ports to expose, space separated list in name:8000 format. Names are alphanumeric + hyphen.
e.g. "http:80 metrics:7127"
default: "http:80"
+ tls_secret_name:
+ type: string
+ description: "The Kubernetes TLS secret resource name."
+ default: ""
db_host:
type: string
description: "MySQL database host"
diff --git a/src/charm.py b/src/charm.py
index 46ad990..947dd6a 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -143,7 +143,9 @@ class WordpressK8sCharm(CharmBase):
def configure_pod(self):
# Only the leader can set_spec().
if self.model.unit.is_leader():
+ resources = self.make_pod_resources()
spec = self.make_pod_spec()
+ spec.update(resources)
msg = "Configuring pod"
logger.info(msg)
@@ -156,6 +158,39 @@ class WordpressK8sCharm(CharmBase):
else:
logger.info("Spec changes ignored by non-leader")
+ def make_pod_resources(self):
+ resources = {
+ "kubernetesResources": {
+ "ingressResources": [{
+ "name": self.app.name,
+ "spec": {
+ "rules": [{
+ "host": self.model.config["blog_hostname"],
+ "http": {
+ "paths": [{
+ "path": "/",
+ "backend": {
+ "serviceName": self.app.name,
+ "servicePort": 80
+ }
+ }]
+ }
+ }],
+ "tls": [{
+ "hosts": [self.model.config["blog_hostname"]],
+ "secretName": self.model.config["tls_secret_name"],
+ }],
+ }
+ }]
+ }
+ }
+
+ out = io.StringIO()
+ pprint(resources, out)
+ logger.info("This is the Kubernetes Pod resources <<EOM\n{}\nEOM".format(out.getvalue()))
+
+ return resources
+
def make_pod_spec(self):
config = self.model.config
full_pod_config = generate_pod_config(config, secured=False)
@@ -167,14 +202,16 @@ class WordpressK8sCharm(CharmBase):
]
spec = {
+ "version": 2,
"containers": [
{
"name": self.app.name,
"imageDetails": {"imagePath": config["image"]},
"ports": ports,
"config": secure_pod_config,
- "readinessProbe": {"exec": {"command": ["/srv/wordpress-helpers/ready.sh"]}},
- }
+ "kubernetes": {
+ "readinessProbe": {"exec": {"command": ["/srv/wordpress-helpers/ready.sh"]}},
+ }}
]
}
References