Skip to content

Commit

Permalink
Fix default resource for solr, singlestore, kafka, rabbitmq and druid
Browse files Browse the repository at this point in the history
Signed-off-by: raihankhan <[email protected]>
  • Loading branch information
raihankhan committed Feb 9, 2024
1 parent 992de06 commit f7e8e20
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 43 deletions.
2 changes: 1 addition & 1 deletion apis/kafka/v1alpha1/connect_cluster_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (k *ConnectCluster) SetDefaults() {
k.setDefaultInitContainerSecurityContext(&k.Spec.PodTemplate)

dbContainer := coreutil.GetContainerByName(k.Spec.PodTemplate.Spec.Containers, ConnectClusterContainerName)
if dbContainer != nil {
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&dbContainer.Resources, api.DefaultResources)
}

Expand Down
6 changes: 3 additions & 3 deletions apis/kubedb/v1alpha2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,9 @@ const (
DruidConfigFileNameRouters = "routers.properties"
DruidVolumeMySQLMetadataStorage = "mysql-metadata-storage"

DruidMainContainer = "druid"
DruidInitContainer = "init-druid"
DruidUserAdmin = "admin"
DruidContainerName = "druid"
DruidInitContainerName = "init-druid"
DruidUserAdmin = "admin"

EnvDruidAdminPassword = "DRUID_ADMIN_PASSWORD"
EnvDruidMetdataStoragePassword = "DRUID_METADATA_STORAGE_PASSWORD"
Expand Down
27 changes: 23 additions & 4 deletions apis/kubedb/v1alpha2/druid_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strconv"
"strings"

"kubedb.dev/apimachinery/apis"
catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
"kubedb.dev/apimachinery/apis/kubedb"
"kubedb.dev/apimachinery/crds"
Expand Down Expand Up @@ -334,6 +335,7 @@ func (d *Druid) SetDefaults() {
}
d.setDefaultContainerSecurityContext(&druidVersion, &d.Spec.Topology.Coordinators.PodTemplate)
d.setDefaultInitContainerSecurityContext(&druidVersion, &d.Spec.Topology.Coordinators.PodTemplate)
d.setDefaultContainerResourceLimits(&d.Spec.Topology.Coordinators.PodTemplate)
}
}
if d.Spec.Topology.Overlords != nil {
Expand All @@ -346,6 +348,7 @@ func (d *Druid) SetDefaults() {
}
d.setDefaultContainerSecurityContext(&druidVersion, &d.Spec.Topology.Overlords.PodTemplate)
d.setDefaultInitContainerSecurityContext(&druidVersion, &d.Spec.Topology.Overlords.PodTemplate)
d.setDefaultContainerResourceLimits(&d.Spec.Topology.Overlords.PodTemplate)
}
}
if d.Spec.Topology.MiddleManagers != nil {
Expand All @@ -358,6 +361,7 @@ func (d *Druid) SetDefaults() {
}
d.setDefaultContainerSecurityContext(&druidVersion, &d.Spec.Topology.MiddleManagers.PodTemplate)
d.setDefaultInitContainerSecurityContext(&druidVersion, &d.Spec.Topology.MiddleManagers.PodTemplate)
d.setDefaultContainerResourceLimits(&d.Spec.Topology.MiddleManagers.PodTemplate)
}
}
if d.Spec.Topology.Historicals != nil {
Expand All @@ -370,6 +374,7 @@ func (d *Druid) SetDefaults() {
}
d.setDefaultContainerSecurityContext(&druidVersion, &d.Spec.Topology.Historicals.PodTemplate)
d.setDefaultInitContainerSecurityContext(&druidVersion, &d.Spec.Topology.Historicals.PodTemplate)
d.setDefaultContainerResourceLimits(&d.Spec.Topology.Historicals.PodTemplate)
}
}
if d.Spec.Topology.Brokers != nil {
Expand All @@ -382,6 +387,7 @@ func (d *Druid) SetDefaults() {
}
d.setDefaultContainerSecurityContext(&druidVersion, &d.Spec.Topology.Brokers.PodTemplate)
d.setDefaultInitContainerSecurityContext(&druidVersion, &d.Spec.Topology.Brokers.PodTemplate)
d.setDefaultContainerResourceLimits(&d.Spec.Topology.Brokers.PodTemplate)

}
}
Expand All @@ -395,6 +401,7 @@ func (d *Druid) SetDefaults() {
}
d.setDefaultContainerSecurityContext(&druidVersion, &d.Spec.Topology.Routers.PodTemplate)
d.setDefaultInitContainerSecurityContext(&druidVersion, &d.Spec.Topology.Routers.PodTemplate)
d.setDefaultContainerResourceLimits(&d.Spec.Topology.Routers.PodTemplate)
}
}
}
Expand All @@ -406,10 +413,10 @@ func (d *Druid) SetDefaults() {
}

