Skip to content

Commit

Permalink
set default resources
Browse files Browse the repository at this point in the history
Signed-off-by: sayedppqq <sayed@appscode.com>
  • Loading branch information
sayedppqq committed Jan 19, 2024
1 parent b1443d8 commit 63d9948
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions apis/kubedb/v1alpha2/ferretdb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 63d9948

Please sign in to comment.