@@ -34,6 +34,7 @@ func compareReplicaID(a, b v1.ClickHouseReplicaID) int {
3434type replicaState struct {
3535 Error bool `json:"error"`
3636 StatefulSet * appsv1.StatefulSet
37+ PVC * corev1.PersistentVolumeClaim
3738 Pinged bool
3839 Version string
3940}
@@ -55,20 +56,30 @@ func (r replicaState) Ready() bool {
5556 return r .Pinged && r .StatefulSet .Status .ReadyReplicas == 1 // Not reliable, but allows to wait until pod is `green`
5657}
5758
58- func (r replicaState ) HasStatefulSetDiff (rec * clickhouseReconciler ) bool {
59+ func (r replicaState ) HasDiff (rec * clickhouseReconciler ) bool {
5960 if r .StatefulSet == nil {
6061 return true
6162 }
6263
63- return ctrlutil .GetSpecHashFromObject (r .StatefulSet ) != rec .Cluster .Status .StatefulSetRevision
64- }
64+ if ctrlutil .GetSpecHashFromObject (r .StatefulSet ) != rec .Cluster .Status .StatefulSetRevision {
65+ return true
66+ }
6567
66- func (r replicaState ) HasConfigMapDiff (rec * clickhouseReconciler ) bool {
67- if r .StatefulSet == nil {
68+ if ctrlutil .GetConfigHashFromObject (r .StatefulSet ) != rec .Cluster .Status .ConfigurationRevision {
6869 return true
6970 }
7071
71- return ctrlutil .GetConfigHashFromObject (r .StatefulSet ) != rec .Cluster .Status .ConfigurationRevision
72+ if rec .Cluster .Spec .DataVolumeClaimSpec != nil {
73+ if r .PVC == nil {
74+ return true
75+ }
76+
77+ if ctrlutil .GetSpecHashFromObject (r .PVC ) != rec .pvcRevision {
78+ return true
79+ }
80+ }
81+
82+ return false
7283}
7384
7485func (r replicaState ) UpdateStage (rec * clickhouseReconciler ) chctrl.ReplicaUpdateStage {
@@ -84,7 +95,7 @@ func (r replicaState) UpdateStage(rec *clickhouseReconciler) chctrl.ReplicaUpdat
8495 return chctrl .StageUpdating
8596 }
8697
87- if r .HasConfigMapDiff ( rec ) || r . HasStatefulSetDiff (rec ) {
98+ if r .HasDiff (rec ) {
8899 return chctrl .StageHasDiff
89100 }
90101
@@ -109,6 +120,7 @@ type clickhouseReconciler struct {
109120 versionProbe chctrl.VersionProbeResult
110121 databasesInSync bool
111122 staleReplicasCleanedUp bool
123+ pvcRevision string
112124}
113125
114126type reconcileFunc func (context.Context , ctrlutil.Logger ) (* ctrl.Result , error )
@@ -316,6 +328,13 @@ func (r *clickhouseReconciler) reconcileClusterRevisions(ctx context.Context, lo
316328 log .Debug (fmt .Sprintf ("observed new StatefulSet revision %q" , stsRevision ))
317329 }
318330
331+ if r .Cluster .Spec .DataVolumeClaimSpec != nil {
332+ r .pvcRevision , err = ctrlutil .DeepHashObject (r .Cluster .Spec .DataVolumeClaimSpec )
333+ if err != nil {
334+ return nil , fmt .Errorf ("get PVC revision: %w" , err )
335+ }
336+ }
337+
319338 probeResult , err := r .VersionProbe (ctx , log , chctrl.VersionProbeConfig {
320339 Binary : "clickhouse-server" ,
321340 Labels : r .Cluster .Spec .Labels ,
@@ -370,10 +389,19 @@ func (r *clickhouseReconciler) reconcileActiveReplicaStatus(ctx context.Context,
370389 }
371390 }
372391
392+ var pvc * corev1.PersistentVolumeClaim
393+ if r .Cluster .Spec .DataVolumeClaimSpec != nil {
394+ pvc , err = r .GetPVCByStatefulSet (ctx , log .With ("replica_id" , id ), & sts )
395+ if err != nil {
396+ log .Error (err , "failed to get PVC for replica" , "replica_id" , id )
397+ }
398+ }
399+
373400 log .Debug ("load replica state done" , "replica_id" , id , "statefulset" , sts .Name )
374401
375402 return id , replicaState {
376403 StatefulSet : & sts ,
404+ PVC : pvc ,
377405 Error : hasError ,
378406 Pinged : pinged ,
379407 Version : version ,
@@ -686,7 +714,7 @@ func (r *clickhouseReconciler) reconcileConditions(ctx context.Context, log ctrl
686714 hasReady = true
687715 }
688716
689- if replica .HasConfigMapDiff ( r ) || replica . HasStatefulSetDiff (r ) || ! replica .Updated () {
717+ if replica .HasDiff (r ) || ! replica .Updated () {
690718 notUpdatedReplicas = append (notUpdatedReplicas , id )
691719 }
692720 }
@@ -812,15 +840,19 @@ func (r *clickhouseReconciler) updateReplica(ctx context.Context, log ctrlutil.L
812840
813841 replica := r .Replica (id )
814842
815- result , err := r .ReconcileReplicaResources (ctx , log , id , chctrl.ReplicaUpdateInput {
816- ExistingSTS : replica .StatefulSet ,
817- DesiredConfigMap : configMap ,
818- DesiredSTS : statefulSet ,
819- HasError : replica .Error ,
843+ result , err := r .ReconcileReplicaResources (ctx , log , chctrl.ReplicaUpdateInput {
820844 ConfigurationRevision : r .Cluster .Status .ConfigurationRevision ,
821- StatefulSetRevision : r .Cluster .Status .StatefulSetRevision ,
822- BreakingSTSVersion : breakingStatefulSetVersion ,
823- DataVolumeClaimSpec : r .Cluster .Spec .DataVolumeClaimSpec ,
845+ DesiredConfigMap : configMap ,
846+
847+ StatefulSetRevision : r .Cluster .Status .StatefulSetRevision ,
848+ ExistingSTS : replica .StatefulSet ,
849+ DesiredSTS : statefulSet ,
850+ HasError : replica .Error ,
851+ BreakingSTSVersion : breakingStatefulSetVersion ,
852+
853+ PVCRevision : r .pvcRevision ,
854+ ExistingPVC : replica .PVC ,
855+ DesiredPVCSpec : r .Cluster .Spec .DataVolumeClaimSpec ,
824856 })
825857 if err != nil {
826858 return nil , fmt .Errorf ("reconcile replica %s resources: %w" , id , err )
0 commit comments