Skip to content

Commit

Permalink
Test and fix druid for webhook changes
Browse files Browse the repository at this point in the history
Signed-off-by: Tapajit Chandra Paul <[email protected]>
  • Loading branch information
tapojit047 committed Aug 1, 2024
1 parent a19a7f3 commit fc8f06b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
16 changes: 8 additions & 8 deletions apis/kubedb/v1alpha2/druid_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (d *Druid) SetDefaultsToMetadataStorage() {
if d.Spec.MetadataStorage == nil {
d.Spec.MetadataStorage = &MetadataStorage{}
}
d.Spec.MetadataStorage.ObjectReference = d.GetMetadataStorageObjectRef()
d.SetMetadataStorageObjectRef()
if d.Spec.MetadataStorage.LinkedDB == "" {
d.Spec.MetadataStorage.LinkedDB = "druid"
}
Expand Down Expand Up @@ -564,7 +564,7 @@ func (d *Druid) SetDefaultsToZooKeeperRef() {
if d.Spec.ZookeeperRef == nil {
d.Spec.ZookeeperRef = &ZookeeperRef{}
}
d.Spec.ZookeeperRef.ObjectReference = d.GetZooKeeperObjectRef()
d.SetZooKeeperObjectRef()
if d.Spec.ZookeeperRef.Version == nil {
defaultVersion := "3.7.2"
d.Spec.ZookeeperRef.Version = &defaultVersion
Expand Down Expand Up @@ -685,17 +685,17 @@ func (d *Druid) GetAppBinding(name string, namespace string) (*appcat.AppBinding
return appbinding, nil
}

func (d *Druid) GetMetadataStorageObjectRef() *kmapi.ObjectReference {
if d.Spec.MetadataStorage == 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
}
return d.Spec.MetadataStorage.ObjectReference
}

func (d *Druid) GetMetadataStorageName() string {
Expand All @@ -705,17 +705,17 @@ func (d *Druid) GetMetadataStorageName() string {
return d.OffShootName() + "-mysql-metadata"
}

func (d *Druid) GetZooKeeperObjectRef() *kmapi.ObjectReference {
if d.Spec.ZookeeperRef == nil {
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
}
return d.Spec.ZookeeperRef.ObjectReference
}

func (d *Druid) GetZooKeeperName() string {
Expand Down
26 changes: 24 additions & 2 deletions apis/kubedb/v1alpha2/druid_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,32 @@ func (d *Druid) validateCreateOrUpdate() field.ErrorList {
d.Name,
"spec.metadataStorage is missing"))
} else {
if d.Spec.MetadataStorage.ExternallyManaged && d.Spec.MetadataStorage.Name == "" {
if 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 == nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("zookeeperRef"),
d.Name,
"spec.zookeeperRef is missing"))
} else {
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"))
}
}

Expand Down

0 comments on commit fc8f06b

Please sign in to comment.