forked from puppetlabs/puppetlabs-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubeadm_spec.rb
619 lines (512 loc) · 22.6 KB
/
kubeadm_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# frozen_string_literal: true
require 'spec_helper'
describe 'kubernetes::config::kubeadm', type: :class do
let(:pre_condition) { 'include kubernetes' }
let(:facts) do
{
kernel: 'Linux',
networking: {
hostname: 'foo'
},
os: {
family: 'Debian',
name: 'Ubuntu',
release: {
full: '16.04'
},
distro: {
codename: 'xenial'
}
},
ec2_metadata: {
hostname: 'ip-10-10-10-1.ec2.internal'
}
}
end
context 'with manage_etcd => true' do
let(:pre_condition) { 'include kubernetes' }
let(:params) do
{
'manage_etcd' => true,
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
'kubelet_extra_arguments' => ['foo']
}
end
kube_dirs = ['/etc/kubernetes', '/etc/kubernetes/manifests', '/etc/kubernetes/pki', '/etc/kubernetes/pki/etcd']
etcd = ['ca.crt', 'ca.key', 'client.crt', 'client.key', 'peer.crt', 'peer.key', 'server.crt', 'server.key']
pki = ['ca.crt', 'ca.key', 'front-proxy-ca.crt', 'front-proxy-ca.key', 'sa.pub', 'sa.key']
kube_dirs.each do |d|
it { is_expected.to contain_file(d.to_s) }
end
etcd.each do |f|
it { is_expected.to contain_file("/etc/kubernetes/pki/etcd/#{f}") }
end
pki.each do |cert|
it { is_expected.to contain_file("/etc/kubernetes/pki/#{cert}") }
end
it { is_expected.to contain_file('/etc/systemd/system/etcd.service') }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').with_content(%r{.*--initial-cluster *}) }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--discovery-srv.*}) }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--listen-metrics-urls.*}) }
it { is_expected.not_to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{foo:\n- bar\n- baz}) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{kubeletConfiguration:\n baseConfig:\n baz:\n - bar\n - foo}) }
context 'with etcd_listen_metric_urls defined' do
let(:params) do
{
'manage_etcd' => true,
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
'kubelet_extra_arguments' => ['foo'],
'etcd_listen_metric_urls' => 'http://0.0.0.0:2381'
}
end
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').with_content(%r{.*--listen-metrics-urls http://0.0.0.0:2381.*}) }
end
end
context 'with manage_etcd => true and delegated_pki => true' do
let(:pre_condition) { 'include kubernetes' }
let(:params) do
{
'manage_etcd' => true,
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
'kubelet_extra_arguments' => ['foo'],
'delegated_pki' => true,
'etcd_version' => '3.3.0'
}
end
kube_dirs = ['/etc/kubernetes', '/etc/kubernetes/manifests', '/etc/kubernetes/pki', '/etc/kubernetes/pki/etcd']
etcd = ['ca.crt', 'ca.key', 'client.crt', 'client.key', 'peer.crt', 'peer.key', 'server.crt', 'server.key']
pki = ['ca.crt', 'ca.key', 'front-proxy-ca.crt', 'front-proxy-ca.key', 'sa.pub', 'sa.key']
kube_dirs.each do |d|
it { is_expected.to contain_file(d.to_s) }
end
etcd.each do |f|
it { is_expected.not_to contain_file("/etc/kubernetes/pki/etcd/#{f}") }
end
pki.each do |cert|
it { is_expected.not_to contain_file("/etc/kubernetes/pki/#{cert}") }
end
it { is_expected.to contain_file('/etc/systemd/system/etcd.service') }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').with_content(%r{.*--initial-cluster *}) }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').with_content(%r{.*--auto-compaction-mode*}) }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--discovery-srv.*}) }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--listen-metrics-urls.*}) }
it { is_expected.not_to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{foo:\n- bar\n- baz}) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{kubeletConfiguration:\n baseConfig:\n baz:\n - bar\n - foo}) }
end
context 'with manage_etcd => false' do
let(:params) do
{
'manage_etcd' => false,
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
'kubelet_extra_arguments' => ['foo']
}
end
kube_dirs = ['/etc/kubernetes', '/etc/kubernetes/manifests', '/etc/kubernetes/pki', '/etc/kubernetes/pki/etcd']
etcd = ['ca.crt', 'ca.key', 'client.crt', 'client.key', 'peer.crt', 'peer.key', 'server.crt', 'server.key']
pki = ['ca.crt', 'ca.key', 'front-proxy-ca.crt', 'front-proxy-ca.key', 'sa.pub', 'sa.key']
kube_dirs.each do |d|
it { is_expected.to contain_file(d.to_s) }
end
etcd.each do |f|
it { is_expected.not_to contain_file("/etc/kubernetes/pki/etcd/#{f}") }
end
pki.each do |cert|
it { is_expected.to contain_file("/etc/kubernetes/pki/#{cert}") }
end
it { is_expected.not_to contain_file('/etc/systemd/system/etcd.service') }
it { is_expected.not_to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{foo:\n- bar\n- baz}) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml').with_content(%r{kubeletConfiguration:\n baseConfig:\n baz:\n - bar\n - foo}) }
end
context 'manage_etcd => true and etcd_install_method => package' do
let(:params) do
{
'etcd_install_method' => 'package',
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
'kubelet_extra_arguments' => ['foo'],
'manage_etcd' => true,
'etcd_version' => '3.3.0'
}
end
it { is_expected.not_to contain_file('/etc/systemd/system/etcd.service') }
it { is_expected.to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{.*ETCD_INITIAL_CLUSTER=.*}) }
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{.*ETCD_AUTO_COMPACTION_MODE=.*}) }
it { is_expected.to contain_file('/etc/default/etcd').without_content(%r{.*ETCD_DISCOVERY_SRV=.*}) }
it { is_expected.to contain_file('/etc/default/etcd').without_content(%r{.*ETCD_LISTEN_METRICS_URLS=.*}) }
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{ETCD_DATA_DIR="/var/lib/etcd"}) }
context 'with etcd_listen_metric_urls defined' do
let(:params) do
{
'etcd_install_method' => 'package',
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
'kubelet_extra_arguments' => ['foo'],
'manage_etcd' => true,
'etcd_version' => '3.3.0',
'etcd_listen_metric_urls' => 'http://0.0.0.0:2381'
}
end
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{.*ETCD_LISTEN_METRICS_URLS="http://0.0.0.0:2381".*}) }
end
end
context 'manage_etcd => true and etcd_install_method => package and etcd_discovery_srv => etcd-autodiscovery and etcd_data_dir => "/var/lib/foo"' do
let(:params) do
{
'etcd_install_method' => 'package',
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
'kubelet_extra_arguments' => ['foo'],
'manage_etcd' => true,
'etcd_discovery_srv' => 'etcd-autodiscovery',
'etcd_version' => '2.9.9',
'etcd_data_dir' => '/var/lib/foo'
}
end
it { is_expected.not_to contain_file('/etc/systemd/system/etcd.service') }
it { is_expected.to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/default/etcd').without_content(%r{.*ETCD_INITIAL_CLUSTER=.*}) }
it { is_expected.to contain_file('/etc/default/etcd').without_content(%r{.*ETCD_AUTO_COMPACTION_MODE=.*}) }
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{.*ETCD_DISCOVERY_SRV="etcd-autodiscovery".*}) }
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{ETCD_DATA_DIR="/var/lib/foo"}) }
end
context 'manage_etcd => true and etcd_install_method => wget and etcd_discovery_srv => etcd-autodiscovery' do
let(:params) do
{
'etcd_install_method' => 'wget',
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
'kubelet_extra_arguments' => ['foo'],
'manage_etcd' => true,
'etcd_discovery_srv' => 'etcd-autodiscovery',
'etcd_version' => '2.9.9'
}
end
it { is_expected.not_to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service') }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').with_content(%r{.*--discovery-srv etcd-autodiscovery.*}) }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--initial-cluster .*}) }
it { is_expected.to contain_file('/etc/systemd/system/etcd.service').without_content(%r{.*--auto-compaction-mode .*}) }
end
context 'manage_etcd => true and etcd_install_method => package and etcd_data_dir => /var/lib/bar' do
let(:params) do
{
'etcd_install_method' => 'package',
'kubeadm_extra_config' => { 'foo' => ['bar', 'baz'] },
'kubelet_extra_config' => { 'baz' => ['bar', 'foo'] },
'kubelet_extra_arguments' => ['foo'],
'manage_etcd' => true,
'etcd_data_dir' => '/var/lib/bar'
}
end
it { is_expected.not_to contain_file('/etc/systemd/system/etcd.service') }
it { is_expected.to contain_file('/etc/default/etcd') }
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{.*ETCD_INITIAL_CLUSTER=.*}) }
it { is_expected.to contain_file('/etc/default/etcd').without_content(%r{.*ETCD_DISCOVERY_SRV=.*}) }
it { is_expected.to contain_file('/etc/default/etcd').with_content(%r{ETCD_DATA_DIR="/var/lib/bar"}) }
end
context 'with version = 1.12 and node_name => foo and cloud_provider => aws' do
let(:params) do
{
'kubernetes_version' => '1.12.3',
'node_name' => 'foo',
'cloud_provider' => 'aws',
'cloud_config' => :undef,
'kubelet_extra_arguments' => ['foo: bar']
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has node_name==foo in first YAML document (InitConfig)' do
expect(config_yaml[0]['nodeRegistration']).to include('name' => params['node_name'])
end
it 'has cloud-provider==aws in first YAML document (InitConfig) NodeRegistration' do
expect(config_yaml[0]['nodeRegistration']['kubeletExtraArgs']).to include('cloud-provider' => params['cloud_provider'])
end
it 'does not have cloud-config in second YAML document (InitConfig) NodeRegistration' do
expect(config_yaml[0]['nodeRegistration']['kubeletExtraArgs']).not_to include('cloud-config')
end
end
context 'with version = 1.12 and cgroup_driver => systemd and cloud_provider => aws and cloud_config => /etc/kubernetes/cloud.conf' do
let(:params) do
{
'kubernetes_version' => '1.12.3',
'node_name' => 'foo',
'cgroup_driver' => 'systemd',
'cloud_provider' => 'aws',
'cloud_config' => '/etc/kubernetes/cloud.conf',
'kubelet_extra_arguments' => ['foo: bar']
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it 'has API Server extra volumes in YAML document' do
expect(config_yaml[1]).to include('apiServerExtraVolumes')
end
end
context 'with version = 1.12 and kubernetes_cluster_name => my_own_name' do
let(:params) do
{
'kubernetes_version' => '1.12.3',
'kubernetes_cluster_name' => 'my_own_name'
}
end
it {
expect(subject).to contain_file('/etc/kubernetes/config.yaml') \
.with_content(%r{clusterName: my_own_name\n})
}
end
context 'with version = 1.13 and kubernetes_cluster_name => my_own_name' do
let(:params) do
{
'kubernetes_version' => '1.13.0',
'kubernetes_cluster_name' => 'my_own_name'
}
end
it {
expect(subject).to contain_file('/etc/kubernetes/config.yaml') \
.with_content(%r{clusterName: my_own_name\n})
}
end
context 'with version = 1.14 - apiserver_extra_arguments' do
let(:params) do
{
'kubernetes_version' => '1.14.1',
'apiserver_extra_arguments' => ['foo', 'bar']
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has foo in API server arguments' do
expect(config_yaml[1]['apiServer']['extraArgs']).to include('foo')
end
it 'has bar in API server arguments' do
expect(config_yaml[1]['apiServer']['extraArgs']).to include('bar')
end
end
context 'with version = 1.14 - controllermanager_extra_arguments' do
let(:params) do
{
'kubernetes_version' => '1.14.1',
'controllermanager_extra_arguments' => ['foo', 'bar']
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has foo in controller manager arguments' do
expect(config_yaml[1]['controllerManager']['extraArgs']).to include('foo')
end
it 'has bar in controller manager arguments' do
expect(config_yaml[1]['controllerManager']['extraArgs']).to include('bar')
end
end
context 'with version = 1.14 - scheduler_extra_arguments' do
let(:params) do
{
'kubernetes_version' => '1.14.1',
'scheduler_extra_arguments' => ['foo', 'bar']
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has foo in scheduler arguments' do
expect(config_yaml[1]['scheduler']['extraArgs']).to include('foo')
end
it 'has bar in scheduler arguments' do
expect(config_yaml[1]['scheduler']['extraArgs']).to include('bar')
end
end
context 'with version = 1.14 - apiserver_extra_volumes' do
let(:params) do
{
'kubernetes_version' => '1.14.1',
'apiserver_extra_volumes' => {
'foo' => {
'hostPath' => '/mnt',
'mountPath' => '/data',
'readOnly' => false,
'pathType' => 'Directory'
}
}
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has hostPath: /mnt in API server extra volumes' do
expect(config_yaml[1]['apiServer']['extraVolumes']).to include('name' => 'foo', 'hostPath' => '/mnt', 'mountPath' => '/data', 'readOnly' => false, 'pathType' => 'Directory')
end
end
context 'with version = 1.14 - controllermanager_extra_volumes' do
let(:params) do
{
'kubernetes_version' => '1.14.1',
'controllermanager_extra_volumes' => {
'foo' => {
'hostPath' => '/mnt',
'mountPath' => '/data',
'readOnly' => false,
'pathType' => 'Directory'
}
}
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has hostPath: /mnt in controller manager extra volumes' do
expect(config_yaml[1]['controllerManager']['extraVolumes']).to include('name' => 'foo', 'hostPath' => '/mnt', 'mountPath' => '/data', 'readOnly' => false, 'pathType' => 'Directory')
end
end
context 'with version = 1.14 - controller_address' do
let(:params) do
{
'kubernetes_version' => '1.14.1',
'controller_address' => 'foo'
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has foo in controlPlaneEndpoint' do
expect(config_yaml[1]['controlPlaneEndpoint']).to include('foo')
end
end
context 'with version = 1.14 - proxy_mode' do
let(:params) do
{
'kubernetes_version' => '1.14.2',
'proxy_mode' => 'ipvs'
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has ipvs in mode:' do
expect(config_yaml[2]['mode']).to include('ipvs')
end
end
context 'with metrics_bind_address = 0.0.0.0 with version 1.14.2 and kube_api_bind_port 12345' do
let(:params) do
{
'kubernetes_version' => '1.14.2',
'metrics_bind_address' => '0.0.0.0',
'kube_api_bind_port' => 12_345
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has 0.0.0.0 in metrics_bind_address:' do
expect(config_yaml[2]['metricsBindAddress']).to include('0.0.0.0')
end
it 'has 12345 in kube_api_bind_port:' do
expect(config_yaml[0]['localAPIEndpoint']['bindPort']).to eq(12_345)
end
end
context 'with metrics_bind_address = 0.0.0.0 with version 1.16.3 and kube_api_bind_port 12345' do
let(:params) do
{
'kubernetes_version' => '1.16.3',
'metrics_bind_address' => '0.0.0.0',
'kube_api_bind_port' => 12_345
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has 0.0.0.0 in metrics_bind_address:' do
expect(config_yaml[2]['metricsBindAddress']).to include('0.0.0.0')
end
it 'has 12345 in kube_api_bind_port:' do
expect(config_yaml[0]['localAPIEndpoint']['bindPort']).to eq(12_345)
end
end
context 'with metrics_bind_address = invalid' do
let(:params) do
{
'kubernetes_version' => '1.14.2',
'metrics_bind_address' => 'invalid'
}
end
it { is_expected.to compile.and_raise_error(%r{metrics_bind_address}) }
end
context 'with conntrack settings version = 1.14' do
let(:params) do
{
'kubernetes_version' => '1.14.2',
'conntrack_max_per_core' => 0,
'conntrack_min' => 0,
'conntrack_tcp_wait_timeout' => '0h0m0s',
'conntrack_tcp_stablished_timeout' => '0h0m0s'
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has 0 in kube_proxy_conntrack_max_per_core:' do
expect(config_yaml[2]['conntrack']['maxPerCore']).to eq(0)
end
it 'has 0 in kube_proxy_conntrack_min:' do
expect(config_yaml[2]['conntrack']['min']).to eq(0)
end
it 'has 0h0m0s in kube_proxy_conntrack_tcp_wait_timeout:' do
expect(config_yaml[2]['conntrack']['tcpCloseWaitTimeout']).to eq('0h0m0s')
end
it 'has 0h0m0s in kube_proxy_conntrack_tcp_stablished_timeout:' do
expect(config_yaml[2]['conntrack']['tcpEstablishedTimeout']).to eq('0h0m0s')
end
end
context 'with conntrack settings version = 1.16' do
let(:params) do
{
'kubernetes_version' => '1.16.2',
'conntrack_max_per_core' => 0,
'conntrack_min' => 0,
'conntrack_tcp_wait_timeout' => '0h0m0s',
'conntrack_tcp_stablished_timeout' => '0h0m0s'
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it { is_expected.to contain_file('/etc/kubernetes/config.yaml') }
it 'has 0 in kube_proxy_conntrack_max_per_core:' do
expect(config_yaml[2]['conntrack']['maxPerCore']).to eq(0)
end
it 'has 0 in kube_proxy_conntrack_min:' do
expect(config_yaml[2]['conntrack']['min']).to eq(0)
end
it 'has 0h0m0s in kube_proxy_conntrack_tcp_wait_timeout:' do
expect(config_yaml[2]['conntrack']['tcpCloseWaitTimeout']).to eq('0h0m0s')
end
it 'has 0h0m0s in kube_proxy_conntrack_tcp_stablished_timeout:' do
expect(config_yaml[2]['conntrack']['tcpEstablishedTimeout']).to eq('0h0m0s')
end
end
context 'set role control-plane' do
let(:params) do
{
'kubernetes_version' => '1.20.0'
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it {
expect(subject).to contain_file('/etc/kubernetes/config.yaml') \
.with_content(%r{key: node-role.kubernetes.io/control-plane\n})
}
end
context 'when scheduler_extra_arguments is defined' do
let(:params) do
{
'kubernetes_version' => '1.26.0',
'scheduler_extra_arguments' => ['bind-address: 0.0.0.0']
}
end
let(:config_yaml) { YAML.load_stream(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
it 'has scheduler extra arguments' do
cluster_config = config_yaml.find { |c| c['kind'] == 'ClusterConfiguration' }
expect(cluster_config['scheduler']['extraArgs']['bind-address']).to eq('0.0.0.0')
end
end
end