Skip to content

Commit 65f4244

Browse files
committed
Enhance CHK reconciliation and normalization features
- Implement InheritClusterReconcileFrom method to inherit reconcile settings from ClickHouseKeeperInstallation. - Add prepareStsReconcileOptsWaitSection to set StatefulSet reconcile options based on readiness and startup probes. - Normalize reconcile host settings in the normalizer. - Update HostObjectsPoller to safely delete ready marks only if readyMarkDeleter is initialized. - Introduce new replacer for CHK clusters in the engine. - Extend namer functionality to handle CHK clusters. Fixes #1796 Signed-off-by: Per Osbäck <[email protected]>
1 parent 3d8d1ea commit 65f4244

File tree

6 files changed

+64
-2
lines changed

6 files changed

+64
-2
lines changed

pkg/apis/clickhouse-keeper.altinity.com/v1/type_cluster.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ func (cluster *Cluster) GetAncestor() apiChi.ICluster {
224224
return (*Cluster)(nil)
225225
}
226226

227+
// InheritClusterReconcileFrom inherits reconcile settings from CHK CR
228+
func (cluster *Cluster) InheritClusterReconcileFrom(chk *ClickHouseKeeperInstallation) {
229+
if chk.Spec.Reconcile == nil {
230+
return
231+
}
232+
cluster.Reconcile.Runtime = cluster.Reconcile.Runtime.MergeFrom(chk.Spec.Reconcile.Runtime, apiChi.MergeTypeFillEmptyValues)
233+
cluster.Reconcile.Host = cluster.Reconcile.Host.MergeFrom(chk.Spec.Reconcile.Host)
234+
}
235+
227236
// GetShard gets shard with specified index
228237
func (cluster *Cluster) GetShard(shard int) *ChkShard {
229238
return cluster.Layout.Shards[shard]

pkg/controller/chk/worker-reconciler-chk.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,30 @@ func (w *worker) reconcileConfigMapHost(ctx context.Context, host *api.Host) err
336336
return nil
337337
}
338338

339+
// prepareStsReconcileOptsWaitSection prepares StatefulSet reconcile options with wait settings
340+
func (w *worker) prepareStsReconcileOptsWaitSection(host *api.Host, opts *statefulset.ReconcileOptions) *statefulset.ReconcileOptions {
341+
if host.GetCluster().GetReconcile().Host.Wait.Probes.GetStartup().IsTrue() {
342+
opts = opts.SetWaitUntilStarted()
343+
w.a.V(1).
344+
M(host).F().
345+
Warning("Setting option SetWaitUntilStarted ")
346+
}
347+
if host.GetCluster().GetReconcile().Host.Wait.Probes.GetReadiness().IsTrue() {
348+
opts = opts.SetWaitUntilReady()
349+
w.a.V(1).
350+
M(host).F().
351+
Warning("Setting option SetWaitUntilReady")
352+
}
353+
return opts
354+
}
355+
339356
// reconcileHostStatefulSet reconciles host's StatefulSet
340357
func (w *worker) reconcileHostStatefulSet(ctx context.Context, host *api.Host, opts *statefulset.ReconcileOptions) error {
341358
log.V(1).M(host).F().S().Info("reconcile StatefulSet start")
342359
defer log.V(1).M(host).F().E().Info("reconcile StatefulSet end")
343360

361+
opts = w.prepareStsReconcileOptsWaitSection(host, opts)
362+
344363
version := w.getHostSoftwareVersion(ctx, host)
345364
host.Runtime.CurStatefulSet, _ = w.c.kube.STS().Get(ctx, host)
346365

pkg/controller/common/poller/domain/poller-host-objects.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ func (p *HostObjectsPoller) WaitHostStatefulSetReady(ctx context.Context, host *
9999
if sts == nil {
100100
return false
101101
}
102-
_ = p.readyMarkDeleter.DeleteReadyMarkOnPodAndService(_ctx, host)
102+
if p.readyMarkDeleter != nil {
103+
_ = p.readyMarkDeleter.DeleteReadyMarkOnPodAndService(_ctx, host)
104+
}
103105
return k8s.IsStatefulSetReconcileCompleted(sts)
104106
},
105107
)

pkg/model/chk/normalizer/normalizer.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,16 @@ func (n *Normalizer) normalizeReconcile(reconcile *chi.ChiReconcile) *chi.ChiRec
340340
// No normalization yet
341341

342342
// Host
343-
// No normalization yet
343+
reconcile.Host = n.normalizeReconcileHost(reconcile.Host)
344344
return reconcile
345345
}
346346

