From 381966c313ca5624b536a4cca75d27f0ceef1300 Mon Sep 17 00:00:00 2001 From: "J. Brandt Buckley" Date: Thu, 11 Feb 2021 17:10:45 -0700 Subject: [PATCH 1/3] Set resource limits on vttablet init containers Signed-off-by: J. Brandt Buckley --- pkg/operator/vttablet/mysqlctld.go | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/operator/vttablet/mysqlctld.go b/pkg/operator/vttablet/mysqlctld.go index 34bdc597..5fc9afdb 100644 --- a/pkg/operator/vttablet/mysqlctld.go +++ b/pkg/operator/vttablet/mysqlctld.go @@ -18,6 +18,7 @@ package vttablet import ( corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/utils/pointer" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" @@ -47,6 +48,12 @@ for mycnf in $(find . -mindepth 2 -maxdepth 2 -path './vt_*/my.cnf'); do sed -i -e 's,^socket[ \t]*=.*$,socket = ` + mysqlSocketPath + `,' "${mycnf}" done ` + + initCPURequestMillis = 100 + initCPULimitMillis = 500 + + initMemoryRequestBytes = 32 * (1 << 20) // 32 MiB + initMemoryLimitBytes = 128 * (1 << 20) // 128 MiB ) func init() { @@ -86,6 +93,18 @@ func init() { }, Command: []string{"bash", "-c"}, Args: []string{vtRootInitScript}, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: *resource.NewMilliQuantity(initCPURequestMillis, resource.DecimalSI), + corev1.ResourceMemory: *resource.NewQuantity(initMemoryRequestBytes, resource.BinarySI), + }, + // Set resource limits on init container for clusters that + // require it (e.g. when a limit is set in ResourceQuota) + Limits: corev1.ResourceList{ + corev1.ResourceCPU: *resource.NewMilliQuantity(initCPULimitMillis, resource.DecimalSI), + corev1.ResourceMemory: *resource.NewQuantity(initMemoryLimitBytes, resource.BinarySI), + }, + }, }, } @@ -108,6 +127,18 @@ func init() { }, Command: []string{"bash", "-c"}, Args: []string{mysqlSocketInitScript}, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: *resource.NewMilliQuantity(initCPURequestMillis, resource.DecimalSI), + corev1.ResourceMemory: *resource.NewQuantity(initMemoryRequestBytes, resource.BinarySI), + }, + // Set resource limits on init container for clusters that + // require it (e.g. when a limit is set in ResourceQuota) + Limits: corev1.ResourceList{ + corev1.ResourceCPU: *resource.NewMilliQuantity(initCPULimitMillis, resource.DecimalSI), + corev1.ResourceMemory: *resource.NewQuantity(initMemoryLimitBytes, resource.BinarySI), + }, + }, }) } From ae43893bde633418a76a8d0c1abbd6c3f06c53bb Mon Sep 17 00:00:00 2001 From: "J. Brandt Buckley" Date: Thu, 11 Feb 2021 18:18:04 -0700 Subject: [PATCH 2/3] Set default init container limits to same as vttablet Signed-off-by: J. Brandt Buckley --- pkg/operator/vttablet/mysqlctld.go | 10 +--------- pkg/operator/vttablet/pod.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/operator/vttablet/mysqlctld.go b/pkg/operator/vttablet/mysqlctld.go index 5fc9afdb..b043b680 100644 --- a/pkg/operator/vttablet/mysqlctld.go +++ b/pkg/operator/vttablet/mysqlctld.go @@ -49,9 +49,7 @@ for mycnf in $(find . -mindepth 2 -maxdepth 2 -path './vt_*/my.cnf'); do done ` - initCPURequestMillis = 100 - initCPULimitMillis = 500 - + initCPURequestMillis = 100 initMemoryRequestBytes = 32 * (1 << 20) // 32 MiB initMemoryLimitBytes = 128 * (1 << 20) // 128 MiB ) @@ -98,10 +96,7 @@ func init() { corev1.ResourceCPU: *resource.NewMilliQuantity(initCPURequestMillis, resource.DecimalSI), corev1.ResourceMemory: *resource.NewQuantity(initMemoryRequestBytes, resource.BinarySI), }, - // Set resource limits on init container for clusters that - // require it (e.g. when a limit is set in ResourceQuota) Limits: corev1.ResourceList{ - corev1.ResourceCPU: *resource.NewMilliQuantity(initCPULimitMillis, resource.DecimalSI), corev1.ResourceMemory: *resource.NewQuantity(initMemoryLimitBytes, resource.BinarySI), }, }, @@ -132,10 +127,7 @@ func init() { corev1.ResourceCPU: *resource.NewMilliQuantity(initCPURequestMillis, resource.DecimalSI), corev1.ResourceMemory: *resource.NewQuantity(initMemoryRequestBytes, resource.BinarySI), }, - // Set resource limits on init container for clusters that - // require it (e.g. when a limit is set in ResourceQuota) Limits: corev1.ResourceList{ - corev1.ResourceCPU: *resource.NewMilliQuantity(initCPULimitMillis, resource.DecimalSI), corev1.ResourceMemory: *resource.NewQuantity(initMemoryLimitBytes, resource.BinarySI), }, }, diff --git a/pkg/operator/vttablet/pod.go b/pkg/operator/vttablet/pod.go index 2378f755..1e55e594 100644 --- a/pkg/operator/vttablet/pod.go +++ b/pkg/operator/vttablet/pod.go @@ -230,9 +230,18 @@ func UpdatePod(obj *corev1.Pod, spec *Spec) { } } + // Set the resource requirements on each of the default vttablet init + // containers to the same values as the vttablet container itself in + // case the cluster requires them. + defaultTabletInitContainers := tabletInitContainers.Get(spec) + for i := range defaultTabletInitContainers { + c := &defaultTabletInitContainers[i] + update.ResourceRequirements(&c.Resources, &spec.Vttablet.Resources) + } + // Make the final list of desired containers and init containers. initContainers := []corev1.Container{} - initContainers = append(initContainers, tabletInitContainers.Get(spec)...) + initContainers = append(initContainers, defaultTabletInitContainers...) initContainers = append(initContainers, spec.InitContainers...) sidecarContainers := []corev1.Container{} From ada9fe12ab89319df7acc7e1e743799da7b8beb7 Mon Sep 17 00:00:00 2001 From: "J. Brandt Buckley" Date: Thu, 11 Feb 2021 18:22:30 -0700 Subject: [PATCH 3/3] Clarify resources in constants are defaults Signed-off-by: J. Brandt Buckley --- pkg/operator/vttablet/mysqlctld.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/operator/vttablet/mysqlctld.go b/pkg/operator/vttablet/mysqlctld.go index b043b680..fe39053f 100644 --- a/pkg/operator/vttablet/mysqlctld.go +++ b/pkg/operator/vttablet/mysqlctld.go @@ -49,9 +49,9 @@ for mycnf in $(find . -mindepth 2 -maxdepth 2 -path './vt_*/my.cnf'); do done ` - initCPURequestMillis = 100 - initMemoryRequestBytes = 32 * (1 << 20) // 32 MiB - initMemoryLimitBytes = 128 * (1 << 20) // 128 MiB + defaultInitCPURequestMillis = 100 + defaultInitMemoryRequestBytes = 32 * (1 << 20) // 32 MiB + defaultInitMemoryLimitBytes = 128 * (1 << 20) // 128 MiB ) func init() { @@ -93,11 +93,11 @@ func init() { Args: []string{vtRootInitScript}, Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ - corev1.ResourceCPU: *resource.NewMilliQuantity(initCPURequestMillis, resource.DecimalSI), - corev1.ResourceMemory: *resource.NewQuantity(initMemoryRequestBytes, resource.BinarySI), + corev1.ResourceCPU: *resource.NewMilliQuantity(defaultInitCPURequestMillis, resource.DecimalSI), + corev1.ResourceMemory: *resource.NewQuantity(defaultInitMemoryRequestBytes, resource.BinarySI), }, Limits: corev1.ResourceList{ - corev1.ResourceMemory: *resource.NewQuantity(initMemoryLimitBytes, resource.BinarySI), + corev1.ResourceMemory: *resource.NewQuantity(defaultInitMemoryLimitBytes, resource.BinarySI), }, }, }, @@ -124,11 +124,11 @@ func init() { Args: []string{mysqlSocketInitScript}, Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ - corev1.ResourceCPU: *resource.NewMilliQuantity(initCPURequestMillis, resource.DecimalSI), - corev1.ResourceMemory: *resource.NewQuantity(initMemoryRequestBytes, resource.BinarySI), + corev1.ResourceCPU: *resource.NewMilliQuantity(defaultInitCPURequestMillis, resource.DecimalSI), + corev1.ResourceMemory: *resource.NewQuantity(defaultInitMemoryRequestBytes, resource.BinarySI), }, Limits: corev1.ResourceList{ - corev1.ResourceMemory: *resource.NewQuantity(initMemoryLimitBytes, resource.BinarySI), + corev1.ResourceMemory: *resource.NewQuantity(defaultInitMemoryLimitBytes, resource.BinarySI), }, }, })