Skip to content

Commit c4135e6

Browse files
committed
Set resources limit for all containers
As a good practice we should set resource limits on each container sf-operator deploys. Without them, containers are not constrained in CPU and MEM usage. Furthermore some cluster force the use of a LimitRange resource for a namespace and this applies the same set of default values on every container whatever it is. https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ https://kubernetes.io/docs/concepts/policy/limit-range/ So with this change: - All containers get a default Resources Limit which is (request.mem: 128Mi, request.cpu: 100m, limit.mem: 256Mi, limit.cpu: 500m) - git-server - remove the nodepexporter container because the volume is not supposed to increase in size as we are (control plan) on control of the content stored into that storage - git-server - Add probes - Add a SetContainerLimitsLowProfile function used to set low limits for sidecar or init containers when it seems to make sense. - Add a SetContainerLimitsHighProfile function used to set limits for containers that require more resources. - Update CRD to add a LimitsSpec for MariaDB, Zookeeper, Nodepool launcher and builder, Zuul web, scheduler, executor, merger. This allows to customize the limits. TODO: Add in documentation the constraints about the requests/and limits. Change-Id: I743d38b09a0ba830511c56558f75d083272d3450
1 parent 62245ae commit c4135e6

17 files changed

+493
-35
lines changed

api/v1/softwarefactory_types.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ type ZuulExecutorSpec struct {
257257
// When set the Control plane is not deployed.
258258
// The standalone executor must be able to connect to the control plane
259259
Standalone *StandaloneZuulExecutorSpec `json:"standalone,omitempty"`
260+
// Memory/CPU Limit
261+
// +kubebuilder:validation:Optional
262+
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
263+
Limits *LimitsSpec `json:"limits"`
260264
}
261265

