8000 Enhance CHK reconciliation and normalization features by perosb · Pull Request #1885 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/apis/clickhouse-keeper.altinity.com/v1/type_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ func (cluster *Cluster) GetAncestor() apiChi.ICluster {
return (*Cluster)(nil)
}

// InheritClusterReconcileFrom inherits reconcile settings from CHK CR
func (cluster *Cluster) InheritClusterReconcileFrom(chk *ClickHouseKeeperInstallation) {
if chk.Spec.Reconcile == nil {
return
}
cluster.Reconcile.Runtime = cluster.Reconcile.Runtime.MergeFrom(chk.Spec.Reconcile.Runtime, apiChi.MergeTypeFillEmptyValues)
cluster.Reconcile.Host = cluster.Reconcile.Host.MergeFrom(chk.Spec.Reconcile.Host)
}

// GetShard gets shard with specified index
func (cluster *Cluster) GetShard(shard int) *ChkShard {
return cluster.Layout.Shards[shard]
Expand Down
19 changes: 19 additions & 0 deletions pkg/controller/chk/worker-reconciler-chk.go
8000
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,30 @@ func (w *worker) reconcileConfigMapHost(ctx context.Context, host *api.Host) err
return nil
}

// prepareStsReconcileOptsWaitSection prepares StatefulSet reconcile options with wait settings
func (w *worker) prepareStsReconcileOptsWaitSection(host *api.Host, opts *statefulset.ReconcileOptions) *statefulset.ReconcileOptions {
if host.GetCluster().GetReconcile().Host.Wait.Probes.GetStartup().IsTrue() {
opts = opts.SetWaitUntilStarted()
w.a.V(1).
M(host).F().
Warning("Setting option SetWaitUntilStarted ")
}
if host.GetCluster().GetReconcile().Host.Wait.Probes.GetReadiness().IsTrue() {
opts = opts.SetWaitUntilReady()
w.a.V(1).
M(host).F().
Warning("Setting option SetWaitUntilReady")
}
return opts
}

// reconcileHostStatefulSet reconciles host's StatefulSet
func (w *worker) reconcileHostStatefulSet(ctx context.Context, host *api.Host, opts *statefulset.ReconcileOptions) error {
log.V(1).M(host).F().S().Info("reconcile StatefulSet start")
defer log.V(1).M(host).F().E().Info("reconcile StatefulSet end")

opts = w.prepareStsReconcileOptsWaitSection(host, opts)

version := w.getHostSoftwareVersion(ctx, host)
host.Runtime.CurStatefulSet, _ = w.c.kube.STS().Get(ctx, host)

Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/common/poller/domain/poller-host-objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func (p *HostObjectsPoller) WaitHostStatefulSetReady(ctx context.Context, host *
if sts == nil {
return false
}
_ = p.readyMarkDeleter.DeleteReadyMarkOnPodAndService(_ctx, host)
if p.readyMarkDeleter != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check default deleter behavior

_ = p.readyMarkDeleter.DeleteReadyMarkOnPodAndService(_ctx, host)
}
return k8s.IsStatefulSetReconcileCompleted(sts)
},
)
Expand Down
11 changes: 10 additions & 1 deletion pkg/model/chk/normalizer/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,16 @@ func (n *Normalizer) normalizeReconcile(reconcile *chi.ChiReconcile) *chi.ChiRec
// No normalization yet

// Host
// No normalization yet
reconcile.Host = n.normalizeReconcileHost(reconcile.Host)
return reconcile
}

func (n *Normalizer) normalizeReconcileHost(rh chi.ReconcileHost) chi.ReconcileHost {
// Normalize
rh = rh.Normalize()
return rh
}

func (n *Normalizer) normalizeReconcileCleanup(cleanup *chi.Cleanup) *chi.Cleanup {
if cleanup == nil {
cleanup = chi.NewCleanup()
Expand Down Expand Up @@ -520,6 +526,9 @@ func (n *Normalizer) normalizeClusterStage1(cluster *chk.Cluster) *chk.Cluster {
// Runtime has to be prepared first
cluster.GetRuntime().SetCR(n.req.GetTarget())

// Inherit reconcile settings from CR
cluster.InheritClusterReconcileFrom(n.req.GetTarget())

n.normalizeClusterLayout(cluster)

// Loop over all shards and replicas inside shards and fill structure
Expand Down
13 changes: 13 additions & 0 deletions pkg/model/common/macro/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package macro
import (
"strconv"

apiChk "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse-keeper.altinity.com/v1"
api "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse.altinity.com/v1"
"github.com/altinity/clickhouse-operator/pkg/apis/common/types"
"github.com/altinity/clickhouse-operator/pkg/interfaces"
Expand Down Expand Up @@ -68,6 +69,8 @@ func (e *Engine) Replacer() *util.Replacer {
return e.newReplacerCR(t)
case api.ICluster:
return e.newReplacerCluster(t)
case *apiChk.Cluster:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is ICluster interface that covers this functionality. No need to duplicate code. If there are doubts on applicability with CHK - ensure ICluster compatibility

return e.newReplacerCHKCluster(t)
case api.IShard:
return e.newReplacerShard(t)
case api.IReplica:
Expand Down Expand Up @@ -105,6 +108,16 @@ func (e *Engine) newReplacerCluster(cluster api.ICluster) *util.Replacer {
})
}

// newReplacerCHKCluster
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code duplication?

func (e *Engine) newReplacerCHKCluster(cluster *apiChk.Cluster) *util.Replacer {
return util.NewReplacer(map[string]string{
e.Get(MacrosNamespace): e.namer.Name(short.Namespace, cluster),
e.Get(MacrosCRName): e.namer.Name(short.CRName, cluster),
e.Get(MacrosClusterName): e.namer.Name(short.ClusterName, cluster),
e.Get(MacrosClusterIndex): strconv.Itoa(cluster.GetRuntime().GetAddress().GetClusterIndex()),
})
}

// newReplacerShard
func (e *Engine) newReplacerShard(shard api.IShard) *util.Replacer {
return util.NewReplacer(map[string]string{
Expand Down
10 changes: 10 additions & 0 deletions pkg/model/common/namer/short/namer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strconv"
"strings"

apiChk "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse-keeper.altinity.com/v1"
api "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse.altinity.com/v1"
"github.com/altinity/clickhouse-operator/pkg/util"
)
Expand Down Expand Up @@ -132,6 +133,9 @@ func (n *Namer) getNamePartNamespace(obj interface{}) string {
case api.ICluster:
cluster := obj.(api.ICluster)
return n.namePartCRName(cluster.GetRuntime().GetAddress().GetNamespace())
case *apiChk.Cluster:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same - interface is for a reason

cluster := obj.(*apiChk.Cluster)
return n.namePartCRName(cluster.GetRuntime().GetAddress().GetNamespace())
case api.IShard:
shard := obj.(api.IShard)
return n.namePartCRName(shard.GetRuntime().GetAddress().GetNamespace())
Expand All @@ -152,6 +156,9 @@ func (n *Namer) getNamePartCRName(obj interface{}) string {
case api.ICluster:
cluster := obj.(api.ICluster)
return n.namePartCRName(cluster.GetRuntime().GetAddress().GetCRName())
case *apiChk.Cluster:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same - interface use

cluster := obj.(*apiChk.Cluster)
return n.namePartCRName(cluster.GetRuntime().GetAddress().GetCRName())
case api.IShard:
shard := obj.(api.IShard)
return n.namePartCRName(shard.GetRuntime().GetAddress().GetCRName())
Expand All @@ -169,6 +176,9 @@ func (n *Namer) getNamePartClusterName(obj interface{}) string {
case api.ICluster:
cluster := obj.(api.ICluster)
return n.namePartClusterName(cluster.GetRuntime().GetAddress().GetClusterName())
case *apiChk.Cluster:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same - interface

cluster := obj.(*apiChk.Cluster)
return n.namePartClusterName(cluster.GetRuntime().GetAddress().GetClusterName())
case api.IShard:
shard := obj.(api.IShard)
return n.namePartClusterName(shard.GetRuntime().GetAddress().GetClusterName())
Expand Down
0