func (d *Druid) setDefaultInitContainerSecurityContext(druidVersion *catalog.DruidVersion, podTemplate *ofst.PodTemplateSpec) {
initContainer := coreutil.GetContainerByName(podTemplate.Spec.InitContainers, DruidInitContainer)
initContainer := coreutil.GetContainerByName(podTemplate.Spec.InitContainers, DruidInitContainerName)
if initContainer == nil {
initContainer = &v1.Container{
Name: DruidInitContainer,
Name: DruidInitContainerName,
}
}
if initContainer.SecurityContext == nil {
Expand All @@ -420,10 +427,10 @@ func (d *Druid) setDefaultInitContainerSecurityContext(druidVersion *catalog.Dru
}

func (d *Druid) setDefaultContainerSecurityContext(druidVersion *catalog.DruidVersion, podTemplate *ofst.PodTemplateSpec) {
container := coreutil.GetContainerByName(podTemplate.Spec.Containers, DruidMainContainer)
container := coreutil.GetContainerByName(podTemplate.Spec.Containers, DruidContainerName)
if container == nil {
container = &v1.Container{
Name: DruidMainContainer,
Name: DruidContainerName,
}
}
if container.SecurityContext == nil {
Expand Down Expand Up @@ -453,6 +460,18 @@ func (d *Druid) assignDefaultContainerSecurityContext(druidVersion *catalog.Drui
}
}

func (d *Druid) setDefaultContainerResourceLimits(podTemplate *ofst.PodTemplateSpec) {
dbContainer := coreutil.GetContainerByName(podTemplate.Spec.Containers, DruidContainerName)
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResources)
}

initContainer := coreutil.GetContainerByName(podTemplate.Spec.InitContainers, DruidInitContainerName)
if initContainer != nil && (initContainer.Resources.Requests == nil && initContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&initContainer.Resources, DefaultInitContainerResource)
}
}