262266
type ZuulWebSpec struct {
@@ -268,6 +272,10 @@ type ZuulWebSpec struct {
268272
// Changing this value will restart the service.
269273
// +optional
270274
LogLevel LogLevel `json:"logLevel,omitempty"`
275+
// Memory/CPU Limit
276+
// +kubebuilder:validation:Optional
277+
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
278+
Limits *LimitsSpec `json:"limits"`
271279
}
272280

273281
// Spec for the scheduler microservice
@@ -284,6 +292,10 @@ type ZuulSchedulerSpec struct {
284292
// Changing this value will restart the service.
285293
// +optional
286294
LogLevel LogLevel `json:"logLevel,omitempty"`
295+
// Memory/CPU Limit
296+
// +kubebuilder:validation:Optional
297+
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
298+
Limits *LimitsSpec `json:"limits"`
287299
}
288300

289301
// Zuul Merger Configuration, see [Zuul's documentation](https://zuul-ci.org/docs/zuul/latest/configuration.html#merger)
@@ -313,6 +325,10 @@ type ZuulMergerSpec struct {
313325
// Changing this value will restart the service.
314326
// +optional
315327
LogLevel LogLevel `json:"logLevel,omitempty"`
328+
// Memory/CPU Limit
329+
// +kubebuilder:validation:Optional
330+
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
331+
Limits *LimitsSpec `json:"limits"`
316332
}
317333

318334
// TODO: make sure to update the GetConnectionsName when adding new connection type.
@@ -435,6 +451,10 @@ type NodepoolLauncherSpec struct {
435451
// Changing this value will restart the service.
436452
// +optional
437453
LogLevel LogLevel `json:"logLevel,omitempty"`
454+
// Memory/CPU Limit
455+
// +kubebuilder:validation:Optional
456+
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
457+
Limits *LimitsSpec `json:"limits"`
438458
}
439459

440460
type NodepoolBuilderSpec struct {
@@ -446,6 +466,10 @@ type NodepoolBuilderSpec struct {
446466
// "WARN",
447467
// "DEBUG".
448468
LogLevel LogLevel `json:"logLevel,omitempty"`
469+
// Memory/CPU Limit
470+
// +kubebuilder:validation:Optional
471+
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
472+
Limits *LimitsSpec `json:"limits"`
449473
}
450474

451475
type NodepoolSpec struct {
@@ -459,13 +483,28 @@ type NodepoolSpec struct {
459483

460484
type ZookeeperSpec struct {
461485
Storage StorageSpec `json:"storage"`
486+
// Memory/CPU Limit
487+
// +kubebuilder:validation:Optional
488+
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
489+
Limits *LimitsSpec `json:"limits"`
490+
}
491+
492+
type LimitsSpec struct {
493+
// +kubebuilder:default:="2Gi"
494+
Memory resource.Quantity `json:"memory"`
495+
// +kubebuilder:default:="2000m"
496+
CPU resource.Quantity `json:"cpu"`
462497
}
463498

464499
type MariaDBSpec struct {
465500
// Storage parameters related to mariaDB's data
466501
DBStorage StorageSpec `json:"dbStorage"`
467502
// Storage parameters related to the database's logging
468503
LogStorage StorageSpec `json:"logStorage"`
504+
// Memory/CPU Limit
505+
// +kubebuilder:validation:Optional
506+
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
507+
Limits *LimitsSpec `json:"limits"`
469508
}
470509

471510
type GitServerSpec struct {

api/v1/zz_generated.deepcopy.go

Lines changed: 59 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cmd/dev/gerrit/gerrit.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
batchv1 "k8s.io/api/batch/v1"
3838
apiv1 "k8s.io/api/core/v1"
3939
apierrors "k8s.io/apimachinery/pkg/api/errors"
40+
"k8s.io/apimachinery/pkg/api/resource"
4041

4142
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4243
"k8s.io/apimachinery/pkg/util/intstr"
@@ -242,6 +243,8 @@ func configureGerritContainer(sts *appsv1.StatefulSet, volumeMounts []apiv1.Volu
242243
sts.Spec.Template.Spec.Containers[0].Env = []apiv1.EnvVar{
243244
base.MkEnvVar("HOME", "/gerrit"),
244245
base.MkEnvVar("FQDN", fqdn),
246+
base.MkEnvVar("JVM_XMS", "128m"),
247+
base.MkEnvVar("JVM_XMX", "512m"),
245248
base.MkSecretEnvVar("GERRIT_ADMIN_SSH", "admin-ssh-key", "priv"),
246249
}
247250
sts.Spec.Template.Spec.Containers[0].ReadinessProbe = base.MkReadinessCMDProbe([]string{"bash", "/gerrit/ready.sh"})
@@ -309,8 +312,16 @@ func createInitContainers(volumeMounts []apiv1.VolumeMount, fqdn string) []apiv1
309312
container.Env = []apiv1.EnvVar{
310313
base.MkSecretEnvVar("GERRIT_ADMIN_SSH_PUB", "admin-ssh-key", "pub"),
311314
base.MkEnvVar("FQDN", fqdn),
315+
base.MkEnvVar("JVM_XMS", "128m"),
316+
base.MkEnvVar("JVM_XMX", "512m"),
312317
}
313318
container.VolumeMounts = volumeMounts
319+
base.SetContainerLimits(
320+
&container,
321+
resource.MustParse("256Mi"),
322+
resource.MustParse("512Mi"),
323+
resource.MustParse("100m"),
324+
resource.MustParse("1000m"))
314325
return []apiv1.Container{
315326
container,
316327
}
@@ -342,6 +353,12 @@ func (g *GerritCMDContext) ensureStatefulSetOrDie() {
342353
b, _ := g.getStatefulSetOrDie(name)
343354
if !b {
344355
container := base.MkContainer(name, gerritImage)
356+
base.SetContainerLimits(
357+
&container,
358+
resource.MustParse("256Mi"),
359+
resource.MustParse("512Mi"),
360+
resource.MustParse("100m"),
361+
resource.MustParse("1000m"))
345362
storageConfig := controllers.BaseGetStorageConfOrDefault(v1.StorageSpec{}, "")
346363
pvc := base.MkPVC(name, g.env.Ns, storageConfig, apiv1.ReadWriteOnce)
347364
sts := base.MkStatefulset(

cli/cmd/dev/gerrit/static/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -ex
44

55
# The /dev/./urandom is not a typo. https://stackoverflow.com/questions/58991966/what-java-security-egd-option-is-for
6-
JAVA_OPTIONS="-Djava.security.egd=file:/dev/./urandom"
6+
JAVA_OPTIONS="-Djava.security.egd=file:/dev/./urandom -Xms${JVM_XMS} -Xmx${JVM_XMX}"
77

88
echo "Set local git config for gerrit admin"
99
cat << EOF > ~/.gitconfig

cli/cmd/dev/gerrit/static/init.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

33
set -ex
4-
export HOME=/gerrit
54

5+
export HOME=/gerrit
66
# The /dev/./urandom is not a typo. https://stackoverflow.com/questions/58991966/what-java-security-egd-option-is-for
7-
JAVA_OPTIONS="-Djava.security.egd=file:/dev/./urandom"
7+
JAVA_OPTIONS="-Djava.security.egd=file:/dev/./urandom -Xms${JVM_XMS} -Xmx${JVM_XMX}"
88

99
echo "Initializing Gerrit site ..."
1010
java ${JAVA_OPTIONS} -jar /var/gerrit/bin/gerrit.war init -d ~/ --batch --no-auto-start --skip-plugins

0 commit comments

Comments
 (0)