This repository has been archived by the owner on May 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
kibana_test.py
237 lines (186 loc) · 6.89 KB
/
kibana_test.py
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
import os
import sys
sys.path.insert(1, os.path.join(sys.path[0], '../../helpers'))
from helpers import helm_template
import yaml
name = 'RELEASE-NAME-kibana'
elasticsearchHosts = 'http://elasticsearch-master:9200'
def test_defaults():
config = '''
'''
r = helm_template(config)
assert name in r['deployment']
assert name in r['service']
s = r['service'][name]['spec']
assert s['ports'][0]['port'] == 5601
assert s['ports'][0]['name'] == 'http'
assert s['ports'][0]['protocol'] == 'TCP'
c = r['deployment'][name]['spec']['template']['spec']['containers'][0]
assert c['name'] == 'kibana'
assert c['image'].startswith('docker.elastic.co/kibana/kibana:')
assert c['ports'][0]['containerPort'] == 5601
assert c['env'][0]['name'] == 'ELASTICSEARCH_HOSTS'
assert c['env'][0]['value'] == elasticsearchHosts
assert 'http "/app/kibana"' in c['readinessProbe']['exec']['command'][-1]
# Empty customizable defaults
assert 'imagePullSecrets' not in r['deployment'][name]['spec']['template']['spec']
assert 'tolerations' not in r['deployment'][name]['spec']['template']['spec']
assert 'nodeSelector' not in r['deployment'][name]['spec']['template']['spec']
assert 'ingress' not in r
assert r['deployment'][name]['spec']['strategy']['type'] == 'Recreate'
def test_overriding_the_elasticsearch_hosts():
config = '''
elasticsearchHosts: 'http://hello.world'
'''
r = helm_template(config)
c = r['deployment'][name]['spec']['template']['spec']['containers'][0]
assert c['env'][0]['name'] == 'ELASTICSEARCH_HOSTS'
assert c['env'][0]['value'] == 'http://hello.world'
def test_overriding_the_elasticsearch_url():
config = '''
elasticsearchURL: 'http://hello.world'
'''
r = helm_template(config)
c = r['deployment'][name]['spec']['template']['spec']['containers'][0]
assert c['env'][0]['name'] == 'ELASTICSEARCH_URL'
assert c['env'][0]['value'] == 'http://hello.world'
def test_overriding_the_port():
config = '''
httpPort: 5602
'''
r = helm_template(config)
c = r['deployment'][name]['spec']['template']['spec']['containers'][0]
assert c['ports'][0]['containerPort'] == 5602
def test_adding_image_pull_secrets():
config = '''
imagePullSecrets:
- name: test-registry
'''
r = helm_template(config)
assert r['deployment'][name]['spec']['template']['spec']['imagePullSecrets'][0]['name'] == 'test-registry'
def test_adding_tolerations():
config = '''
tolerations:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoExecute"
tolerationSeconds: 3600
'''
r = helm_template(config)
assert r['deployment'][name]['spec']['template']['spec']['tolerations'][0]['key'] == 'key1'
def test_adding_a_node_selector():
config = '''
nodeSelector:
disktype: ssd
'''
r = helm_template(config)
assert r['deployment'][name]['spec']['template']['spec']['nodeSelector']['disktype'] == 'ssd'
def test_adding_an_affinity_rule():
config = '''
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- kibana
topologyKey: kubernetes.io/hostname
'''
r = helm_template(config)
assert r['deployment'][name]['spec']['template']['spec']['affinity']['podAntiAffinity'][
'requiredDuringSchedulingIgnoredDuringExecution'][0]['topologyKey'] == 'kubernetes.io/hostname'
def test_adding_an_ingress_rule():
config = '''
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
path: /
hosts:
- kibana.elastic.co
tls:
- secretName: elastic-co-wildcard
hosts:
- kibana.elastic.co
'''
r = helm_template(config)
assert name in r['ingress']
i = r['ingress'][name]['spec']
assert i['tls'][0]['hosts'][0] == 'kibana.elastic.co'
assert i['tls'][0]['secretName'] == 'elastic-co-wildcard'
assert i['rules'][0]['host'] == 'kibana.elastic.co'
assert i['rules'][0]['http']['paths'][0]['path'] == '/'
assert i['rules'][0]['http']['paths'][0]['backend']['serviceName'] == name
assert i['rules'][0]['http']['paths'][0]['backend']['servicePort'] == 5601
def test_override_the_default_update_strategy():
config = '''
updateStrategy:
type: "RollingUpdate"
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
'''
r = helm_template(config)
assert r['deployment'][name]['spec']['strategy']['type'] == 'RollingUpdate'
assert r['deployment'][name]['spec']['strategy']['rollingUpdate']['maxUnavailable'] == 1
assert r['deployment'][name]['spec']['strategy']['rollingUpdate']['maxSurge'] == 1
def test_using_a_name_override():
config = '''
nameOverride: overrider
'''
r = helm_template(config)
assert 'overrider-kibana' in r['deployment']
def test_setting_a_custom_service_account():
config = '''
serviceAccount: notdefault
'''
r = helm_template(config)
assert r['deployment'][name]['spec']['template']['spec']['serviceAccount'] == 'notdefault'
def test_setting_pod_security_context():
config = '''
podSecurityContext:
runAsUser: 1001
fsGroup: 1002
'''
r = helm_template(config)
assert r['deployment'][name]['spec']['template']['spec']['securityContext']['runAsUser'] == 1001
assert r['deployment'][name]['spec']['template']['spec']['securityContext']['fsGroup'] == 1002
def test_adding_in_kibana_config():
config = '''
kibanaConfig:
kibana.yml: |
key:
nestedkey: value
dot.notation: test
other-config.yml: |
hello = world
'''
r = helm_template(config)
c = r['configmap'][name + '-config']['data']
assert 'kibana.yml' in c
assert 'other-config.yml' in c
assert 'nestedkey: value' in c['kibana.yml']
assert 'dot.notation: test' in c['kibana.yml']
assert 'hello = world' in c['other-config.yml']
d = r['deployment'][name]['spec']['template']['spec']
assert {'configMap': {'name': name + '-config'}, 'name': 'kibanaconfig'} in d['volumes']
assert {'mountPath': '/usr/share/kibana/config/kibana.yml', 'name': 'kibanaconfig', 'subPath': 'kibana.yml'} in d['containers'][0]['volumeMounts']
assert {'mountPath': '/usr/share/kibana/config/other-config.yml', 'name': 'kibanaconfig', 'subPath': 'other-config.yml'} in d['containers'][0]['volumeMounts']
assert 'configchecksum' in r['deployment'][name]['spec']['template']['metadata']['annotations']
def test_changing_the_protocol():
config = '''
protocol: https
'''
r = helm_template(config)
c = r['deployment'][name]['spec']['template']['spec']['containers'][0]
assert 'https://' in c['readinessProbe']['exec']['command'][-1]
def test_changing_the_health_check_path():
config = '''
healthCheckPath: "/kibana/app/kibana"
'''
r = helm_template(config)
c = r['deployment'][name]['spec']['template']['spec']['containers'][0]
assert 'http "/kibana/app/kibana"' in c['readinessProbe']['exec']['command'][-1]