Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Kibana default memory requests and limits to 1Gi #1818

Merged
merged 1 commit into from Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/controller/kibana/driver_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -311,6 +312,7 @@ func expectedDeploymentParams() *DeploymentParams {
},
},
},
Resources: pod.DefaultResources,
}},
AutomountServiceAccountToken: &false,
},
Expand Down
12 changes: 12 additions & 0 deletions pkg/controller/kibana/pod/pod.go
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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())).
Expand Down
39 changes: 39 additions & 0 deletions pkg/controller/kibana/pod/pod_test.go
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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{
Expand Down