diff --git a/pkg/apis/planetscale/v2/defaults.go b/pkg/apis/planetscale/v2/defaults.go index 1c93ee37..66386b94 100644 --- a/pkg/apis/planetscale/v2/defaults.go +++ b/pkg/apis/planetscale/v2/defaults.go @@ -103,6 +103,9 @@ const ( DefaultMysqlPortName = "mysql" defaultVitessLiteImage = "vitess/lite:latest" + + DefaultInitCPURequestMillis = 100 + DefaultInitMemoryRequestBytes = 32 * (1 << 20) // 32 MiB ) // DefaultImages are a set of images to use when the CRD doesn't specify. diff --git a/pkg/operator/vttablet/mysqlctld.go b/pkg/operator/vttablet/mysqlctld.go index 34bdc597..442aaf6d 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" @@ -86,6 +87,12 @@ func init() { }, Command: []string{"bash", "-c"}, Args: []string{vtRootInitScript}, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: *resource.NewMilliQuantity(planetscalev2.DefaultInitCPURequestMillis, resource.DecimalSI), + corev1.ResourceMemory: *resource.NewQuantity(planetscalev2.DefaultInitMemoryRequestBytes, resource.BinarySI), + }, + }, }, } @@ -108,6 +115,12 @@ func init() { }, Command: []string{"bash", "-c"}, Args: []string{mysqlSocketInitScript}, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: *resource.NewMilliQuantity(planetscalev2.DefaultInitCPURequestMillis, resource.DecimalSI), + corev1.ResourceMemory: *resource.NewQuantity(planetscalev2.DefaultInitMemoryRequestBytes, resource.BinarySI), + }, + }, }) } diff --git a/pkg/operator/vttablet/pod.go b/pkg/operator/vttablet/pod.go index c86f3c14..e408baa7 100644 --- a/pkg/operator/vttablet/pod.go +++ b/pkg/operator/vttablet/pod.go @@ -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{}