func (d *Druid) GetPersistentSecrets() []string {
if d == nil {
return nil
Expand Down
11 changes: 8 additions & 3 deletions apis/kubedb/v1alpha2/kafka_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ func (k *Kafka) SetDefaults() {
if k.Spec.Topology.Controller.Replicas == nil {
k.Spec.Topology.Controller.Replicas = pointer.Int32P(1)
}
apis.SetDefaultResourceLimits(&k.Spec.Topology.Controller.Resources, DefaultResources)

if k.Spec.Topology.Controller.Resources.Requests == nil && k.Spec.Topology.Controller.Resources.Limits == nil {
apis.SetDefaultResourceLimits(&k.Spec.Topology.Controller.Resources, DefaultResources)
}
}

if k.Spec.Topology.Broker != nil {
Expand All @@ -347,11 +350,13 @@ func (k *Kafka) SetDefaults() {
if k.Spec.Topology.Broker.Replicas == nil {
k.Spec.Topology.Broker.Replicas = pointer.Int32P(1)
}
apis.SetDefaultResourceLimits(&k.Spec.Topology.Broker.Resources, DefaultResources)
if k.Spec.Topology.Broker.Resources.Requests == nil && k.Spec.Topology.Broker.Resources.Limits == nil {
apis.SetDefaultResourceLimits(&k.Spec.Topology.Broker.Resources, DefaultResources)
}
}
} else {
dbContainer := coreutil.GetContainerByName(k.Spec.PodTemplate.Spec.Containers, KafkaContainerName)
if dbContainer != nil {
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResources)
}
if k.Spec.Replicas == nil {
Expand Down
7 changes: 0 additions & 7 deletions apis/kubedb/v1alpha2/openapi_generated.go

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

2 changes: 1 addition & 1 deletion apis/kubedb/v1alpha2/rabbitmq_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (r *RabbitMQ) SetDefaults() {
r.setDefaultContainerSecurityContext(&rmVersion, &r.Spec.PodTemplate)

dbContainer := coreutil.GetContainerByName(r.Spec.PodTemplate.Spec.Containers, RabbitMQContainerName)
if dbContainer != nil {
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResources)
}

Expand Down
32 changes: 29 additions & 3 deletions apis/kubedb/v1alpha2/singlestore_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"strings"

"kubedb.dev/apimachinery/apis"
catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
"kubedb.dev/apimachinery/apis/kubedb"
"kubedb.dev/apimachinery/crds"
Expand Down Expand Up @@ -277,10 +278,16 @@ func (s *Singlestore) SetDefaults() {
s.setDefaultContainerSecurityContext(&sdbVersion, s.Spec.Topology.Leaf.PodTemplate)
}

if s.Spec.EnableSSL {
s.SetTLSDefaults()
}
s.SetTLSDefaults()

s.SetHealthCheckerDefaults()

if s.IsClustering() {
s.setDefaultContainerResourceLimits(s.Spec.Topology.Aggregator.PodTemplate)
s.setDefaultContainerResourceLimits(s.Spec.Topology.Leaf.PodTemplate)
} else {
s.setDefaultContainerResourceLimits(s.Spec.PodTemplate)
}
}

func (s *Singlestore) setDefaultContainerSecurityContext(sdbVersion *catalog.SinglestoreVersion, podTemplate *ofst.PodTemplateSpec) {
Expand Down Expand Up @@ -379,6 +386,25 @@ func (s *Singlestore) assignDefaultContainerSecurityContext(sdbVersion *catalog.
}
}

func (s *Singlestore) setDefaultContainerResourceLimits(podTemplate *ofst.PodTemplateSpec) {
dbContainer := coreutil.GetContainerByName(podTemplate.Spec.Containers, SinglestoreContainerName)
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResources)
}

initContainer := coreutil.GetContainerByName(podTemplate.Spec.InitContainers, SinglestoreInitContainerName)
if initContainer != nil && (initContainer.Resources.Requests == nil && initContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&initContainer.Resources, DefaultInitContainerResource)
}

if s.IsClustering() {
coordinatorContainer := coreutil.GetContainerByName(podTemplate.Spec.Containers, SinglestoreCoordinatorContainerName)
if coordinatorContainer != nil && (coordinatorContainer.Resources.Requests == nil && coordinatorContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&coordinatorContainer.Resources, CoordinatorDefaultResources)
}
}
}

func (s *Singlestore) SetTLSDefaults() {
if s.Spec.TLS == nil || s.Spec.TLS.IssuerRef == nil {
return
Expand Down
3 changes: 0 additions & 3 deletions apis/kubedb/v1alpha2/singlestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ type SinglestoreSpec struct {
// Storage to specify how storage shall be used.
Storage *core.PersistentVolumeClaimSpec `json:"storage,omitempty"`

// To enable ssl for http layer
EnableSSL bool `json:"enableSSL,omitempty"`

// Init is used to initialize database
// +optional
Init *InitSpec `json:"init,omitempty"`
Expand Down
14 changes: 0 additions & 14 deletions apis/kubedb/v1alpha2/singlestore_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,6 @@ func (s *Singlestore) ValidateDelete() (admission.Warnings, error) {
func (s *Singlestore) ValidateCreateOrUpdate() field.ErrorList {
var allErr field.ErrorList

if s.Spec.EnableSSL {
if s.Spec.TLS == nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("enableSSL"),
s.Name,
".spec.tls can't be nil, if .spec.enableSSL is true"))
}
} else {
if s.Spec.TLS != nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("enableSSL"),
s.Name,
".spec.tls must be nil, if .spec.enableSSL is disabled"))
}
}

