Skip to content

Commit 7a548e8

Browse files
author
tazhate
committed
fix(controller): preserve pod-template annotations across reconciles
ensureStatefulSet was calling sts.Spec = desired on every reconcile, which overwrote the pod-template annotations entirely with just {config-hash}. This erased the restarted-at annotation set by reconcileUpgrade, causing the upgrade test to fail (it verified the annotation persisted through a no-op reconcile). Fixed by merging existing pod-template annotations into desired: desired keys (config-hash) take priority; all other keys are carried over. This preserves restarted-at and any future annotations without interfering with the config-hash change-detection mechanism. Spent ~30min tracing through CreateOrUpdate + Spec replace behavior with debug prints to isolate the root cause.
1 parent 3ed046a commit 7a548e8

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

internal/controller/reconcile_statefulset.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,21 @@ func (r *BlockchainNodeReconciler) ensureStatefulSet(
7272
}
7373

7474
_, err := controllerutil.CreateOrUpdate(ctx, r.Client, sts, func() error {
75+
// Preserve pod-template annotations set by reconcileUpgrade (e.g. restarted-at).
76+
// desired.Template.Annotations only carries config-hash; don't clobber the rest.
77+
existingTemplateAnns := sts.Spec.Template.Annotations
78+
7579
sts.Labels = coreLabels(node)
7680
sts.Spec = desired
81+
82+
if sts.Spec.Template.Annotations == nil {
83+
sts.Spec.Template.Annotations = map[string]string{}
84+
}
85+
for k, v := range existingTemplateAnns {
86+
if _, ok := sts.Spec.Template.Annotations[k]; !ok {
87+
sts.Spec.Template.Annotations[k] = v
88+
}
89+
}
7790
return controllerutil.SetControllerReference(node, sts, r.Scheme)
7891
})
7992
if err != nil {

0 commit comments

Comments
 (0)