Skip to content

Commit 22db0b9

Browse files
Merge pull request #470 from treydock/etcd-monitoring
Add etcd_listen_metric_urls parameter
2 parents 2661d87 + 04fa9f0 commit 22db0b9

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

manifests/config/kubeadm.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
String $etcd_version = $kubernetes::etcd_version,
3232
Integer $etcd_max_wals = $kubernetes::etcd_max_wals,
3333
Integer $etcd_max_request_bytes = $kubernetes::etcd_max_request_bytes,
34+
Optional[String] $etcd_listen_metric_urls = $kubernetes::etcd_listen_metric_urls,
3435
String $token = $kubernetes::token,
3536
String $ttl_duration = $kubernetes::ttl_duration,
3637
String $discovery_token_hash = $kubernetes::discovery_token_hash,

manifests/init.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@
193193
# This will tell etcd the maximum size of a request in bytes
194194
# Defaults to 1572864
195195
#
196+
# [*etcd_listen_metric_urls*]
197+
# The URL(s) to listen on to respond to /metrics and /health for etcd
198+
# Defaults to undef
199+
#
196200
# [*etcd_ca_key*]
197201
# This is the ca certificate key data for the etcd cluster. This must be passed as string not as a file.
198202
# Defaults to undef
@@ -529,6 +533,7 @@
529533
Variant[String, Integer] $etcd_compaction_retention = 0,
530534
Integer $etcd_max_wals = 5,
531535
Integer $etcd_max_request_bytes = 1572864,
536+
Optional[String] $etcd_listen_metric_urls = undef,
532537
Optional[String] $etcd_ca_key = undef,
533538
Optional[String] $etcd_ca_crt = undef,
534539
Optional[String] $etcdclient_key = undef,

spec/classes/config/kubeadm_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,25 @@
5555
it { is_expected.to contain_file('/etc/systemd/system/etcd.service') }
5656
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').with_content(%r{.*--initial-cluster *}) }
5757
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--discovery-srv.*}) }
58+
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--listen-metrics-urls.*}) }
5859
it { is_expected.not_to contain_file('/etc/default/etcd') }
5960
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
6061
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{foo:\n- bar\n- baz}) }
6162
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{kubeletConfiguration:\n baseConfig:\n baz:\n - bar\n - foo}) }
63+
64+
context 'with etcd_listen_metric_urls defined' do
65+
let(:params) do
66+
{
67+
'manage_etcd' => true,
68+
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
69+
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
70+
'kubelet_extra_arguments' => ['foo'],
71+
'etcd_listen_metric_urls' => 'http://0.0.0.0:2381',
72+
}
73+
end
74+
75+
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').with_content(%r{.*--listen-metrics-urls http://0.0.0.0:2381.*}) }
76+
end
6277
end
6378

6479
context 'with manage_etcd => true and delegated_pki => true' do
@@ -94,6 +109,7 @@
94109
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').with_content(%r{.*--initial-cluster *}) }
95110
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').with_content(%r{.*--auto-compaction-mode*}) }
96111
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--discovery-srv.*}) }
112+
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--listen-metrics-urls.*}) }
97113
it { is_expected.not_to contain_file('/etc/default/etcd') }
98114
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
99115
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{foo:\n- bar\n- baz}) }
@@ -150,6 +166,23 @@
150166
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{.*ETCD_INITIAL_CLUSTER=.*}) }
151167
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{.*ETCD_AUTO_COMPACTION_MODE=.*}) }
152168
it { is_expected.to contain_file('/etc/default/etcd').without_content(%r{.*ETCD_DISCOVERY_SRV=.*}) }
169+
it { is_expected.to contain_file('/etc/default/etcd').without_content(%r{.*ETCD_LISTEN_METRICS_URLS=.*}) }
170+
171+
context 'with etcd_listen_metric_urls defined' do
172+
let(:params) do
173+
{
174+
'etcd_install_method' => 'package',
175+
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
176+
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
177+
'kubelet_extra_arguments' => ['foo'],
178+
'manage_etcd' => true,
179+
'etcd_version' => '3.3.0',
180+
'etcd_listen_metric_urls' => 'http://0.0.0.0:2381',
181+
}
182+
end
183+
184+
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{.*ETCD_LISTEN_METRICS_URLS="http://0.0.0.0:2381".*}) }
185+
end
153186
end
154187

155188
context 'manage_etcd => true and etcd_install_method => package and etcd_discovery_srv => etcd-autodiscovery' do

templates/etcd/etcd.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ ETCD_AUTO_COMPACTION_MODE="<%= @etcd_compaction_method %>"
1717
ETCD_AUTO_COMPACTION_RETENTION="<%= @etcd_compaction_retention %>"
1818
ETCD_MAX_WALS="<%= @etcd_max_wals %>"
1919
ETCD_MAX_REQUEST_BYTES="<%= @etcd_max_request_bytes %>"
20+
<%- if @etcd_listen_metric_urls -%>
21+
ETCD_LISTEN_METRICS_URLS="<%= @etcd_listen_metric_urls %>"
22+
<%- end -%>
2023
ETCD_ADVERTISE_CLIENT_URLS="https://<%= @etcd_ip %>:2379"
2124
ETCD_CERT_FILE="/etc/kubernetes/pki/etcd/server.crt"
2225
ETCD_KEY_FILE="/etc/kubernetes/pki/etcd/server.key"

templates/etcd/etcd.service.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ ExecStart=/usr/local/bin/etcd --name <%= @etcd_hostname %> \
4040
<% if @etcd_version >= "3.3.0" -%>
4141
--auto-compaction-mode <%= @etcd_compaction_method %> \
4242
<% end -%>
43-
--max-wals <%= @etcd_max_wals %> \
4443
--max-request-bytes <%= @etcd_max_request_bytes %>
44+
<%- if @etcd_listen_metric_urls -%>
45+
--listen-metrics-urls <%= @etcd_listen_metric_urls %> \
46+
<%- end -%>
47+
--max-wals <%= @etcd_max_wals %>
4548

4649

4750
[Install]

0 commit comments

Comments
 (0)