Skip to content

Commit

Permalink
dev: generalize namer
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsingerus committed May 16, 2024
1 parent 05c72d2 commit e856514
Show file tree
Hide file tree
Showing 36 changed files with 997 additions and 722 deletions.
4 changes: 2 additions & 2 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# CH_PASSWORD_PLAIN=
# CH_CREDENTIALS_SECRET_NAMESPACE=
# CH_CREDENTIALS_SECRET_NAME=clickhouse-operator
# VERBOSITY=1
# VERBOSITY=2

################################################
##
Expand Down Expand Up @@ -348,7 +348,7 @@ pod:
logger:
logtostderr: "true"
alsologtostderr: "false"
v: "1"
v: "2"
stderrthreshold: ""
vmodule: ""
log_backtrace_at: ""
4 changes: 2 additions & 2 deletions deploy/operator/clickhouse-operator-install-ansible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3451,7 +3451,7 @@ data:
# CH_PASSWORD_PLAIN=
# CH_CREDENTIALS_SECRET_NAMESPACE=
# CH_CREDENTIALS_SECRET_NAME=clickhouse-operator
# VERBOSITY=1
# VERBOSITY=2
################################################
##
Expand Down Expand Up @@ -3788,7 +3788,7 @@ data:
logger:
logtostderr: "true"
alsologtostderr: "false"
v: "1"
v: "2"
stderrthreshold: ""
vmodule: ""
log_backtrace_at: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3400,7 +3400,7 @@ data:
# CH_PASSWORD_PLAIN=
# CH_CREDENTIALS_SECRET_NAMESPACE=
# CH_CREDENTIALS_SECRET_NAME=clickhouse-operator
# VERBOSITY=1
# VERBOSITY=2
################################################
##
Expand Down Expand Up @@ -3737,7 +3737,7 @@ data:
logger:
logtostderr: "true"
alsologtostderr: "false"
v: "1"
v: "2"
stderrthreshold: ""
vmodule: ""
log_backtrace_at: ""
Expand Down
4 changes: 2 additions & 2 deletions deploy/operator/clickhouse-operator-install-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3444,7 +3444,7 @@ data:
# CH_PASSWORD_PLAIN=
# CH_CREDENTIALS_SECRET_NAMESPACE=
# CH_CREDENTIALS_SECRET_NAME=clickhouse-operator
# VERBOSITY=1
# VERBOSITY=2
################################################
##
Expand Down Expand Up @@ -3781,7 +3781,7 @@ data:
logger:
logtostderr: "true"
alsologtostderr: "false"
v: "1"
v: "2"
stderrthreshold: ""
vmodule: ""
log_backtrace_at: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3400,7 +3400,7 @@ data:
# CH_PASSWORD_PLAIN=
# CH_CREDENTIALS_SECRET_NAMESPACE=
# CH_CREDENTIALS_SECRET_NAME=clickhouse-operator
# VERBOSITY=1
# VERBOSITY=2
################################################
##
Expand Down Expand Up @@ -3737,7 +3737,7 @@ data:
logger:
logtostderr: "true"
alsologtostderr: "false"
v: "1"
v: "2"
stderrthreshold: ""
vmodule: ""
log_backtrace_at: ""
Expand Down
4 changes: 2 additions & 2 deletions deploy/operator/clickhouse-operator-install-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3444,7 +3444,7 @@ data:
# CH_PASSWORD_PLAIN=
# CH_CREDENTIALS_SECRET_NAMESPACE=
# CH_CREDENTIALS_SECRET_NAME=clickhouse-operator
# VERBOSITY=1
# VERBOSITY=2
################################################
##
Expand Down Expand Up @@ -3781,7 +3781,7 @@ data:
logger:
logtostderr: "true"
alsologtostderr: "false"
v: "1"
v: "2"
stderrthreshold: ""
vmodule: ""
log_backtrace_at: ""
Expand Down
4 changes: 2 additions & 2 deletions deploy/operator/clickhouse-operator-install-tf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3451,7 +3451,7 @@ data:
# CH_PASSWORD_PLAIN=
# CH_CREDENTIALS_SECRET_NAMESPACE=
# CH_CREDENTIALS_SECRET_NAME=clickhouse-operator
# VERBOSITY=1
# VERBOSITY=2
################################################
##
Expand Down Expand Up @@ -3788,7 +3788,7 @@ data:
logger:
logtostderr: "true"
alsologtostderr: "false"
v: "1"
v: "2"
stderrthreshold: ""
vmodule: ""
log_backtrace_at: ""
Expand Down
20 changes: 10 additions & 10 deletions pkg/controller/chi/deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (c *Controller) deleteConfigMapsCHI(ctx context.Context, chi *api.ClickHous

var err error

configMapCommon := namer.CreateConfigMapCommonName(chi)
configMapCommonUsersName := namer.CreateConfigMapCommonUsersName(chi)
configMapCommon := namer.Name(namer.NameConfigMapCommon, chi)
configMapCommonUsersName := namer.Name(namer.NameConfigMapCommonUsers, chi)

// Delete ConfigMap
err = c.kubeClient.CoreV1().ConfigMaps(chi.Namespace).Delete(ctx, configMapCommon, controller.NewDeleteOptions())
Expand Down Expand Up @@ -95,7 +95,7 @@ func (c *Controller) statefulSetDeletePod(ctx context.Context, statefulSet *apps
return nil
}

name := namer.CreatePodName(statefulSet)
name := namer.Name(namer.NamePod, statefulSet)
log.V(1).M(host).Info("Delete Pod %s/%s", statefulSet.Namespace, name)
err := c.kubeClient.CoreV1().Pods(statefulSet.Namespace).Delete(ctx, name, controller.NewDeleteOptions())
if err == nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (c *Controller) deleteStatefulSet(ctx context.Context, host *api.Host) erro
// it is possible to scale the StatefulSet down to 0 prior to deletion.

// Namespaced name
name := namer.CreateStatefulSetName(host)
name := namer.Name(namer.NameStatefulSet, host)
namespace := host.Runtime.Address.Namespace
log.V(1).M(host).F().Info("%s/%s", namespace, name)

Expand Down Expand Up @@ -229,7 +229,7 @@ func (c *Controller) deleteConfigMap(ctx context.Context, host *api.Host) error
return nil
}