if s.Spec.Version == "" {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("version"),
s.Name,
Expand Down
18 changes: 16 additions & 2 deletions apis/kubedb/v1alpha2/solr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) {
s.Spec.Topology.Data.PodTemplate.Spec.SecurityContext.FSGroup = slVersion.Spec.SecurityContext.RunAsUser
s.setDefaultContainerSecurityContext(slVersion, &s.Spec.Topology.Data.PodTemplate)
s.setDefaultInitContainerSecurityContext(slVersion, &s.Spec.Topology.Data.PodTemplate)
s.setDefaultContainerResourceLimits(&s.Spec.Topology.Data.PodTemplate)
}

if s.Spec.Topology.Overseer != nil {
Expand All @@ -235,6 +236,7 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) {
s.Spec.Topology.Overseer.PodTemplate.Spec.SecurityContext.FSGroup = slVersion.Spec.SecurityContext.RunAsUser
s.setDefaultContainerSecurityContext(slVersion, &s.Spec.Topology.Overseer.PodTemplate)
s.setDefaultInitContainerSecurityContext(slVersion, &s.Spec.Topology.Overseer.PodTemplate)
s.setDefaultContainerResourceLimits(&s.Spec.Topology.Overseer.PodTemplate)
}

if s.Spec.Topology.Coordinator != nil {
Expand All @@ -251,6 +253,7 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) {
s.Spec.Topology.Coordinator.PodTemplate.Spec.SecurityContext.FSGroup = slVersion.Spec.SecurityContext.RunAsUser
s.setDefaultContainerSecurityContext(slVersion, &s.Spec.Topology.Coordinator.PodTemplate)
s.setDefaultInitContainerSecurityContext(slVersion, &s.Spec.Topology.Coordinator.PodTemplate)
s.setDefaultContainerResourceLimits(&s.Spec.Topology.Coordinator.PodTemplate)
}
} else {

Expand All @@ -264,8 +267,8 @@ func (s *Solr) SetDefaults(slVersion *catalog.SolrVersion) {

s.Spec.PodTemplate.Spec.SecurityContext.FSGroup = slVersion.Spec.SecurityContext.RunAsUser
s.setDefaultContainerSecurityContext(slVersion, &s.Spec.PodTemplate)

s.setDefaultInitContainerSecurityContext(slVersion, &s.Spec.PodTemplate)
s.setDefaultContainerResourceLimits(&s.Spec.PodTemplate)
}
}

Expand Down Expand Up @@ -294,7 +297,6 @@ func (s *Solr) setDefaultContainerSecurityContext(slVersion *catalog.SolrVersion
if container.SecurityContext == nil {
container.SecurityContext = &v1.SecurityContext{}
}
apis.SetDefaultResourceLimits(&container.Resources, DefaultResources)
s.assignDefaultContainerSecurityContext(slVersion, container.SecurityContext)
podTemplate.Spec.Containers = coreutil.UpsertContainer(podTemplate.Spec.Containers, *container)
}
Expand All @@ -319,6 +321,18 @@ func (s *Solr) assignDefaultContainerSecurityContext(slVersion *catalog.SolrVers
}
}

func (s *Solr) setDefaultContainerResourceLimits(podTemplate *ofst.PodTemplateSpec) {
dbContainer := coreutil.GetContainerByName(podTemplate.Spec.Containers, SolrContainerName)
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&dbContainer.Resources, DefaultResources)
}

initContainer := coreutil.GetContainerByName(podTemplate.Spec.InitContainers, SolrInitContainerName)
if initContainer != nil && (initContainer.Resources.Requests == nil && initContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&initContainer.Resources, DefaultInitContainerResource)
}
}

func (s *Solr) SetHealthCheckerDefaults() {
if s.Spec.HealthChecker.PeriodSeconds == nil {
s.Spec.HealthChecker.PeriodSeconds = pointer.Int32P(20)
Expand Down
2 changes: 0 additions & 2 deletions crds/kubedb.com_singlestores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
enableSSL:
type: boolean
halted:
type: boolean
healthChecker:
Expand Down

0 comments on commit f7e8e20

Please sign in to comment.