Merge ~sajoupa/charm-k8s-telegraf:image-dockerhub into charm-k8s-telegraf:master

Proposed by Laurent Sesquès
Status: Merged
Approved by: Laurent Sesquès
Approved revision: a9858e3dfeb1cb39b95ebe3b3cd78057e6d442a6
Merged at revision: e37ae7199bc800dc966884b178b30c5b9b39d8ed
Proposed branch: ~sajoupa/charm-k8s-telegraf:image-dockerhub
Merge into: charm-k8s-telegraf:master
Diff against target: 172 lines (+48/-21)
5 files modified
.flake8 (+1/-1)
README.md (+32/-4)
config.yaml (+1/-1)
tests/unit/scenario.py (+8/-8)
tests/unit/test_charm.py (+6/-7)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+393334@code.launchpad.net

Commit message

use the telegrafcharmers/telegraf image from dockerhub by default, update README and tests.

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, thx

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

Change successfully merged at revision e37ae7199bc800dc966884b178b30c5b9b39d8ed

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.flake8 b/.flake8
2index 7310f0e..41512a8 100644
3--- a/.flake8
4+++ b/.flake8
5@@ -1,5 +1,5 @@
6 [flake8]
7-max-line-length = 119
8+max-line-length = 120
9 select: E,W,F,C,N
10 exclude:
11 venv
12diff --git a/README.md b/README.md
13index c8adcfa..7a29599 100644
14--- a/README.md
15+++ b/README.md
16@@ -13,12 +13,40 @@ Telegraf is plugin-driven and has the concept of 4 distinct plugin types:
17 Deploying telegraf in a k8s environment makes sense to monitor services or 3rd party
18 APIs, not to gather system stats (telegraf would only monitor itself in its container).
19
20+It is possible for instance to deploy telegraf on k8s to gather metrics about a github
21+repository with the github input plugin, weather data with the OpenWeatherMap input
22+plugin, or check HTTP/HTTPS connections with the http_response plugin.
23+
24 ## Usage
25
26-juju deploy ./telegraf.charm --config inputs='[[inputs.github]]
27- repositories = [
28- "influxdata/telegraf"
29- ]' --config image_path='localhost:32000/telegraf:latest'
30+Deploy the charm to a k8s juju model, for example:
31+
32+ juju deploy cs:~telegraf-charmers/telegraf --config inputs='[[inputs.github]]
33+ repositories = [
34+ "influxdata/telegraf"
35+ ]'
36+
37+In this case, telegraf will expose its metrics using the charm's default output plugin,
38+prometheus on tcp port 9103.
39+
40+## Using a custom image
41+
42+By default the charm will use the telegrafcharmers/telegraf:edge image from dockerhub.
43+To build and push a custom image:
44+
45+ git clone https://git.launchpad.net/charm-k8s-telegraf
46+ cd charm-k8s-telegraf
47+ make image-build
48+ docker tag telegraf:latest localhost:32000/telegraf
49+ docker push localhost:32000/telegraf
50+
51+Then, to use your new image, either replace the `deploy` step above with:
52+
53+ juju deploy ./telegraf.charm --config image_path=localhost:32000/telegraf
54+
55+or, if you've already deployed telegraf:
56+
57+ juju config telegraf image_path=localhost:32000/telegraf
58
59 ## Testing
60
61diff --git a/config.yaml b/config.yaml
62index bf3039d..fbe14b5 100644
63--- a/config.yaml
64+++ b/config.yaml
65@@ -59,7 +59,7 @@ options:
66 The location of the image to use, e.g. "registry.example.com/telegraf:v1".
67
68 This setting is required.
69- default: ''
70+ default: 'telegrafcharmers/telegraf:edge'
71 image_username:
72 type: string
73 description: >
74diff --git a/tests/unit/scenario.py b/tests/unit/scenario.py
75index d74855a..e60569b 100644
76--- a/tests/unit/scenario.py
77+++ b/tests/unit/scenario.py
78@@ -31,8 +31,13 @@ JUJU_DEFAULT_CONFIG = get_juju_default_config()
79 TEST_JUJU_CONFIG = {
80 'defaults': {
81 'config': {},
82- 'logger': ["ERROR:charm:Required Juju config item(s) not set : image_path"],
83- 'expected': 'Required Juju config item(s) not set : image_path',
84+ 'logger': [],
85+ 'expected': False,
86+ },
87+ 'missing_required_config': {
88+ 'config': {'inputs': ''},
89+ 'logger': ["ERROR:charm:Required Juju config item(s) not set : inputs"],
90+ 'expected': 'Required Juju config item(s) not set : inputs',
91 },
92 'good_config': {
93 'config': {'image_path': 'telegraf:latest'},
94@@ -41,7 +46,6 @@ TEST_JUJU_CONFIG = {
95 },
96 'empty_ports_list': {
97 'config': {
98- 'image_path': 'telegraf:latest',
99 'open_ports': '',
100 },
101 'logger': ['ERROR:charm:Required Juju config item(s) not set : open_ports'],
102@@ -49,7 +53,6 @@ TEST_JUJU_CONFIG = {
103 },
104 'port_out_of_range': {
105 'config': {
106- 'image_path': 'telegraf:latest',
107 'open_ports': '9103:tcp,-1:udp',
108 'inputs': '[[inputs.internal]]',
109 'outputs': '[[outputs.prometheus_client]]',
110@@ -59,7 +62,6 @@ TEST_JUJU_CONFIG = {
111 },
112 'invalid_protocol': {
113 'config': {
114- 'image_path': 'telegraf:latest',
115 'open_ports': '9103:tcp,6343:wrong_protocol',
116 'inputs': '[[inputs.internal]]',
117 'outputs': '[[outputs.prometheus_client]]',
118@@ -77,7 +79,6 @@ TEST_JUJU_CONFIG = {
119 },
120 'invalid_port_number': {
121 'config': {
122- 'image_path': 'telegraf:latest',
123 'open_ports': 'not_an_int:tcp',
124 'inputs': '[[inputs.internal]]',
125 'outputs': '[[outputs.prometheus_client]]',
126@@ -129,7 +130,6 @@ TEST_MAKE_OPEN_PORTS_LIST = {
127 TEST_MAKE_POD_SPEC = {
128 'basic': {
129 'config': {
130- 'image_path': 'telegraf:latest',
131 'agent_conf': ('[agent]\n' ' interval = "10s"\n' ' round_interval = true'),
132 },
133 'pod_spec': {
134@@ -138,7 +138,7 @@ TEST_MAKE_POD_SPEC = {
135 {
136 'name': 'telegraf',
137 'imageDetails': {
138- 'imagePath': 'telegraf:latest',
139+ 'imagePath': 'telegrafcharmers/telegraf:edge',
140 },
141 'imagePullPolicy': 'Always',
142 'ports': [{'containerPort': 9103, 'protocol': 'TCP', 'name': '9103-tcp'}],
143diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
144index 030e31c..3ee5524 100644
145--- a/tests/unit/test_charm.py
146+++ b/tests/unit/test_charm.py
147@@ -66,20 +66,19 @@ class TestTelegrafK8sCharm(unittest.TestCase):
148
149 self.harness.update_config(JUJU_DEFAULT_CONFIG)
150
151- self.harness.set_leader(True)
152- self.harness.charm._configure_pod(mock_event)
153- self.assertEqual(
154- self.harness.charm.unit.status, BlockedStatus('Required Juju config item(s) not set : image_path')
155- )
156-
157 for is_leader in [True, False]:
158 self.harness.set_leader(is_leader)
159 self.harness.charm.unit.status = BlockedStatus("Testing")
160- self.harness.update_config({'image_path': 'telegraf:latest'})
161 self.harness.charm._configure_pod(mock_event)
162 self.assertEqual(self.harness.charm.unit.status, ActiveStatus())
163 self.harness.update_config(JUJU_DEFAULT_CONFIG) # You need to clean the config after each run
164
165+ self.harness.set_leader(True)
166+ self.harness.update_config({'inputs': ''})
167+ self.harness.charm._configure_pod(mock_event)
168+ self.assertEqual(self.harness.charm.unit.status, BlockedStatus("Required Juju config item(s) not set : inputs"))
169+ self.harness.update_config(JUJU_DEFAULT_CONFIG) # You need to clean the config after each run
170+
171 def test_make_open_ports_list(self):
172 """Test the _make_open_ports_list function."""
173

Subscribers

People subscribed via source and target branches