From 3ff57f1c04871b641fd5812f8b20bf185080898f Mon Sep 17 00:00:00 2001 From: sebgl Date: Fri, 27 Sep 2019 15:14:44 +0200 Subject: [PATCH] Set a default 1Gi memory requests and limits for Kibana Similar to Elasticsearch and APM, set a default value for Kibana requests and limits. The value is set to 1Gi. --- pkg/controller/kibana/driver_test.go | 2 ++ pkg/controller/kibana/pod/pod.go | 12 +++++++++ pkg/controller/kibana/pod/pod_test.go | 39 +++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/pkg/controller/kibana/driver_test.go b/pkg/controller/kibana/driver_test.go index a09e84330f..76306db63e 100644 --- a/pkg/controller/kibana/driver_test.go +++ b/pkg/controller/kibana/driver_test.go @@ -13,6 +13,7 @@ import ( "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/pod" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/volume" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/assert" @@ -311,6 +312,7 @@ func expectedDeploymentParams() *DeploymentParams { }, }, }, + Resources: pod.DefaultResources, }}, AutomountServiceAccountToken: &false, }, diff --git a/pkg/controller/kibana/pod/pod.go b/pkg/controller/kibana/pod/pod.go index 56eee7140e..ad20bc9e82 100644 --- a/pkg/controller/kibana/pod/pod.go +++ b/pkg/controller/kibana/pod/pod.go @@ -5,6 +5,8 @@ package pod import ( + "k8s.io/apimachinery/pkg/api/resource" + "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1alpha1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore" @@ -28,6 +30,15 @@ var ports = []corev1.ContainerPort{ {Name: "http", ContainerPort: int32(HTTPPort), Protocol: corev1.ProtocolTCP}, } +var DefaultResources = corev1.ResourceRequirements{ + Requests: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("1Gi"), + }, + Limits: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("1Gi"), + }, +} + // readinessProbe is the readiness probe for the Kibana container func readinessProbe(useTLS bool) corev1.Probe { scheme := corev1.URISchemeHTTP @@ -56,6 +67,7 @@ func imageWithVersion(image string, version string) string { func NewPodTemplateSpec(kb v1alpha1.Kibana, keystore *keystore.Resources) corev1.PodTemplateSpec { builder := defaults.NewPodTemplateBuilder(kb.Spec.PodTemplate, v1alpha1.KibanaContainerName). + WithResources(DefaultResources). WithLabels(label.NewLabels(kb.Name)). WithDockerImage(kb.Spec.Image, imageWithVersion(defaultImageRepositoryAndName, kb.Spec.Version)). WithReadinessProbe(readinessProbe(kb.Spec.HTTP.TLS.Enabled())). diff --git a/pkg/controller/kibana/pod/pod_test.go b/pkg/controller/kibana/pod/pod_test.go index 6b09172848..2494a24188 100644 --- a/pkg/controller/kibana/pod/pod_test.go +++ b/pkg/controller/kibana/pod/pod_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -98,6 +99,44 @@ func TestNewPodTemplateSpec(t *testing.T) { assert.Equal(t, "my-custom-image:1.0.0", GetKibanaContainer(pod.Spec).Image) }, }, + { + name: "with default resources", + kb: v1alpha1.Kibana{Spec: v1alpha1.KibanaSpec{ + Version: "7.1.0", + }}, + keystore: nil, + assertions: func(pod corev1.PodTemplateSpec) { + assert.Equal(t, DefaultResources, GetKibanaContainer(pod.Spec).Resources) + }, + }, + { + name: "with user-provided resources", + kb: v1alpha1.Kibana{Spec: v1alpha1.KibanaSpec{ + Version: "7.1.0", + PodTemplate: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: v1alpha1.KibanaContainerName, + Resources: corev1.ResourceRequirements{ + Limits: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("3Gi"), + }, + }, + }, + }, + }, + }, + }}, + keystore: nil, + assertions: func(pod corev1.PodTemplateSpec) { + assert.Equal(t, corev1.ResourceRequirements{ + Limits: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceMemory: resource.MustParse("3Gi"), + }, + }, GetKibanaContainer(pod.Spec).Resources) + }, + }, { name: "with user-provided init containers", kb: v1alpha1.Kibana{Spec: v1alpha1.KibanaSpec{