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
diff --git a/src/charm.py b/src/charm.py
index eb751a6..f4922e3 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -16,33 +16,6 @@ logger = logging.getLogger()
16REQUIRED_SETTINGS = ['bind_image_path']16REQUIRED_SETTINGS = ['bind_image_path']
1717
1818
19def generate_pod_config(config, secured=True):
20 """Kubernetes pod config generator.
21
22 generate_pod_config generates Kubernetes deployment config.
23 If the secured keyword is set then it will return a sanitised copy
24 without exposing secrets.
25 """
26 pod_config = {}
27 if config["container_config"].strip():
28 pod_config = safe_load(config["container_config"])
29
30 if config["custom_config_repo"].strip():
31 pod_config["CUSTOM_CONFIG_REPO"] = config["custom_config_repo"]
32
33 if config["https_proxy"].strip():
34 pod_config["http_proxy"] = config["https_proxy"]
35 pod_config["https_proxy"] = config["https_proxy"]
36
37 if secured:
38 return pod_config
39
40 # Add secrets from charm config.
41 pass
42
43 return pod_config
44
45
46class BindK8sCharm(CharmBase):19class BindK8sCharm(CharmBase):
47 def __init__(self, *args):20 def __init__(self, *args):
48 super().__init__(*args)21 super().__init__(*args)
@@ -93,6 +66,7 @@ class BindK8sCharm(CharmBase):
93 self.model.unit.status = ActiveStatus(msg)66 self.model.unit.status = ActiveStatus(msg)
94 else:67 else:
95 logger.info("Spec changes ignored by non-leader")68 logger.info("Spec changes ignored by non-leader")
69 self.model.unit.status = ActiveStatus()
9670
97 def make_pod_resources(self):71 def make_pod_resources(self):
98 resources = {}72 resources = {}
@@ -101,10 +75,40 @@ class BindK8sCharm(CharmBase):
101 logger.info("This is the Kubernetes Pod resources <<EOM\n{}\nEOM".format(out.getvalue()))75 logger.info("This is the Kubernetes Pod resources <<EOM\n{}\nEOM".format(out.getvalue()))
102 return resources76 return resources
10377
78 def generate_pod_config(self, secured=True):
79 """Kubernetes pod config generator.
80
81 generate_pod_config generates Kubernetes deployment config.
82 If the secured keyword is set then it will return a sanitised copy
83 without exposing secrets.
84 """
85 config = self.model.config
86 pod_config = {}
87 if config["container_config"].strip():
88 pod_config = safe_load(config["container_config"])
89
90 if config["custom_config_repo"].strip():
91 pod_config["CUSTOM_CONFIG_REPO"] = config["custom_config_repo"]
92
93 if config["https_proxy"].strip():
94 pod_config["http_proxy"] = config["https_proxy"]
95 pod_config["https_proxy"] = config["https_proxy"]
96
97 if secured:
98 return pod_config
99
100 if config["container_secrets"].strip():
101 container_secrets = safe_load(config["container_secrets"])
102 else:
103 container_secrets = {}
104
105 pod_config.update(container_secrets)
106 return pod_config
107
104 def make_pod_spec(self):108 def make_pod_spec(self):
105 config = self.model.config109 config = self.model.config
106 full_pod_config = generate_pod_config(config, secured=False)110 full_pod_config = self.generate_pod_config(secured=False)
107 secure_pod_config = generate_pod_config(config, secured=True)111 secure_pod_config = self.generate_pod_config(secured=True)
108112
109 ports = [113 ports = [
110 {"name": "domain-tcp", "containerPort": 53, "protocol": "TCP"},114 {"name": "domain-tcp", "containerPort": 53, "protocol": "TCP"},

Subscribers

People subscribed via source and target branches

to all changes: