Skip to content

Commit

Permalink
Merge "Set resources limit for all containers"
Browse files Browse the repository at this point in the history
  • Loading branch information
Microzuul CI authored and Gerrit Code Review committed May 21, 2024
2 parents 456a35c + c4135e6 commit 7d8150b
Show file tree
Hide file tree
Showing 17 changed files with 493 additions and 35 deletions.
39 changes: 39 additions & 0 deletions api/v1/softwarefactory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ type ZuulExecutorSpec struct {
// When set the Control plane is not deployed.
// The standalone executor must be able to connect to the control plane
Standalone *StandaloneZuulExecutorSpec `json:"standalone,omitempty"`
// Memory/CPU Limit
// +kubebuilder:validation:Optional
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
Limits *LimitsSpec `json:"limits"`
}

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

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

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

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

type NodepoolBuilderSpec struct {
Expand All @@ -446,6 +466,10 @@ type NodepoolBuilderSpec struct {
// "WARN",
// "DEBUG".
LogLevel LogLevel `json:"logLevel,omitempty"`
// Memory/CPU Limit
// +kubebuilder:validation:Optional
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
Limits *LimitsSpec `json:"limits"`
}

type NodepoolSpec struct {
Expand All @@ -459,13 +483,28 @@ type NodepoolSpec struct {

type ZookeeperSpec struct {
Storage StorageSpec `json:"storage"`
// Memory/CPU Limit
// +kubebuilder:validation:Optional
// +kubebuilder:default={"memory": "2Gi", "cpu": "2000m"}
Limits *LimitsSpec `json:"limits"`
}

type LimitsSpec struct {
// +kubebuilder:default:="2Gi"
Memory resource.Quantity `json:"memory"`
// +kubebuilder:default:="2000m"
CPU resource.Quantity `json:"cpu"`
}

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

type GitServerSpec struct {
Expand Down
61 changes: 59 additions & 2 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions cli/cmd/dev/gerrit/gerrit.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
batchv1 "k8s.io/api/batch/v1"
apiv1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -242,6 +243,8 @@ func configureGerritContainer(sts *appsv1.StatefulSet, volumeMounts []apiv1.Volu
sts.Spec.Template.Spec.Containers[0].Env = []apiv1.EnvVar{
base.MkEnvVar("HOME", "/gerrit"),
base.MkEnvVar("FQDN", fqdn),
base.MkEnvVar("JVM_XMS", "128m"),
base.MkEnvVar("JVM_XMX", "512m"),
base.MkSecretEnvVar("GERRIT_ADMIN_SSH", "admin-ssh-key", "priv"),
}
sts.Spec.Template.Spec.Containers[0].ReadinessProbe = base.MkReadinessCMDProbe([]string{"bash", "/gerrit/ready.sh"})
Expand Down Expand Up @@ -309,8 +312,16 @@ func createInitContainers(volumeMounts []apiv1.VolumeMount, fqdn string) []apiv1
container.Env = []apiv1.EnvVar{
base.MkSecretEnvVar("GERRIT_ADMIN_SSH_PUB", "admin-ssh-key", "pub"),
base.MkEnvVar("FQDN", fqdn),
base.MkEnvVar("JVM_XMS", "128m"),
base.MkEnvVar("JVM_XMX", "512m"),
}
container.VolumeMounts = volumeMounts
base.SetContainerLimits(
&container,
resource.MustParse("256Mi"),
resource.MustParse("512Mi"),
resource.MustParse("100m"),
resource.MustParse("1000m"))
return []apiv1.Container{
container,
}
Expand Down Expand Up @@ -342,6 +353,12 @@ func (g *GerritCMDContext) ensureStatefulSetOrDie() {
b, _ := g.getStatefulSetOrDie(name)
if !b {
container := base.MkContainer(name, gerritImage)
base.SetContainerLimits(
&container,
resource.MustParse("256Mi"),
resource.MustParse("512Mi"),
resource.MustParse("100m"),
resource.MustParse("1000m"))
storageConfig := controllers.BaseGetStorageConfOrDefault(v1.StorageSpec{}, "")
pvc := base.MkPVC(name, g.env.Ns, storageConfig, apiv1.ReadWriteOnce)
sts := base.MkStatefulset(
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/dev/gerrit/static/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -ex

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

echo "Set local git config for gerrit admin"
cat << EOF > ~/.gitconfig
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/dev/gerrit/static/init.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

set -ex
export HOME=/gerrit

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

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

0 comments on commit 7d8150b

Please sign in to comment.