Skip to content

Commit

Permalink
Increase MongoDB resource for version 7.x+ (#1345)
Browse files Browse the repository at this point in the history
* update default resources for mongodb version 8

Signed-off-by: sayedppqq <[email protected]>

* remove authArgs from probes cmd

Signed-off-by: sayedppqq <[email protected]>

* use memory intensive resource for arbiter in mongodb v7+

Signed-off-by: sayedppqq <[email protected]>

* comments resolved

Signed-off-by: sayedppqq <[email protected]>

---------

Signed-off-by: sayedppqq <[email protected]>
  • Loading branch information
sayedppqq authored Nov 15, 2024
1 parent 1275347 commit 4ce2b88
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
24 changes: 22 additions & 2 deletions apis/kubedb/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -1613,9 +1613,19 @@ var (
core.ResourceMemory: resource.MustParse("256Mi"),
},
}
DefaultArbiterMemoryIntensive = core.ResourceRequirements{
Requests: core.ResourceList{
// these are the default cpu & memory for a coordinator container
core.ResourceCPU: resource.MustParse(".200"),
core.ResourceMemory: resource.MustParse("500Mi"),
},
Limits: core.ResourceList{
core.ResourceMemory: resource.MustParse("500Mi"),
},
}

// DefaultResourcesCPUIntensive is for MongoDB versions >= 6
DefaultResourcesCPUIntensive = core.ResourceRequirements{
// DefaultResourcesCPUIntensiveMongoDBv6 is for MongoDB versions >= 6
DefaultResourcesCPUIntensiveMongoDBv6 = core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse(".800"),
core.ResourceMemory: resource.MustParse("1024Mi"),
Expand All @@ -1624,6 +1634,16 @@ var (
core.ResourceMemory: resource.MustParse("1024Mi"),
},
}
// DefaultResourcesCPUIntensiveMongoDBv8 is for MongoDB versions >= 8
DefaultResourcesCPUIntensiveMongoDBv8 = core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse(".800"),
core.ResourceMemory: resource.MustParse("1.5Gi"),
},
Limits: core.ResourceList{
core.ResourceMemory: resource.MustParse("1.5Gi"),
},
}

