Skip to content

Commit

Permalink
fix elasticsearch for kube version 1.24+
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEsL committed Sep 4, 2024
1 parent f645027 commit 7d280a1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
9 changes: 9 additions & 0 deletions pkg/dbs/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ func esCluster() []*desired.State {
Own: true,
Updatable: true,
},
{
TemplatePath: path + "/es/sts-job.tpl",
Template: nil,
ParsedTemplate: "",
Obj: &unstructured.Unstructured{},
GVK: desired.Kinds[desired.JobGVK],
Own: true,
Updatable: true,
},
{
TemplatePath: path + "/es/svc-headless.tpl",
Template: nil,
Expand Down
2 changes: 1 addition & 1 deletion pkg/dbs/tmpl/es/sts-cluster-cm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ metadata:
data:
elastic_cleanup.sh: |+
#!/bin/bash
ES_URL=http://localhost:9200
ES_URL=http://elasticsearch:9200
while [[ "$(curl -u "elastic:${CNVRG_ES_PASS}" -s -o /dev/null -w '%{http_code}\n' $ES_URL)" != "200" ]]; do sleep 2; done
while [[ "$(curl -X PUT -u "elastic:${CNVRG_ES_PASS}" "${ES_URL}/_security/user/${CNVRG_ES_USER}?pretty" -H 'Content-Type: application/json' -d "{ \"password\" : \"${CNVRG_ES_PASS}\", \"roles\" : [ \"superuser\" ] }" -s -o /dev/null -w '%{http_code}\n')" != "200" ]]; do sleep 2; done
curl -X PUT -u "${CNVRG_ES_USER}:${CNVRG_ES_PASS}" "${ES_URL}/_ilm/policy/cleanup_policy_app?pretty" -H 'Content-Type: application/json' -d '{ "policy": { "phases": { "hot": { "actions": {} }, "delete": { "min_age": "30d", "actions": { "delete": {} } } } } }'
Expand Down
17 changes: 1 addition & 16 deletions pkg/dbs/tmpl/es/sts-cluster.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ spec:
topologyKey: kubernetes.io/hostname
weight: 1
volumes:
- name: es-ilm
configMap:
name: "es-ilm"
defaultMode: 0755
- name: {{ .Spec.Dbs.Es.ServiceAccount }}-certs
secret:
secretName: {{ .Spec.Dbs.Es.ServiceAccount }}-certs
Expand Down Expand Up @@ -160,8 +156,6 @@ spec:
envFrom:
- secretRef:
name: {{ .Spec.Dbs.Es.CredsRef }}
- configMapRef:
name: es-ilm-cm
ports:
- name: http
containerPort: {{ .Spec.Dbs.Es.Port }}
Expand Down Expand Up @@ -238,18 +232,9 @@ spec:
periodSeconds: 10
successThreshold: 3
timeoutSeconds: 5
lifecycle:
postStart:
exec:
command:
- /bin/bash
- -c
- /tmp/elastic/elastic_cleanup.sh&
volumeMounts:
- name: {{ .Spec.Dbs.Es.PvcName }}
mountPath: "/usr/share/elasticsearch/data"
- name: {{ .Spec.Dbs.Es.ServiceAccount }}-certs
mountPath: /usr/share/elasticsearch/config/certs
readOnly: true
- name: es-ilm
mountPath: "/tmp/elastic/"
readOnly: true
35 changes: 35 additions & 0 deletions pkg/dbs/tmpl/es/sts-job.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: batch/v1
kind: Job
metadata:
name: run-elasticsearch-script
namespace: {{ ns . }}
annotations:
{{- range $k, $v := .Spec.Annotations }}
{{$k}}: "{{$v}}"
{{- end }}
labels:
app: {{ .Spec.Dbs.Es.SvcName }}
{{- range $k, $v := .Spec.Labels }}
{{$k}}: "{{$v}}"
{{- end }}
spec:
template:
spec:
containers:
- name: script-runner
image: byrnedo/alpine-curl:3.19
command: ["sh", "/tmp/elastic/elastic_cleanup.sh"]
envFrom:
- secretRef:
name: {{ .Spec.Dbs.Es.CredsRef }}
- configMapRef:
name: es-ilm-cm
volumeMounts:
- name: es-ilm
mountPath: "/tmp/elastic/"
volumes:
- name: es-ilm
configMap:
name: "es-ilm"
defaultMode: 0755

0 comments on commit 7d280a1

Please sign in to comment.