Skip to content

Commit

Permalink
Keep the druid dependency references if given (#1272)
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <[email protected]>
Signed-off-by: Tapajit Chandra Paul <[email protected]>
Co-authored-by: Tapajit Chandra Paul <[email protected]>
  • Loading branch information
ArnobKumarSaha and tapojit047 authored Aug 1, 2024
1 parent 88b6087 commit c57d4c2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 44 deletions.
81 changes: 46 additions & 35 deletions apis/kubedb/v1alpha2/druid_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,18 +511,25 @@ func (d *Druid) SetDefaults() {
}
}

if d.Spec.MetadataStorage == nil {
d.Spec.MetadataStorage = &MetadataStorage{}
}
if !d.Spec.MetadataStorage.ExternallyManaged {
if d.Spec.MetadataStorage.ObjectReference == nil {
d.Spec.MetadataStorage.ObjectReference = &kmapi.ObjectReference{}
d.SetDefaultsToMetadataStorage()
d.SetDefaultsToZooKeeperRef()

if d.Spec.Monitor != nil {
if d.Spec.Monitor.Prometheus == nil {
d.Spec.Monitor.Prometheus = &mona.PrometheusSpec{}
}
d.Spec.MetadataStorage.Name = d.GetMetadataStorageName()
if d.Spec.Monitor.Prometheus != nil && d.Spec.Monitor.Prometheus.Exporter.Port == 0 {
d.Spec.Monitor.Prometheus.Exporter.Port = kubedb.DruidExporterPort
}
d.Spec.Monitor.SetDefaults()
}
if d.Spec.MetadataStorage.Namespace == "" {
d.Spec.MetadataStorage.Namespace = d.Namespace
}

func (d *Druid) SetDefaultsToMetadataStorage() {
if d.Spec.MetadataStorage == nil {
d.Spec.MetadataStorage = &MetadataStorage{}
}
d.SetMetadataStorageObjectRef()
if d.Spec.MetadataStorage.LinkedDB == "" {
d.Spec.MetadataStorage.LinkedDB = "druid"
}
Expand All @@ -541,12 +548,6 @@ func (d *Druid) SetDefaults() {
d.Spec.MetadataStorage.Type = DruidMetadataStorageMySQL
}
}
if !d.Spec.MetadataStorage.ExternallyManaged {
if d.Spec.MetadataStorage.ObjectReference == nil {
d.Spec.MetadataStorage.ObjectReference = &kmapi.ObjectReference{}
}
d.Spec.MetadataStorage.Name = d.GetMetadataStorageName()
}

if d.Spec.MetadataStorage.Version == nil {
var defaultVersion string
Expand All @@ -557,33 +558,17 @@ func (d *Druid) SetDefaults() {
}
d.Spec.MetadataStorage.Version = &defaultVersion
}
}

func (d *Druid) SetDefaultsToZooKeeperRef() {
if d.Spec.ZookeeperRef == nil {
d.Spec.ZookeeperRef = &ZookeeperRef{}
}
if !d.Spec.ZookeeperRef.ExternallyManaged {
if d.Spec.ZookeeperRef.ObjectReference == nil {
d.Spec.ZookeeperRef.ObjectReference = &kmapi.ObjectReference{}
}
if d.Spec.ZookeeperRef.Name == "" {
d.Spec.ZookeeperRef.Name = d.GetZooKeeperName()
}
if d.Spec.ZookeeperRef.Namespace == "" {
d.Spec.ZookeeperRef.Namespace = d.Namespace
}
d.SetZooKeeperObjectRef()
if d.Spec.ZookeeperRef.Version == nil {
defaultVersion := "3.7.2"
d.Spec.ZookeeperRef.Version = &defaultVersion
}

if d.Spec.Monitor != nil {
if d.Spec.Monitor.Prometheus == nil {
d.Spec.Monitor.Prometheus = &mona.PrometheusSpec{}
}
if d.Spec.Monitor.Prometheus != nil && d.Spec.Monitor.Prometheus.Exporter.Port == 0 {
d.Spec.Monitor.Prometheus.Exporter.Port = kubedb.DruidExporterPort
}
d.Spec.Monitor.SetDefaults()
}
}

func (d *Druid) GetDefaultPVC() *core.PersistentVolumeClaimSpec {
Expand Down Expand Up @@ -700,13 +685,39 @@ func (d *Druid) GetAppBinding(name string, namespace string) (*appcat.AppBinding
return appbinding, nil
}

func (d *Druid) SetMetadataStorageObjectRef() {
if d.Spec.MetadataStorage.ObjectReference == nil {
d.Spec.MetadataStorage.ObjectReference = &kmapi.ObjectReference{}
}
if d.Spec.MetadataStorage.Name == "" {
d.Spec.MetadataStorage.ExternallyManaged = false
d.Spec.MetadataStorage.Name = d.GetMetadataStorageName()
}
if d.Spec.MetadataStorage.Namespace == "" {
d.Spec.MetadataStorage.Namespace = d.Namespace
}
}

func (d *Druid) GetMetadataStorageName() string {
if d.Spec.MetadataStorage.Type == DruidMetadataStoragePostgreSQL {
return d.OffShootName() + "-pg-metadata"
}
return d.OffShootName() + "-mysql-metadata"
}

func (d *Druid) SetZooKeeperObjectRef() {
if d.Spec.ZookeeperRef.ObjectReference == nil {
d.Spec.ZookeeperRef.ObjectReference = &kmapi.ObjectReference{}
}
if d.Spec.ZookeeperRef.Name == "" {
d.Spec.ZookeeperRef.ExternallyManaged = false
d.Spec.ZookeeperRef.Name = d.GetZooKeeperName()
}
if d.Spec.ZookeeperRef.Namespace == "" {
d.Spec.ZookeeperRef.Namespace = d.Namespace
}
}

func (d *Druid) GetZooKeeperName() string {
return d.OffShootName() + "-zk"
}
Expand Down
28 changes: 19 additions & 9 deletions apis/kubedb/v1alpha2/druid_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,26 @@ func (d *Druid) validateCreateOrUpdate() field.ErrorList {
}
}

if d.Spec.MetadataStorage == nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("metadataStorage"),
if d.Spec.MetadataStorage.Name == "" {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("metadataStorage").Child("name"),
d.Name,
"spec.metadataStorage is missing"))
} else {
if d.Spec.MetadataStorage.ExternallyManaged && d.Spec.MetadataStorage.Name == "" {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("metadataStorage").Child("name"),
d.Name,
"spec.metadataStorage.name can not be empty when d.Spec.MetadataStorage.ExternallyManaged is true"))
}
"spec.metadataStorage.name can not be empty"))
}
if d.Spec.MetadataStorage.Namespace == "" {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("metadataStorage").Child("namespace"),
d.Name,
"spec.metadataStorage.namespace can not be empty"))
}

if d.Spec.ZookeeperRef.Name == "" {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("zookeeperRef").Child("name"),
d.Name,
"spec.zookeeperRef.name can not be empty"))
}
if d.Spec.ZookeeperRef.Namespace == "" {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("zookeeperRef").Child("namespace"),
d.Name,
"spec.zookeeperRef.namespace can not be empty"))
}

if d.Spec.Topology == nil {
Expand Down

0 comments on commit c57d4c2

Please sign in to comment.