-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add default index config kibana (#1993)
* add default index config kibana * move template to kibana chart * fix pre-commit * add support for vector pattern * Update charts/kibana/templates/kibana-default-index-cronjob.yaml Co-authored-by: Daniel Hoherd <daniel.hoherd@gmail.com> * fix pre-commit * Update charts/kibana/templates/kibana-default-index-cronjob.yaml Co-authored-by: Daniel Hoherd <daniel.hoherd@gmail.com> * add network policy for index job * add testcases * update kibana index image to ap-init * update job template * fix pull secret template * fix tests * fix pre-commit * fix pre-commit * add functional test for kibana index pod * add namespace * add feature flag for create default index --------- Co-authored-by: Daniel Hoherd <daniel.hoherd@gmail.com>
- Loading branch information
1 parent
3e83899
commit c7ad09c
Showing
9 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
######################################## | ||
# Kibana default index helm hook | ||
######################################## | ||
{{ if .Values.createDefaultIndex }} | ||
apiVersion: {{ include "apiVersion.batch.cronjob" . }} | ||
kind: Job | ||
metadata: | ||
name: {{ template "kibana.fullname" . }}-default-index | ||
labels: | ||
tier: logging | ||
component: kibana-default-index | ||
chart: {{ template "kibana.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
annotations: | ||
# This is what defines this resource as a hook. Without this line, the | ||
# job is considered part of the release. | ||
"helm.sh/hook": post-upgrade,post-install | ||
"helm.sh/hook-weight": "1" | ||
"helm.sh/hook-delete-policy": before-hook-creation | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
tier: logging | ||
component: kibana-default-index | ||
release: {{ .Release.Name }} | ||
app: kibana-default-index | ||
version: {{ .Chart.Version }} | ||
spec: | ||
{{- include "kibana.imagePullSecrets" . | indent 8 }} | ||
containers: | ||
- name: kibana-default-index | ||
image: {{ template "kibana.init.image" . }} | ||
imagePullPolicy: {{ .Values.images.init.pullPolicy }} | ||
resources: {{ toYaml .Values.resources | nindent 12 }} | ||
command: | ||
- "/bin/sh" | ||
- -ec | ||
- | | ||
http_status=$(curl --retry 10 --retry-delay 30 --retry-all-errors -s -o /dev/null -w "%{http_code}" -XGET http://{{ .Release.Name }}-kibana:5601/api/data_views/data_view/{{ template "kibana.IndexPattern" . }}.*) | ||
if [[ "$http_status" -eq 200 ]]; then | ||
echo "Kibana Index Pattern Already Exists. Skipping Creation" | ||
else | ||
echo "Creating Kibana Index Pattern" | ||
curl --retry 10 --retry-delay 30 --retry-all-errors -XPOST -H 'Content-Type: application/json' -H 'kbn-xsrf: astronomer' --data '{"attributes":{"title":"{{ template "kibana.IndexPattern" . }}.*","timeFieldName":"@timestamp"}}' http://{{ .Release.Name }}-kibana:5601/api/saved_objects/index-pattern/{{ template "kibana.IndexPattern" . }}.*?overwrite=false | ||
fi | ||
restartPolicy: Never | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pytest | ||
|
||
from tests import supported_k8s_versions | ||
from tests.chart_tests.helm_template_generator import render_chart | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"kube_version", | ||
supported_k8s_versions, | ||
) | ||
class TestKibana: | ||
def test_kibana_index_defaults(self, kube_version): | ||
"""Test kibana Service with index defaults.""" | ||
docs = render_chart( | ||
kube_version=kube_version, | ||
values={}, | ||
show_only=[ | ||
"charts/kibana/templates/kibana-default-index-cronjob.yaml", | ||
], | ||
) | ||
assert len(docs) == 1 | ||
doc = docs[0] | ||
assert doc["kind"] == "Job" | ||
assert doc["apiVersion"] == "batch/v1" | ||
assert doc["metadata"]["name"] == "release-name-kibana-default-index" | ||
assert ( | ||
"fluentd.*" | ||
in doc["spec"]["template"]["spec"]["containers"][0]["command"][2] | ||
) | ||
|
||
def test_kibana_index_with_logging_sidecar(self, kube_version): | ||
"""Test kibana Service with logging sidecar index.""" | ||
docs = render_chart( | ||
kube_version=kube_version, | ||
values={"global": {"loggingSidecar": {"enabled": True}}}, | ||
show_only=[ | ||
"charts/kibana/templates/kibana-default-index-cronjob.yaml", | ||
], | ||
) | ||
|
||
assert len(docs) == 1 | ||
doc = docs[0] | ||
assert doc["kind"] == "Job" | ||
assert doc["apiVersion"] == "batch/v1" | ||
assert doc["metadata"]["name"] == "release-name-kibana-default-index" | ||
assert ( | ||
"vector.*" in doc["spec"]["template"]["spec"]["containers"][0]["command"][2] | ||
) | ||
|
||
def test_kibana_index_disabled(self, kube_version): | ||
"""Test kibana Service with index creation disabled.""" | ||
docs = render_chart( | ||
kube_version=kube_version, | ||
values={"kibana": {"createDefaultIndex": False}}, | ||
show_only=[ | ||
"charts/kibana/templates/kibana-default-index-cronjob.yaml", | ||
], | ||
) | ||
|
||
assert len(docs) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters