From 960b3ee73614779a9c5bd6e7c595999037a7ffd6 Mon Sep 17 00:00:00 2001 From: SK Ali Arman Date: Thu, 8 Aug 2024 11:27:14 +0600 Subject: [PATCH] refactor Signed-off-by: SK Ali Arman --- apis/kubedb/v1alpha2/clickhouse_helpers.go | 7 +++---- apis/kubedb/v1alpha2/clickhouse_webhook.go | 7 +------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/apis/kubedb/v1alpha2/clickhouse_helpers.go b/apis/kubedb/v1alpha2/clickhouse_helpers.go index 96bf73b03..4ec167764 100644 --- a/apis/kubedb/v1alpha2/clickhouse_helpers.go +++ b/apis/kubedb/v1alpha2/clickhouse_helpers.go @@ -124,7 +124,7 @@ func (c *ClickHouse) OffshootSelectors(extraSelectors ...map[string]string) map[ func (c *ClickHouse) OffshootKeeperSelectors(extraSelectors ...map[string]string) map[string]string { selector := map[string]string{ meta_util.NameLabelKey: c.ResourceFQN(), - meta_util.InstanceLabelKey: c.OffshootKeeperName(), + meta_util.InstanceLabelKey: c.Name, meta_util.ManagedByLabelKey: kubedb.GroupName, } return meta_util.OverwriteKeys(selector, extraSelectors...) @@ -314,7 +314,6 @@ func (c *ClickHouse) SetDefaults() { apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResources) } } - } else { if c.Spec.Replicas == nil { c.Spec.Replicas = pointer.Int32P(1) @@ -334,8 +333,8 @@ func (c *ClickHouse) SetDefaults() { if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) { apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResources) } - c.SetHealthCheckerDefaults() } + c.SetHealthCheckerDefaults() } func (c *ClickHouse) setDefaultContainerSecurityContext(chVersion *catalog.ClickHouseVersion, podTemplate *ofst.PodTemplateSpec) { @@ -439,7 +438,7 @@ func (c *ClickHouse) ReplicasAreReady(lister pslister.PetSetLister) (bool, strin } if !c.Spec.ClusterTopology.ClickHouseKeeper.ExternallyManaged { if c.Spec.ClusterTopology.ClickHouseKeeper.Spec.Replicas != nil { - expectedItems += int(*c.Spec.ClusterTopology.ClickHouseKeeper.Spec.Replicas) + expectedItems += 1 } } } else { diff --git a/apis/kubedb/v1alpha2/clickhouse_webhook.go b/apis/kubedb/v1alpha2/clickhouse_webhook.go index 42dee859f..b6d445a6e 100644 --- a/apis/kubedb/v1alpha2/clickhouse_webhook.go +++ b/apis/kubedb/v1alpha2/clickhouse_webhook.go @@ -111,7 +111,7 @@ func (r *ClickHouse) ValidateCreateOrUpdate() error { r.Name, "number of replica can not be 0 or less")) } - allErr = r.validateStandaloneStorageType(r.Spec.ClusterTopology.ClickHouseKeeper.Spec.StorageType, r.Spec.ClusterTopology.ClickHouseKeeper.Spec.Storage, allErr) + allErr = r.validateClickHouseKeeperStorageType(r.Spec.ClusterTopology.ClickHouseKeeper.Spec.StorageType, r.Spec.ClusterTopology.ClickHouseKeeper.Spec.Storage, allErr) } } else { if r.Spec.ClusterTopology.ClickHouseKeeper.Node.Host == "" { @@ -257,10 +257,6 @@ func (c *ClickHouse) validateClusterStorageType(cluster ClusterSpec, allErr fiel } func (c *ClickHouse) validateClickHouseKeeperStorageType(storageType StorageType, storage *core.PersistentVolumeClaimSpec, allErr field.ErrorList) field.ErrorList { - allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("clusterTopology").Child("clickHouseKeeper").Child("spec").Child("storageType"), - c.Name, - "number of replica can not be 0 or less")) - if storageType == "" { allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("clusterTopology").Child("clickHouseKeeper").Child("spec").Child("storageType"), c.Name, @@ -272,7 +268,6 @@ func (c *ClickHouse) validateClickHouseKeeperStorageType(storageType StorageType "StorageType should be either durable or ephemeral")) } } - if storage == nil && c.Spec.StorageType == StorageTypeDurable { allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("clusterTopology").Child("clickHouseKeeper").Child("spec").Child("storage"), c.Name,