From fc8f06b5f19ebc164416d1422d0bcfa7b18b01c4 Mon Sep 17 00:00:00 2001 From: Tapajit Chandra Paul Date: Thu, 1 Aug 2024 18:27:31 +0600 Subject: [PATCH] Test and fix druid for webhook changes Signed-off-by: Tapajit Chandra Paul --- apis/kubedb/v1alpha2/druid_helpers.go | 16 ++++++++-------- apis/kubedb/v1alpha2/druid_webhook.go | 26 ++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/apis/kubedb/v1alpha2/druid_helpers.go b/apis/kubedb/v1alpha2/druid_helpers.go index 3fa0c9a7a1..45fd8c6650 100644 --- a/apis/kubedb/v1alpha2/druid_helpers.go +++ b/apis/kubedb/v1alpha2/druid_helpers.go @@ -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" } @@ -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 @@ -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 { @@ -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 { diff --git a/apis/kubedb/v1alpha2/druid_webhook.go b/apis/kubedb/v1alpha2/druid_webhook.go index cf62fbf719..f8fa2b1a7a 100644 --- a/apis/kubedb/v1alpha2/druid_webhook.go +++ b/apis/kubedb/v1alpha2/druid_webhook.go @@ -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")) } }