Skip to content

Commit

Permalink
[Development][Add] Added plugins support for elasticsearch (#42)
Browse files Browse the repository at this point in the history
* Added plugins support for elasticsearch

Signed-off-by: iamabhishek-dubey <[email protected]>

* Updated version of operator

Signed-off-by: iamabhishek-dubey <[email protected]>

* Added examples for elasticsearch plugin

Signed-off-by: iamabhishek-dubey <[email protected]>

* Fixed code for plugin installation

Signed-off-by: iamabhishek-dubey <[email protected]>

* Changed plugin installation architecture

Signed-off-by: iamabhishek-dubey <[email protected]>

* Changed plugin installation architecture

Signed-off-by: iamabhishek-dubey <[email protected]>

Signed-off-by: iamabhishek-dubey <[email protected]>
  • Loading branch information
iamabhishek-dubey authored Sep 2, 2022
1 parent 6f1f2c8 commit c1a2a62
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= v0.3.2
VERSION ?= v0.4.0

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/elasticsearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ElasticsearchSpec struct {
ESData *NodeSpecificConfig `json:"esData,omitempty"`
ESIngestion *NodeSpecificConfig `json:"esIngestion,omitempty"`
ESClient *NodeSpecificConfig `json:"esClient,omitempty"`
ESPlugins *[]string `json:"esPlugins,omitempty"`
}

// NodeSpecificConfig defines the properties for elasticsearch nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4826,6 +4826,10 @@ spec:
type: string
type: object
type: object
esPlugins:
items:
type: string
type: array
esSecurity:
description: Security defines the security config of Elasticsearch
properties:
Expand Down
9 changes: 9 additions & 0 deletions examples/elasticsearch/plugins/elasticsearch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: logging.logging.opstreelabs.in/v1beta1
kind: Elasticsearch
metadata:
name: elasticsearch
spec:
esClusterName: "prod"
esVersion: "7.16.0"
esPlugins: ["repository-s3"]
17 changes: 17 additions & 0 deletions k8sgo/elasticsearch/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func CreateElasticsearchStatefulSet(cr *loggingv1beta1.Elasticsearch, nodeConfig
if nodeConfig.Replicas != nil {
statefulsetParams.Replicas = nodeConfig.Replicas
}
if cr.Spec.ESPlugins != nil {
statefulsetParams.ESPlugins = cr.Spec.ESPlugins
}
statefulsetParams.ExtraVolumes = getVolumes(cr)

if nodeConfig != nil {
Expand Down Expand Up @@ -110,6 +113,12 @@ func getVolumeMounts(cr *loggingv1beta1.Elasticsearch, role string) *[]corev1.Vo
})
}
}
if cr.Spec.ESPlugins != nil {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "plugin-volume",
MountPath: "/usr/share/elasticsearch/plugins",
})
}
return &volumeMounts
}

Expand All @@ -128,6 +137,14 @@ func getVolumes(cr *loggingv1beta1.Elasticsearch) *[]corev1.Volume {
})
}
}
if cr.Spec.ESPlugins != nil {
volume = append(volume, corev1.Volume{
Name: "plugin-volume",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
})
}
return &volume
}

Expand Down
25 changes: 25 additions & 0 deletions k8sgo/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package k8sgo

import (
"context"
"strings"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -44,6 +45,7 @@ type StatefulSetParameters struct {
PriorityClassName *string
SecurityContext *corev1.PodSecurityContext
ExtraVolumes *[]corev1.Volume
ESPlugins *[]string
}

// PVCParameters is a struct to pass arguments for PVC
Expand Down Expand Up @@ -181,6 +183,9 @@ func generateStatefulSetDef(params StatefulSetParameters) *appsv1.StatefulSet {
},
}

if params.ESPlugins != nil {
statefulset.Spec.Template.Spec.InitContainers = append(statefulset.Spec.Template.Spec.InitContainers, getPluginInitContainers(params))
}
if params.ExtraVolumes != nil {
statefulset.Spec.Template.Spec.Volumes = *params.ExtraVolumes
}
Expand Down Expand Up @@ -226,3 +231,23 @@ func getInitContainer(params ContainerParams) corev1.Container {
},
}
}

// getPluginInitContainers is a method to create plugins init container
func getPluginInitContainers(params StatefulSetParameters) corev1.Container {
shellCommand := []string{"sh", "-c"}
command := []string{"bin/elasticsearch-plugin install --batch"}
command = append(command, *params.ESPlugins...)

shellCommand = append(shellCommand, strings.Join(command, " "))
return corev1.Container{
Name: "plugins",
Image: params.ContainerParams.Image,
Command: shellCommand,
VolumeMounts: []corev1.VolumeMount{
{
Name: "plugin-volume",
MountPath: "/usr/share/elasticsearch/plugins",
},
},
}
}

0 comments on commit c1a2a62

Please sign in to comment.