Merge ~barryprice/charm-k8s-bind/+git/charm-k8s-bind:charm-fixes into charm-k8s-bind:master

Proposed by Barry Price
Status: Merged
Approved by: Tom Haddon
Approved revision: 1dc9a9219ae394ed8184b36771ee98b11b2bb54a
Merged at revision: 2716ef0783c3fb02e5c72e19fea4109ceffb9459
Proposed branch: ~barryprice/charm-k8s-bind/+git/charm-k8s-bind:charm-fixes
Merge into: charm-k8s-bind:master
Prerequisite: ~barryprice/charm-k8s-bind/+git/charm-k8s-bind:image-builder
Diff against target: 89 lines (+33/-29)
1 file modified
src/charm.py (+33/-29)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+388450@code.launchpad.net

Commit message

Move generate_pod_config() inside our class, add an ActiveStatus to non-leader units, handle container_secrets correctly

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
Tom Haddon (mthaddon) wrote :

LGTM

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

Change successfully merged at revision 2716ef0783c3fb02e5c72e19fea4109ceffb9459

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 eb751a6..f4922e3 100755
3--- a/src/charm.py
4+++ b/src/charm.py
5@@ -16,33 +16,6 @@ logger = logging.getLogger()
6 REQUIRED_SETTINGS = ['bind_image_path']
7
8
9-def generate_pod_config(config, secured=True):
10- """Kubernetes pod config generator.
11-
12- generate_pod_config generates Kubernetes deployment config.
13- If the secured keyword is set then it will return a sanitised copy
14- without exposing secrets.
15- """
16- pod_config = {}
17- if config["container_config"].strip():
18- pod_config = safe_load(config["container_config"])
19-
20- if config["custom_config_repo"].strip():
21- pod_config["CUSTOM_CONFIG_REPO"] = config["custom_config_repo"]
22-
23- if config["https_proxy"].strip():
24- pod_config["http_proxy"] = config["https_proxy"]
25- pod_config["https_proxy"] = config["https_proxy"]
26-
27- if secured:
28- return pod_config
29-
30- # Add secrets from charm config.
31- pass
32-
33- return pod_config
34-
35-
36 class BindK8sCharm(CharmBase):
37 def __init__(self, *args):
38 super().__init__(*args)
39@@ -93,6 +66,7 @@ class BindK8sCharm(CharmBase):
40 self.model.unit.status = ActiveStatus(msg)
41 else:
42 logger.info("Spec changes ignored by non-leader")
43+ self.model.unit.status = ActiveStatus()
44
45 def make_pod_resources(self):
46 resources = {}
47@@ -101,10 +75,40 @@ class BindK8sCharm(CharmBase):
48 logger.info("This is the Kubernetes Pod resources <<EOM\n{}\nEOM".format(out.getvalue()))
49 return resources
50
51+ def generate_pod_config(self, secured=True):
52+ """Kubernetes pod config generator.
53+
54+ generate_pod_config generates Kubernetes deployment config.
55+ If the secured keyword is set then it will return a sanitised copy
56+ without exposing secrets.
57+ """
58+ config = self.model.config
59+ pod_config = {}
60+ if config["container_config"].strip():
61+ pod_config = safe_load(config["container_config"])
62+
63+ if config["custom_config_repo"].strip():
64+ pod_config["CUSTOM_CONFIG_REPO"] = config["custom_config_repo"]
65+
66+ if config["https_proxy"].strip():
67+ pod_config["http_proxy"] = config["https_proxy"]
68+ pod_config["https_proxy"] = config["https_proxy"]
69+
70+ if secured:
71+ return pod_config
72+
73+ if config["container_secrets"].strip():
74+ container_secrets = safe_load(config["container_secrets"])
75+ else:
76+ container_secrets = {}
77+
78+ pod_config.update(container_secrets)
79+ return pod_config
80+
81 def make_pod_spec(self):
82 config = self.model.config
83- full_pod_config = generate_pod_config(config, secured=False)
84- secure_pod_config = generate_pod_config(config, secured=True)
85+ full_pod_config = self.generate_pod_config(secured=False)
86+ secure_pod_config = self.generate_pod_config(secured=True)
87
88 ports = [
89 {"name": "domain-tcp", "containerPort": 53, "protocol": "TCP"},

Subscribers

People subscribed via source and target branches

to all changes: