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 vttablet init container resource limits #216

Merged
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
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 @@ -233,9 +233,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