name := namer.CreateConfigMapHostName(host)
name := namer.Name(namer.NameConfigMapHost, host)
namespace := host.Runtime.Address.Namespace
log.V(1).M(host).F().Info("%s/%s", namespace, name)

Expand Down Expand Up @@ -263,7 +263,7 @@ func (c *Controller) deleteServiceHost(ctx context.Context, host *api.Host) erro
return nil
}

serviceName := namer.CreateStatefulSetServiceName(host)
serviceName := namer.Name(namer.NameStatefulSetService, host)
namespace := host.Runtime.Address.Namespace
log.V(1).M(host).F().Info("%s/%s", namespace, serviceName)
return c.deleteServiceIfExists(ctx, namespace, serviceName)
Expand All @@ -276,7 +276,7 @@ func (c *Controller) deleteServiceShard(ctx context.Context, shard *api.ChiShard
return nil
}

serviceName := namer.CreateShardServiceName(shard)
serviceName := namer.Name(namer.NameShardService, shard)
namespace := shard.Runtime.Address.Namespace
log.V(1).M(shard).F().Info("%s/%s", namespace, serviceName)
return c.deleteServiceIfExists(ctx, namespace, serviceName)
Expand All @@ -289,7 +289,7 @@ func (c *Controller) deleteServiceCluster(ctx context.Context, cluster *api.Clus
return nil
}

serviceName := namer.CreateClusterServiceName(cluster)
serviceName := namer.Name(namer.NameClusterService, cluster)
namespace := cluster.Runtime.Address.Namespace
log.V(1).M(cluster).F().Info("%s/%s", namespace, serviceName)
return c.deleteServiceIfExists(ctx, namespace, serviceName)
Expand All @@ -302,7 +302,7 @@ func (c *Controller) deleteServiceCHI(ctx context.Context, chi *api.ClickHouseIn
return nil
}

serviceName := namer.CreateCHIServiceName(chi)
serviceName := namer.Name(namer.NameCHIService, chi)
namespace := chi.Namespace
log.V(1).M(chi).F().Info("%s/%s", namespace, serviceName)
return c.deleteServiceIfExists(ctx, namespace, serviceName)
Expand Down Expand Up @@ -342,7 +342,7 @@ func (c *Controller) deleteSecretCluster(ctx context.Context, cluster *api.Clust
return nil
}

