Skip to content

Commit

Permalink
Set vttablet init container resource requests and limits (#370)
Browse files Browse the repository at this point in the history
* Set vttablet init container resource requests and limits

Sets the resource requirements on each of the default vttablet init containers to the same request and limit values as the vttablet container itself.

This fixes the issue reported in #212 where pods would fail to be created on clusters with strict quota requirements because no limit was set on the init containers.

## History

This is a reimplementation of #216 with the change that it no longer sets a default resource _limit_.

This fixes the issue reported in #240 and discussed in #244 where the vttablet pod would fail to be created when the user sets a request larger than the default limit without also setting a larger limit. The user's nil limit would not override the default value because `update.ResourceRequirements(dst, src)` won't update `dst` with a nil `src` ([for good reasons](https://github.com/planetscale/vitess-operator/blob/da7efd4c945193864f5996cb793055449c4de97a/pkg/operator/update/podspec.go#L201-L203)).

With this change, users can once again increase the request by itself. If a cluster requires a limit, the user will already need to have set it on for vttablet so we can use the same value to override the init containers' default nil limit.

fixes #212
fixes #240

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

* refactor: move defaults to the correct location

Signed-off-by: Manan Gupta <manan@planetscale.com>

---------

Signed-off-by: J. Brandt Buckley <brandt@runlevel1.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Co-authored-by: J. Brandt Buckley <brandt@runlevel1.com>
  • Loading branch information
GuptaManan100 and brandt committed Feb 2, 2023
1 parent 8ac7bcb commit 9c0e6a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/apis/planetscale/v2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 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 @@ -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),
},
},
},
}

Expand All @@ -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),
},
},
})
}

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 9c0e6a8

Please sign in to comment.