Skip to content

Commit

Permalink
Upgrade the default resource settings for Elastic
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-dekker committed Jun 22, 2020
1 parent d19b67d commit b43b0f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
26 changes: 9 additions & 17 deletions pkg/render/logstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,33 +343,25 @@ func (es elasticsearchComponent) pvcTemplate() corev1.PersistentVolumeClaim {

// Generate the pod template required for the ElasticSearch nodes (controls the ElasticSearch container)
func (es elasticsearchComponent) podTemplate() corev1.PodTemplateSpec {
// Setup default configuration for ES container
// Setup default configuration for ES container. For more information on managing resources, see:
// https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-managing-compute-resources.html and
// https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-jvm-heap-size.html#k8s-jvm-heap-size

esContainer := corev1.Container{
Name: "elasticsearch",
// Important note: Following Elastic ECK docs, the recommended practice is to set
// request and limit for memory to the same value:
// https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-managing-compute-resources.html#k8s-compute-resources-elasticsearch
//
// Default values for memory request and limit taken from ECK docs:
// https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-managing-compute-resources.html#k8s-default-behavior
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
"cpu": resource.MustParse("1"),
"memory": resource.MustParse("2Gi"),
"memory": resource.MustParse("4Gi"),
},
Requests: corev1.ResourceList{
"cpu": resource.MustParse("1"),
"memory": resource.MustParse("2Gi"),
"cpu": resource.MustParse("250m"),
"memory": resource.MustParse("4Gi"),
},
},
Env: []corev1.EnvVar{
// Important note: Following Elastic ECK docs, the recommendation is to set
// the Java heap size to half the size of RAM allocated to the Pod:
// https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-managing-compute-resources.html#k8s-compute-resources-elasticsearch
//
// Default values for Java Heap min and max taken from ECK docs:
// https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-jvm-heap-size.html#k8s-jvm-heap-size
{Name: "ES_JAVA_OPTS", Value: "-Xms1G -Xmx1G"},
// Set to 30% of the default memory, such that resources can be divided over ES, Lucene and ML.
{Name: "ES_JAVA_OPTS", Value: "-Xms1398101K -Xmx1398101K"},
},
}

Expand Down
28 changes: 15 additions & 13 deletions pkg/render/logstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,22 @@ var _ = Describe("Elasticsearch rendering tests", func() {
compareResources(createResources, expectedCreateResources)
compareResources(deleteResources, []resourceTestObj{})

resultES := GetResource(createResources, render.ElasticsearchName, render.ElasticsearchNamespace,
"elasticsearch.k8s.elastic.co", "v1", "Elasticsearch").(*esv1.Elasticsearch)

// There are no node selectors in the LogStorage CR, so we expect no node selectors in the Elasticsearch CR.
Expect(createResources[15].(*esv1.Elasticsearch).Spec.NodeSets[0].PodTemplate.Spec.NodeSelector).To(BeEmpty())
Expect(resultES.Spec.NodeSets[0].PodTemplate.Spec.NodeSelector).To(BeEmpty())

// Verify that the default container limist/requests are set.
esContainer := resultES.Spec.NodeSets[0].PodTemplate.Spec.Containers[0]
limits := esContainer.Resources.Limits
resources := esContainer.Resources.Requests

Expect(limits.Cpu().String()).To(Equal("1"))
Expect(limits.Memory().String()).To(Equal("4Gi"))
Expect(resources.Cpu().String()).To(Equal("250m"))
Expect(resources.Memory().String()).To(Equal("4Gi"))
Expect(esContainer.Env[0].Value).To(Equal("-Xms1398101K -Xmx1398101K"))
})
It("should render an elasticsearchComponent and delete the Elasticsearch and Kibana ExternalService", func() {
expectedCreateResources := []resourceTestObj{
Expand Down Expand Up @@ -288,18 +302,6 @@ var _ = Describe("Elasticsearch rendering tests", func() {
},
},
},
Indices: &operator.Indices{
Replicas: &replicas,
},
Retention: &operatorv1.Retention{
Flows: &retention,
AuditReports: &retention,
Snapshots: &retention,
ComplianceReports: &retention,
},
},
Status: operator.LogStorageStatus{
State: "",
},
}

Expand Down

0 comments on commit b43b0f9

Please sign in to comment.