347+
func (n *Normalizer) normalizeReconcileHost(rh chi.ReconcileHost) chi.ReconcileHost {
348+
// Normalize
349+
rh = rh.Normalize()
350+
return rh
351+
}
352+
347353
func (n *Normalizer) normalizeReconcileCleanup(cleanup *chi.Cleanup) *chi.Cleanup {
348354
if cleanup == nil {
349355
cleanup = chi.NewCleanup()
@@ -520,6 +526,9 @@ func (n *Normalizer) normalizeClusterStage1(cluster *chk.Cluster) *chk.Cluster {
520526
// Runtime has to be prepared first
521527
cluster.GetRuntime().SetCR(n.req.GetTarget())
522528

529+
// Inherit reconcile settings from CR
530+
cluster.InheritClusterReconcileFrom(n.req.GetTarget())
531+
523532
n.normalizeClusterLayout(cluster)
524533

525534
// Loop over all shards and replicas inside shards and fill structure

pkg/model/common/macro/engine.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package macro
1717
import (
1818
"strconv"
1919

20+
apiChk "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse-keeper.altinity.com/v1"
2021
api "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse.altinity.com/v1"
2122
"github.com/altinity/clickhouse-operator/pkg/apis/common/types"
2223
"github.com/altinity/clickhouse-operator/pkg/interfaces"
@@ -68,6 +69,8 @@ func (e *Engine) Replacer() *util.Replacer {
6869
return e.newReplacerCR(t)
6970
case api.ICluster:
7071
return e.newReplacerCluster(t)
72+
case *apiChk.Cluster:
73+
return e.newReplacerCHKCluster(t)
7174
case api.IShard:
7275
return e.newReplacerShard(t)
7376
case api.IReplica:
@@ -105,6 +108,16 @@ func (e *Engine) newReplacerCluster(cluster api.ICluster) *util.Replacer {
105108
})
106109
}
107110

111+
// newReplacerCHKCluster
112+
func (e *Engine) newReplacerCHKCluster(cluster *apiChk.Cluster) *util.Replacer {
113+
return util.NewReplacer(map[string]string{
114+
e.Get(MacrosNamespace): e.namer.Name(short.Namespace, cluster),
115+
e.Get(MacrosCRName): e.namer.Name(short.CRName, cluster),
116+
e.Get(MacrosClusterName): e.namer.Name(short.ClusterName, cluster),
117+
e.Get(MacrosClusterIndex): strconv.Itoa(cluster.GetRuntime().GetAddress().GetClusterIndex()),
118+
})
119+
}
120+
108121
// newReplacerShard
109122
func (e *Engine) newReplacerShard(shard api.IShard) *util.Replacer {
110123
return util.NewReplacer(map[string]string{

pkg/model/common/namer/short/namer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"strconv"
1919
"strings"
2020

21+
apiChk "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse-keeper.altinity.com/v1"
2122
api "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse.altinity.com/v1"
2223
"github.com/altinity/clickhouse-operator/pkg/util"
2324
)
@@ -132,6 +133,9 @@ func (n *Namer) getNamePartNamespace(obj interface{}) string {
132133
case api.ICluster:
133134
cluster := obj.(api.ICluster)
134135
return n.namePartCRName(cluster.GetRuntime().GetAddress().GetNamespace())
136+
case *apiChk.Cluster:
137+
cluster := obj.(*apiChk.Cluster)
138+
return n.namePartCRName(cluster.GetRuntime().GetAddress().GetNamespace())
135139
case api.IShard:
136140
shard := obj.(api.IShard)
137141
return n.namePartCRName(shard.GetRuntime().GetAddress().GetNamespace())
@@ -152,6 +156,9 @@ func (n *Namer) getNamePartCRName(obj interface{}) string {
152156
case api.ICluster:
153157
cluster := obj.(api.ICluster)
154158
return n.namePartCRName(cluster.GetRuntime().GetAddress().GetCRName())
159+
case *apiChk.Cluster:
160+
cluster := obj.(*apiChk.Cluster)
161+
return n.namePartCRName(cluster.GetRuntime().GetAddress().GetCRName())
155162
case api.IShard:
156163
shard := obj.(api.IShard)
157164
return n.namePartCRName(shard.GetRuntime().GetAddress().GetCRName())
@@ -169,6 +176,9 @@ func (n *Namer) getNamePartClusterName(obj interface{}) string {
169176
case api.ICluster:
170177
cluster := obj.(api.ICluster)
171178
return n.namePartClusterName(cluster.GetRuntime().GetAddress().GetClusterName())
179+
case *apiChk.Cluster:
180+
cluster := obj.(*apiChk.Cluster)
181+
return n.namePartClusterName(cluster.GetRuntime().GetAddress().GetClusterName())
172182
case api.IShard:
173183
shard := obj.(api.IShard)
174184
return n.namePartClusterName(shard.GetRuntime().GetAddress().GetClusterName())

0 commit comments

Comments
 (0)