Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: SK Ali Arman <[email protected]>
  • Loading branch information
sheikh-arman committed Aug 15, 2024
1 parent 823d016 commit 960b3ee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
7 changes: 3 additions & 4 deletions apis/kubedb/v1alpha2/clickhouse_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions apis/kubedb/v1alpha2/clickhouse_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 960b3ee

Please sign in to comment.