Skip to content

Commit

Permalink
Set vttablet init container resource limits (#216)
Browse files Browse the repository at this point in the history
* Set resource limits on vttablet init containers

Signed-off-by: J. Brandt Buckley <brandt@runlevel1.com>

* Set default init container limits to same as vttablet

Signed-off-by: J. Brandt Buckley <brandt@runlevel1.com>

* Clarify resources in constants are defaults

Signed-off-by: J. Brandt Buckley <brandt@runlevel1.com>
  • Loading branch information
brandt committed Sep 14, 2021
1 parent 93fb53d commit be42288
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
23 changes: 23 additions & 0 deletions pkg/operator/vttablet/mysqlctld.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -47,6 +48,10 @@ for mycnf in $(find . -mindepth 2 -maxdepth 2 -path './vt_*/my.cnf'); do
sed -i -e 's,^socket[ \t]*=.*$,socket = ` + mysqlSocketPath + `,' "${mycnf}"
done
`

defaultInitCPURequestMillis = 100
defaultInitMemoryRequestBytes = 32 * (1 << 20) // 32 MiB
defaultInitMemoryLimitBytes = 128 * (1 << 20) // 128 MiB
)

func init() {
Expand Down Expand Up @@ -86,6 +91,15 @@ func init() {
},
Command: []string{"bash", "-c"},
Args: []string{vtRootInitScript},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewMilliQuantity(defaultInitCPURequestMillis, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(defaultInitMemoryRequestBytes, resource.BinarySI),
},
Limits: corev1.ResourceList{
corev1.ResourceMemory: *resource.NewQuantity(defaultInitMemoryLimitBytes, resource.BinarySI),
},
},
},
}

Expand All @@ -108,6 +122,15 @@ func init() {
},
Command: []string{"bash", "-c"},
Args: []string{mysqlSocketInitScript},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewMilliQuantity(defaultInitCPURequestMillis, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(defaultInitMemoryRequestBytes, resource.BinarySI),
},
Limits: corev1.ResourceList{
corev1.ResourceMemory: *resource.NewQuantity(defaultInitMemoryLimitBytes, resource.BinarySI),
},
},
})
}

Expand Down
11 changes: 10 additions & 1 deletion pkg/operator/vttablet/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,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{}
Expand Down

0 comments on commit be42288

Please sign in to comment.