// DefaultResourcesMemoryIntensive must be used for elasticsearch
// to avoid OOMKILLED while deploying ES V8
Expand Down
32 changes: 17 additions & 15 deletions apis/kubedb/v1/mongodb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,10 @@ func (m *MongoDB) setPodTemplateDefaultValues(podTemplate *ofstv2.PodTemplateSpe
m.setDefaultPodSecurityContext(mgVersion, podTemplate)

defaultResource := kubedb.DefaultResources
if m.isVersion6OrLater(mgVersion) {
defaultResource = kubedb.DefaultResourcesCPUIntensive
if m.isLaterVersion(mgVersion, 8) {
defaultResource = kubedb.DefaultResourcesCPUIntensiveMongoDBv8
} else if m.isLaterVersion(mgVersion, 6) {
defaultResource = kubedb.DefaultResourcesCPUIntensiveMongoDBv6
}

container := ofst_util.EnsureInitContainerExists(podTemplate, kubedb.MongoDBInitInstallContainerName)
Expand All @@ -733,7 +735,11 @@ func (m *MongoDB) setContainerDefaultValues(container *core.Container, mgVersion
defaultResource core.ResourceRequirements, isArbiter ...bool,
) {
if len(isArbiter) > 0 && isArbiter[0] {
m.setContainerDefaultResources(container, kubedb.DefaultArbiter(true))
if m.isLaterVersion(mgVersion, 7) {
m.setContainerDefaultResources(container, kubedb.DefaultArbiterMemoryIntensive)
} else {
m.setContainerDefaultResources(container, kubedb.DefaultArbiter(true))
}
} else {
m.setContainerDefaultResources(container, defaultResource)
}
Expand Down Expand Up @@ -886,19 +892,19 @@ func (m *MongoDB) SetTLSDefaults() {
})
}

func (m *MongoDB) isVersion6OrLater(mgVersion *v1alpha1.MongoDBVersion) bool {
func (m *MongoDB) isLaterVersion(mgVersion *v1alpha1.MongoDBVersion, version uint64) bool {
v, _ := semver.NewVersion(mgVersion.Spec.Version)
return v.Major() >= 6
return v.Major() >= version
}

func (m *MongoDB) GetEntryCommand(mgVersion *v1alpha1.MongoDBVersion) string {
if m.isVersion6OrLater(mgVersion) {
if m.isLaterVersion(mgVersion, 6) {
return "mongosh"
}
return "mongo"
}

func (m *MongoDB) getCmdForProbes(mgVersion *v1alpha1.MongoDBVersion, isArbiter ...bool) []string {
func (m *MongoDB) getCmdForProbes(mgVersion *v1alpha1.MongoDBVersion) []string {
var sslArgs string
if m.Spec.SSLMode == SSLModeRequireSSL {
sslArgs = fmt.Sprintf("--tls --tlsCAFile=%v/%v --tlsCertificateKeyFile=%v/%v",
Expand All @@ -917,25 +923,21 @@ func (m *MongoDB) getCmdForProbes(mgVersion *v1alpha1.MongoDBVersion, isArbiter
}
}

var authArgs string
if len(isArbiter) == 0 { // not arbiter
authArgs = "--username=$MONGO_INITDB_ROOT_USERNAME --password=$MONGO_INITDB_ROOT_PASSWORD --authenticationDatabase=admin"
}
return []string{
"bash",
"-c",
fmt.Sprintf(`set -x; if [[ $(%s admin --host=localhost %v %v --quiet --eval "db.adminCommand('ping').ok" ) -eq "1" ]]; then
fmt.Sprintf(`set -x; if [[ $(%s admin --host=localhost %v --quiet --eval "db.adminCommand('ping').ok" ) -eq "1" ]]; then
exit 0
fi
exit 1`, m.GetEntryCommand(mgVersion), sslArgs, authArgs),
exit 1`, m.GetEntryCommand(mgVersion), sslArgs),
}
}

func (m *MongoDB) GetDefaultLivenessProbeSpec(mgVersion *v1alpha1.MongoDBVersion, isArbiter ...bool) *core.Probe {
return &core.Probe{
ProbeHandler: core.ProbeHandler{
Exec: &core.ExecAction{
Command: m.getCmdForProbes(mgVersion, isArbiter...),
Command: m.getCmdForProbes(mgVersion),
},
},
FailureThreshold: 3,
Expand All @@ -949,7 +951,7 @@ func (m *MongoDB) GetDefaultReadinessProbeSpec(mgVersion *v1alpha1.MongoDBVersio
return &core.Probe{
ProbeHandler: core.ProbeHandler{
Exec: &core.ExecAction{
Command: m.getCmdForProbes(mgVersion, isArbiter...),
Command: m.getCmdForProbes(mgVersion),
},
},
FailureThreshold: 3,
Expand Down
12 changes: 7 additions & 5 deletions apis/kubedb/v1alpha2/mongodb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,10 @@ func (m *MongoDB) SetDefaults(mgVersion *v1alpha1.MongoDBVersion, topology *core
}

defaultResource := kubedb.DefaultResources
if m.isVersion6OrLater(mgVersion) {
defaultResource = kubedb.DefaultResourcesCPUIntensive
if m.isLaterVersion(mgVersion, 8) {
defaultResource = kubedb.DefaultResourcesCPUIntensiveMongoDBv8
} else if m.isLaterVersion(mgVersion, 6) {
defaultResource = kubedb.DefaultResourcesCPUIntensiveMongoDBv6
}

if m.Spec.ShardTopology != nil {
Expand Down Expand Up @@ -890,13 +892,13 @@ func (m *MongoDB) SetTLSDefaults() {
})
}

func (m *MongoDB) isVersion6OrLater(mgVersion *v1alpha1.MongoDBVersion) bool {
func (m *MongoDB) isLaterVersion(mgVersion *v1alpha1.MongoDBVersion, version uint64) bool {
v, _ := semver.NewVersion(mgVersion.Spec.Version)
return v.Major() >= 6
return v.Major() >= version
}

func (m *MongoDB) GetEntryCommand(mgVersion *v1alpha1.MongoDBVersion) string {
if m.isVersion6OrLater(mgVersion) {
if m.isLaterVersion(mgVersion, 6) {
return "mongosh"
}
return "mongo"
Expand Down

0 comments on commit 4ce2b88

Please sign in to comment.