diff --git a/pkg/apis/clickhouse-keeper.altinity.com/v1/type_cluster.go b/pkg/apis/clickhouse-keeper.altinity.com/v1/type_cluster.go index 301287826..0d373ecaf 100644 --- a/pkg/apis/clickhouse-keeper.altinity.com/v1/type_cluster.go +++ b/pkg/apis/clickhouse-keeper.altinity.com/v1/type_cluster.go @@ -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] diff --git a/pkg/controller/chk/worker-reconciler-chk.go b/pkg/controller/chk/worker-reconciler-chk.go index c440dd23c..21d8bbfcd 100644 --- a/pkg/controller/chk/worker-reconciler-chk.go +++ b/pkg/controller/chk/worker-reconciler-chk.go @@ -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) diff --git a/pkg/controller/common/poller/domain/poller-host-objects.go b/pkg/controller/common/poller/domain/poller-host-objects.go index 4ccf6f2e7..69548803e 100644 --- a/pkg/controller/common/poller/domain/poller-host-objects.go +++ b/pkg/controller/common/poller/domain/poller-host-objects.go @@ -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 { + _ = p.readyMarkDeleter.DeleteReadyMarkOnPodAndService(_ctx, host) + } return k8s.IsStatefulSetReconcileCompleted(sts) }, ) diff --git a/pkg/model/chk/normalizer/normalizer.go b/pkg/model/chk/normalizer/normalizer.go index 881b060d3..8b56cbb0e 100644 --- a/pkg/model/chk/normalizer/normalizer.go +++ b/pkg/model/chk/normalizer/normalizer.go @@ -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() @@ -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 diff --git a/pkg/model/common/macro/engine.go b/pkg/model/common/macro/engine.go index 905d4b09d..dc65e0311 100644 --- a/pkg/model/common/macro/engine.go +++ b/pkg/model/common/macro/engine.go @@ -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" @@ -68,6 +69,8 @@ func (e *Engine) Replacer() *util.Replacer { return e.newReplacerCR(t) case api.ICluster: return e.newReplacerCluster(t) + case *apiChk.Cluster: + return e.newReplacerCHKCluster(t) case api.IShard: return e.newReplacerShard(t) case api.IReplica: @@ -105,6 +108,16 @@ func (e *Engine) newReplacerCluster(cluster api.ICluster) *util.Replacer { }) } +// newReplacerCHKCluster +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{ diff --git a/pkg/model/common/namer/short/namer.go b/pkg/model/common/namer/short/namer.go index b31b868df..55df20b34 100644 --- a/pkg/model/common/namer/short/namer.go +++ b/pkg/model/common/namer/short/namer.go @@ -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" ) @@ -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: + 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()) @@ -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: + 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()) @@ -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: + 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())