From 63d994841c5d3ccc9eae9e5449711f1645ed2c6c Mon Sep 17 00:00:00 2001 From: sayedppqq Date: Fri, 19 Jan 2024 19:11:45 +0600 Subject: [PATCH] set default resources Signed-off-by: sayedppqq --- apis/kubedb/v1alpha2/ferretdb_helpers.go | 20 ++++++++++++++++++++ go.mod | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apis/kubedb/v1alpha2/ferretdb_helpers.go b/apis/kubedb/v1alpha2/ferretdb_helpers.go index 2730504260..5215267ab9 100644 --- a/apis/kubedb/v1alpha2/ferretdb_helpers.go +++ b/apis/kubedb/v1alpha2/ferretdb_helpers.go @@ -19,17 +19,22 @@ package v1alpha2 import ( "fmt" + "kubedb.dev/apimachinery/apis" "kubedb.dev/apimachinery/apis/kubedb" "kubedb.dev/apimachinery/crds" + "github.com/fatih/structs" v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "gomodules.xyz/pointer" + core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" kmapi "kmodules.xyz/client-go/api/v1" "kmodules.xyz/client-go/apiextensions" + coreutil "kmodules.xyz/client-go/core/v1" meta_util "kmodules.xyz/client-go/meta" appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1" mona "kmodules.xyz/monitoring-agent-api/api/v1" + ofst "kmodules.xyz/offshoot-api/api/v2" ) func (f *FerretDB) CustomResourceDefinition() *apiextensions.CustomResourceDefinition { @@ -159,6 +164,21 @@ func (f *FerretDB) SetDefaults() { f.Spec.Replicas = pointer.Int32P(1) } + if f.Spec.PodTemplate == nil { + f.Spec.PodTemplate = &ofst.PodTemplateSpec{} + } + + dbContainer := coreutil.GetContainerByName(f.Spec.PodTemplate.Spec.Containers, FerretDBContainerName) + if dbContainer == nil { + dbContainer = &core.Container{ + Name: FerretDBContainerName, + } + f.Spec.PodTemplate.Spec.Containers = append(f.Spec.PodTemplate.Spec.Containers, *dbContainer) + } + if structs.IsZero(dbContainer.Resources) { + apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResources) + } + if f.Spec.Backend.LinkedDB == "" { if f.Spec.Backend.ExternallyManaged { f.Spec.Backend.LinkedDB = "postgres" diff --git a/go.mod b/go.mod index 5f44c01b8b..ba66cf6092 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/cert-manager/cert-manager v1.9.1 github.com/evanphx/json-patch v5.7.0+incompatible + github.com/fatih/structs v1.1.0 github.com/google/go-cmp v0.6.0 github.com/google/gofuzz v1.2.0 github.com/iancoleman/orderedmap v0.2.0 @@ -77,7 +78,6 @@ require ( github.com/docker/docker-credential-helpers v0.7.0 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.7.0 // indirect - github.com/fatih/structs v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.3.0 // indirect