From 27f963746166e2edbea8de562e3e9e283c397d45 Mon Sep 17 00:00:00 2001 From: sayedppqq Date: Mon, 21 Oct 2024 16:01:15 +0600 Subject: [PATCH 1/4] update default resources for mongodb version 8 Signed-off-by: sayedppqq --- apis/kubedb/constants.go | 18 ++++++++++++++---- apis/kubedb/v1/mongodb_helpers.go | 12 +++++++----- apis/kubedb/v1alpha2/mongodb_helpers.go | 12 +++++++----- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/apis/kubedb/constants.go b/apis/kubedb/constants.go index cac9c28825..283d12025b 100644 --- a/apis/kubedb/constants.go +++ b/apis/kubedb/constants.go @@ -1607,15 +1607,15 @@ var ( core.ResourceStorage: resource.MustParse("2Gi"), // these are the default cpu & memory for a coordinator container core.ResourceCPU: resource.MustParse(".200"), - core.ResourceMemory: resource.MustParse("256Mi"), + core.ResourceMemory: resource.MustParse("500Mi"), }, Limits: core.ResourceList{ - core.ResourceMemory: resource.MustParse("256Mi"), + core.ResourceMemory: resource.MustParse("500Mi"), }, } - // DefaultResourcesCPUIntensive is for MongoDB versions >= 6 - DefaultResourcesCPUIntensive = core.ResourceRequirements{ + // DefaultResourcesCPUIntensiveVersion6 is for MongoDB versions >= 6 + DefaultResourcesCPUIntensiveVersion6 = core.ResourceRequirements{ Requests: core.ResourceList{ core.ResourceCPU: resource.MustParse(".800"), core.ResourceMemory: resource.MustParse("1024Mi"), @@ -1624,6 +1624,16 @@ var ( core.ResourceMemory: resource.MustParse("1024Mi"), }, } + // DefaultResourcesCPUIntensiveVersion8 is for MongoDB versions >= 8 + DefaultResourcesCPUIntensiveVersion8 = 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 diff --git a/apis/kubedb/v1/mongodb_helpers.go b/apis/kubedb/v1/mongodb_helpers.go index 48c310d48e..9522625b86 100644 --- a/apis/kubedb/v1/mongodb_helpers.go +++ b/apis/kubedb/v1/mongodb_helpers.go @@ -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.DefaultResourcesCPUIntensiveVersion8 + } else if m.isLaterVersion(mgVersion, 6) { + defaultResource = kubedb.DefaultResourcesCPUIntensiveVersion6 } container := ofst_util.EnsureInitContainerExists(podTemplate, kubedb.MongoDBInitInstallContainerName) @@ -886,13 +888,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" diff --git a/apis/kubedb/v1alpha2/mongodb_helpers.go b/apis/kubedb/v1alpha2/mongodb_helpers.go index 7304b41b12..d71f2a2354 100644 --- a/apis/kubedb/v1alpha2/mongodb_helpers.go +++ b/apis/kubedb/v1alpha2/mongodb_helpers.go @@ -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.DefaultResourcesCPUIntensiveVersion8 + } else if m.isLaterVersion(mgVersion, 6) { + defaultResource = kubedb.DefaultResourcesCPUIntensiveVersion6 } if m.Spec.ShardTopology != nil { @@ -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" From f7685262bf342995a5da642de5617b39dabee51b Mon Sep 17 00:00:00 2001 From: sayedppqq Date: Tue, 12 Nov 2024 13:58:09 +0600 Subject: [PATCH 2/4] remove authArgs from probes cmd Signed-off-by: sayedppqq --- apis/kubedb/v1/mongodb_helpers.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/apis/kubedb/v1/mongodb_helpers.go b/apis/kubedb/v1/mongodb_helpers.go index 9522625b86..a68adf20dd 100644 --- a/apis/kubedb/v1/mongodb_helpers.go +++ b/apis/kubedb/v1/mongodb_helpers.go @@ -900,7 +900,7 @@ func (m *MongoDB) GetEntryCommand(mgVersion *v1alpha1.MongoDBVersion) string { 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", @@ -919,17 +919,13 @@ 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), } } @@ -937,7 +933,7 @@ func (m *MongoDB) GetDefaultLivenessProbeSpec(mgVersion *v1alpha1.MongoDBVersion return &core.Probe{ ProbeHandler: core.ProbeHandler{ Exec: &core.ExecAction{ - Command: m.getCmdForProbes(mgVersion, isArbiter...), + Command: m.getCmdForProbes(mgVersion), }, }, FailureThreshold: 3, @@ -951,7 +947,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, From fa97422ca4985fdd7812a9ac7de49be590640492 Mon Sep 17 00:00:00 2001 From: sayedppqq Date: Fri, 15 Nov 2024 11:28:16 +0600 Subject: [PATCH 3/4] use memory intensive resource for arbiter in mongodb v7+ Signed-off-by: sayedppqq --- apis/kubedb/constants.go | 10 ++++++++++ apis/kubedb/v1/mongodb_helpers.go | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apis/kubedb/constants.go b/apis/kubedb/constants.go index 283d12025b..6501cf0150 100644 --- a/apis/kubedb/constants.go +++ b/apis/kubedb/constants.go @@ -1605,6 +1605,16 @@ var ( defaultArbiter = core.ResourceRequirements{ Requests: core.ResourceList{ core.ResourceStorage: resource.MustParse("2Gi"), + // these are the default cpu & memory for a coordinator container + core.ResourceCPU: resource.MustParse(".200"), + core.ResourceMemory: resource.MustParse("250Mi"), + }, + Limits: core.ResourceList{ + core.ResourceMemory: resource.MustParse("250Mi"), + }, + } + 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"), diff --git a/apis/kubedb/v1/mongodb_helpers.go b/apis/kubedb/v1/mongodb_helpers.go index a68adf20dd..1f781057ef 100644 --- a/apis/kubedb/v1/mongodb_helpers.go +++ b/apis/kubedb/v1/mongodb_helpers.go @@ -735,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) } From 08d05d308984ab4b12ea130d3a86c593160ce15d Mon Sep 17 00:00:00 2001 From: sayedppqq Date: Fri, 15 Nov 2024 12:19:55 +0600 Subject: [PATCH 4/4] comments resolved Signed-off-by: sayedppqq --- apis/kubedb/constants.go | 12 ++++++------ apis/kubedb/v1/mongodb_helpers.go | 4 ++-- apis/kubedb/v1alpha2/mongodb_helpers.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apis/kubedb/constants.go b/apis/kubedb/constants.go index 6501cf0150..88afd28541 100644 --- a/apis/kubedb/constants.go +++ b/apis/kubedb/constants.go @@ -1607,10 +1607,10 @@ var ( core.ResourceStorage: resource.MustParse("2Gi"), // these are the default cpu & memory for a coordinator container core.ResourceCPU: resource.MustParse(".200"), - core.ResourceMemory: resource.MustParse("250Mi"), + core.ResourceMemory: resource.MustParse("256Mi"), }, Limits: core.ResourceList{ - core.ResourceMemory: resource.MustParse("250Mi"), + core.ResourceMemory: resource.MustParse("256Mi"), }, } DefaultArbiterMemoryIntensive = core.ResourceRequirements{ @@ -1624,8 +1624,8 @@ var ( }, } - // DefaultResourcesCPUIntensiveVersion6 is for MongoDB versions >= 6 - DefaultResourcesCPUIntensiveVersion6 = core.ResourceRequirements{ + // DefaultResourcesCPUIntensiveMongoDBv6 is for MongoDB versions >= 6 + DefaultResourcesCPUIntensiveMongoDBv6 = core.ResourceRequirements{ Requests: core.ResourceList{ core.ResourceCPU: resource.MustParse(".800"), core.ResourceMemory: resource.MustParse("1024Mi"), @@ -1634,8 +1634,8 @@ var ( core.ResourceMemory: resource.MustParse("1024Mi"), }, } - // DefaultResourcesCPUIntensiveVersion8 is for MongoDB versions >= 8 - DefaultResourcesCPUIntensiveVersion8 = core.ResourceRequirements{ + // DefaultResourcesCPUIntensiveMongoDBv8 is for MongoDB versions >= 8 + DefaultResourcesCPUIntensiveMongoDBv8 = core.ResourceRequirements{ Requests: core.ResourceList{ core.ResourceCPU: resource.MustParse(".800"), core.ResourceMemory: resource.MustParse("1.5Gi"), diff --git a/apis/kubedb/v1/mongodb_helpers.go b/apis/kubedb/v1/mongodb_helpers.go index 1f781057ef..4422cccafe 100644 --- a/apis/kubedb/v1/mongodb_helpers.go +++ b/apis/kubedb/v1/mongodb_helpers.go @@ -714,9 +714,9 @@ func (m *MongoDB) setPodTemplateDefaultValues(podTemplate *ofstv2.PodTemplateSpe defaultResource := kubedb.DefaultResources if m.isLaterVersion(mgVersion, 8) { - defaultResource = kubedb.DefaultResourcesCPUIntensiveVersion8 + defaultResource = kubedb.DefaultResourcesCPUIntensiveMongoDBv8 } else if m.isLaterVersion(mgVersion, 6) { - defaultResource = kubedb.DefaultResourcesCPUIntensiveVersion6 + defaultResource = kubedb.DefaultResourcesCPUIntensiveMongoDBv6 } container := ofst_util.EnsureInitContainerExists(podTemplate, kubedb.MongoDBInitInstallContainerName) diff --git a/apis/kubedb/v1alpha2/mongodb_helpers.go b/apis/kubedb/v1alpha2/mongodb_helpers.go index d71f2a2354..d06b88a655 100644 --- a/apis/kubedb/v1alpha2/mongodb_helpers.go +++ b/apis/kubedb/v1alpha2/mongodb_helpers.go @@ -635,9 +635,9 @@ func (m *MongoDB) SetDefaults(mgVersion *v1alpha1.MongoDBVersion, topology *core defaultResource := kubedb.DefaultResources if m.isLaterVersion(mgVersion, 8) { - defaultResource = kubedb.DefaultResourcesCPUIntensiveVersion8 + defaultResource = kubedb.DefaultResourcesCPUIntensiveMongoDBv8 } else if m.isLaterVersion(mgVersion, 6) { - defaultResource = kubedb.DefaultResourcesCPUIntensiveVersion6 + defaultResource = kubedb.DefaultResourcesCPUIntensiveMongoDBv6 } if m.Spec.ShardTopology != nil {