secretName := namer.CreateClusterAutoSecretName(cluster)
secretName := namer.Name(namer.NameClusterAutoSecret, cluster)
namespace := cluster.Runtime.Address.Namespace
log.V(1).M(cluster).F().Info("%s/%s", namespace, secretName)
return c.deleteSecretIfExists(ctx, namespace, secretName)
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/chi/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *Controller) getService(obj interface{}) (*core.Service, error) {
name = typedObj.Name
namespace = typedObj.Namespace
case *api.Host:
name = namer.CreateStatefulSetServiceName(typedObj)
name = namer.Name(namer.NameStatefulSetService, typedObj)
namespace = typedObj.Runtime.Address.Namespace
}
return c.serviceLister.Services(namespace).Get(name)
Expand Down Expand Up @@ -165,7 +165,7 @@ func (c *Controller) getStatefulSetByMeta(meta meta.Object, byNameOnly bool) (*a
// getStatefulSetByHost finds StatefulSet of a specified host
func (c *Controller) getStatefulSetByHost(host *api.Host) (*apps.StatefulSet, error) {
// Namespaced name
name := namer.CreateStatefulSetName(host)
name := namer.Name(namer.NameStatefulSet, host)
namespace := host.Runtime.Address.Namespace

return c.kubeClient.AppsV1().StatefulSets(namespace).Get(controller.NewContext(), name, controller.NewGetOptions())
Expand All @@ -183,10 +183,10 @@ func (c *Controller) getPod(obj interface{}) (*core.Pod, error) {
var name, namespace string
switch typedObj := obj.(type) {
case *apps.StatefulSet:
name = namer.CreatePodName(obj)
name = namer.Name(namer.NamePod, obj)
namespace = typedObj.Namespace
case *api.Host:
name = namer.CreatePodName(obj)
name = namer.Name(namer.NamePod, obj)
namespace = typedObj.Runtime.Address.Namespace
}
return c.kubeClient.CoreV1().Pods(namespace).Get(controller.NewContext(), name, controller.NewGetOptions())
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/chi/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func (c *Controller) walkPVCs(host *api.Host, f func(pvc *core.PersistentVolumeClaim)) {
namespace := host.Runtime.Address.Namespace
name := namer.CreatePodName(host)
name := namer.Name(namer.NamePod, host)
pod, err := c.kubeClient.CoreV1().Pods(namespace).Get(controller.NewContext(), name, controller.NewGetOptions())
if err != nil {
log.M(host).F().Error("FAIL get pod for host %s/%s err:%v", namespace, host.GetName(), err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/chi/worker-chi-reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func (w *worker) reconcileCluster(ctx context.Context, cluster *api.Cluster) err

// Add ChkCluster's Auto Secret
if cluster.Secret.Source() == api.ClusterSecretSourceAuto {
if secret := w.task.creator.CreateClusterSecret(namer.CreateClusterAutoSecretName(cluster)); secret != nil {
if secret := w.task.creator.CreateClusterSecret(namer.Name(namer.NameClusterAutoSecret, cluster)); secret != nil {
if err := w.reconcileSecret(ctx, cluster.Runtime.CHI, secret); err == nil {
w.task.registryReconciled.RegisterSecret(secret.GetObjectMeta())
} else {
Expand Down Expand Up @@ -1211,7 +1211,7 @@ func (w *worker) fetchPVC(
// No this is not a reference to VolumeClaimTemplate, it may be reference to ConfigMap
return nil, nil, false, fmt.Errorf("unable to find VolumeClaimTemplate from volume mount")
}
pvcName := namer.CreatePVCNameByVolumeClaimTemplate(host, volumeClaimTemplate)
pvcName := namer.Name(namer.NamePVCNameByVolumeClaimTemplate, host, volumeClaimTemplate)

// We have a VolumeClaimTemplate for this VolumeMount
// Treat it as persistent storage mount
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/chi/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func (w *worker) walkHosts(ctx context.Context, chi *api.ClickHouseInstallation,
cluster.WalkHosts(func(host *api.Host) error {

// Name of the StatefulSet for this host
name := namer.CreateStatefulSetName(host)
name := namer.Name(namer.NameStatefulSet, host)
// Have we found this StatefulSet
found := false

Expand Down Expand Up @@ -948,7 +948,7 @@ func (w *worker) migrateTables(ctx context.Context, host *api.Host, opts ...*mig
M(host).F().
Info("Tables added successfully on shard/host:%d/%d cluster:%s",
host.Runtime.Address.ShardIndex, host.Runtime.Address.ReplicaIndex, host.Runtime.Address.ClusterName)
host.GetCR().EnsureStatus().PushHostTablesCreated(namer.CreateFQDN(host))
host.GetCR().EnsureStatus().PushHostTablesCreated(namer.Name(namer.NameFQDN, host))
} else {
w.a.V(1).
WithEvent(host.GetCR(), eventActionCreate, eventReasonCreateFailed).
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/chi/config/ch_config_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (c *ClickHouseConfigGenerator) getHostMacros(host *api.Host) string {
util.Iline(b, 8, "<shard>%s</shard>", host.Runtime.Address.ShardName)
// <replica>replica id = full deployment id</replica>
// full deployment id is unique to identify replica within the cluster
util.Iline(b, 8, "<replica>%s</replica>", namer.CreatePodHostname(host))
util.Iline(b, 8, "<replica>%s</replica>", namer.Name(namer.NamePodHostname, host))

// </macros>
// </yandex>
Expand Down Expand Up @@ -489,7 +489,7 @@ func (c *ClickHouseConfigGenerator) getDistributedDDLPath() string {
// getRemoteServersReplicaHostname returns hostname (podhostname + service or FQDN) for "remote_servers.xml"
// based on .Spec.Defaults.ReplicasUseFQDN
func (c *ClickHouseConfigGenerator) getRemoteServersReplicaHostname(host *api.Host) string {
return namer.CreateInstanceHostname(host)
return namer.Name(namer.NameInstanceHostname, host)
}

// getSecure gets config-usable value for host or node secure flag
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/chi/creator/config_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *Creator) CreateConfigMap(what ConfigMapType, params ...any) *core.Confi
func (c *Creator) createConfigMapCHICommon(options *config.ClickHouseConfigFilesGeneratorOptions) *core.ConfigMap {
cm := &core.ConfigMap{
ObjectMeta: meta.ObjectMeta{
Name: namer.CreateConfigMapCommonName(c.cr),
Name: namer.Name(namer.NameConfigMapCommon, c.cr),
Namespace: c.cr.GetNamespace(),
Labels: namer.Macro(c.cr).Map(c.tagger.Label(tags.LabelConfigMapCommon)),
Annotations: namer.Macro(c.cr).Map(c.tagger.Annotate(tags.AnnotateConfigMapCommon)),
Expand All @@ -75,7 +75,7 @@ func (c *Creator) createConfigMapCHICommon(options *config.ClickHouseConfigFiles
func (c *Creator) createConfigMapCHICommonUsers() *core.ConfigMap {
cm := &core.ConfigMap{
ObjectMeta: meta.ObjectMeta{
Name: namer.CreateConfigMapCommonUsersName(c.cr),
Name: namer.Name(namer.NameConfigMapCommonUsers, c.cr),
Namespace: c.cr.GetNamespace(),
Labels: namer.Macro(c.cr).Map(c.tagger.Label(tags.LabelConfigMapCommonUsers)),
Annotations: namer.Macro(c.cr).Map(c.tagger.Annotate(tags.AnnotateConfigMapCommonUsers)),
Expand All @@ -93,7 +93,7 @@ func (c *Creator) createConfigMapCHICommonUsers() *core.ConfigMap {
func (c *Creator) createConfigMapCHIHost(host *api.Host) *core.ConfigMap {
cm := &core.ConfigMap{
ObjectMeta: meta.ObjectMeta{
Name: namer.CreateConfigMapHostName(host),
Name: namer.Name(namer.NameConfigMapHost, host),
Namespace: host.GetRuntime().GetAddress().GetNamespace(),
Labels: namer.Macro(host).Map(c.tagger.Label(tags.LabelConfigMapHost, host)),
Annotations: namer.Macro(host).Map(c.tagger.Annotate(tags.AnnotateConfigMapHost, host)),
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/chi/creator/pod_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func newDefaultPodTemplate(host *api.Host) *api.PodTemplate {
// newDefaultClickHousePodTemplate returns default Pod Template to be used with StatefulSet
func newDefaultClickHousePodTemplate(host *api.Host) *api.PodTemplate {
podTemplate := &api.PodTemplate{
Name: namer.CreateStatefulSetName(host),
Name: namer.Name(namer.NameStatefulSet, host),
Spec: core.PodSpec{
Containers: []core.Container{},
Volumes: []core.Volume{},
Expand Down
12 changes: 6 additions & 6 deletions pkg/model/chi/creator/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *Creator) createServiceCHI() *core.Service {
return c.createServiceFromTemplate(
template,
c.cr.GetNamespace(),
namer.CreateCHIServiceName(c.cr),
namer.Name(namer.NameCHIService, c.cr),
c.tagger.Label(tags.LabelServiceCHI, c.cr),
c.tagger.Annotate(tags.AnnotateServiceCHI, c.cr),
c.tagger.Selector(tags.SelectorCHIScopeReady),
Expand All @@ -85,7 +85,7 @@ func (c *Creator) createServiceCHI() *core.Service {
// We do not have .templates.ServiceTemplate specified or it is incorrect
svc := &core.Service{
ObjectMeta: meta.ObjectMeta{
Name: namer.CreateCHIServiceName(c.cr),
Name: namer.Name(namer.NameCHIService, c.cr),
Namespace: c.cr.GetNamespace(),
Labels: namer.Macro(c.cr).Map(c.tagger.Label(tags.LabelServiceCHI, c.cr)),
Annotations: namer.Macro(c.cr).Map(c.tagger.Annotate(tags.AnnotateServiceCHI, c.cr)),
Expand Down Expand Up @@ -118,7 +118,7 @@ func (c *Creator) createServiceCHI() *core.Service {

// createServiceCluster creates new core.Service for specified Cluster
func (c *Creator) createServiceCluster(cluster api.ICluster) *core.Service {
serviceName := namer.CreateClusterServiceName(cluster)
serviceName := namer.Name(namer.NameClusterService, cluster)
ownerReferences := createOwnerReferences(c.cr)

c.a.V(1).F().Info("%s/%s", cluster.GetRuntime().GetAddress().GetNamespace(), serviceName)
Expand Down Expand Up @@ -146,7 +146,7 @@ func (c *Creator) createServiceShard(shard api.IShard) *core.Service {
return c.createServiceFromTemplate(
template,
shard.GetRuntime().GetAddress().GetNamespace(),
namer.CreateShardServiceName(shard),
namer.Name(namer.NameShardService, shard),
c.tagger.Label(tags.LabelServiceShard, shard),
c.tagger.Annotate(tags.AnnotateServiceShard, shard),
c.tagger.Selector(tags.SelectorShardScopeReady, shard),
Expand All @@ -165,7 +165,7 @@ func (c *Creator) createServiceHost(host *api.Host) *core.Service {
return c.createServiceFromTemplate(
template,
host.Runtime.Address.Namespace,
namer.CreateStatefulSetServiceName(host),
namer.Name(namer.NameStatefulSetService, host),
c.tagger.Label(tags.LabelServiceHost, host),
c.tagger.Annotate(tags.AnnotateServiceHost, host),
c.tagger.Selector(tags.SelectorHostScope, host),
Expand All @@ -178,7 +178,7 @@ func (c *Creator) createServiceHost(host *api.Host) *core.Service {
// We do not have .templates.ServiceTemplate specified or it is incorrect
svc := &core.Service{
ObjectMeta: meta.ObjectMeta{
Name: namer.CreateStatefulSetServiceName(host),
Name: namer.Name(namer.NameStatefulSetService, host),
Namespace: host.Runtime.Address.Namespace,
Labels: namer.Macro(host).Map(c.tagger.Label(tags.LabelServiceHost, host)),
Annotations: namer.Macro(host).Map(c.tagger.Annotate(tags.AnnotateServiceHost, host)),
Expand Down

0 comments on commit e856514

Please sign in to comment.