Skip to content

Don't restart pods on some config changes#115

Draft
scanhex12 wants to merge 4 commits intomainfrom
reload_without_restart
Draft

Don't restart pods on some config changes#115
scanhex12 wants to merge 4 commits intomainfrom
reload_without_restart

Conversation

@scanhex12
Copy link
Member

Why

Some configuration updates don't require a pod restart. This pull request improves that behavior.

@scanhex12 scanhex12 marked this pull request as draft March 4, 2026 20:25
@scanhex12 scanhex12 requested a review from Copilot March 17, 2026 17:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to prevent unnecessary ClickHouse pod restarts for configuration changes that ClickHouse can reload dynamically (e.g., ExtraUsersConfig), while still restarting pods for config changes that require it.

Changes:

  • Add a “restart-required config hash” annotation to StatefulSets and use it to decide whether a ConfigMap change should trigger a pod restart.
  • If restart is not required, issue ClickHouse SYSTEM RELOAD CONFIG / SYSTEM RELOAD USERS commands instead of restarting pods.
  • Add an e2e test asserting that ExtraUsersConfig updates do not restart pods.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/e2e/clickhouse_e2e_test.go Adds an e2e scenario validating no pod restart on ExtraUsersConfig changes.
internal/controllerutil/annotations.go Introduces an annotation key + helpers for storing/retrieving the restart-required config hash.
internal/controller/clickhouse/templates.go Defines which generated config keys are considered restart-required and computes a hash for them.
internal/controller/clickhouse/sync.go Updates reconcile logic to restart only when restart-required config changes; otherwise reload in-place.
internal/controller/clickhouse/commands.go Adds commander methods to run ClickHouse SYSTEM RELOAD CONFIG/USERS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +812 to +818
desiredRestartRequiredHash, err := getRestartRequiredConfigRevision(r)
if err != nil {
desiredRestartRequiredHash = "" // on error — always restart
}

currentRestartRequiredHash := ctrlutil.GetRestartRequiredConfigHashFromObject(replica.StatefulSet)
restartNeeded := desiredRestartRequiredHash != currentRestartRequiredHash
Comment on lines 826 to 843
} else {
log.Info("config changed but restart not required, reloading config without pod restart")

if r.commander != nil {
if reloadErr := r.commander.ReloadConfig(ctx, id); reloadErr != nil {
log.Warn("failed to reload config", "error", reloadErr)
}

if reloadErr := r.commander.ReloadUsers(ctx, id); reloadErr != nil {
log.Warn("failed to reload users", "error", reloadErr)
}
}
}

ctrlutil.AddObjectConfigHash(replica.StatefulSet, r.Cluster.Status.ConfigurationRevision)
ctrlutil.AddObjectRestartRequiredConfigHash(statefulSet, desiredRestartRequiredHash)

stsNeedsUpdate = true
Comment on lines +160 to +173
By("waiting for configuration to sync")
EventuallyWithOffset(1, func() bool {
var cluster v1.ClickHouseCluster

ExpectWithOffset(1, k8sClient.Get(ctx, cr.NamespacedName(), &cluster)).To(Succeed())

for _, cond := range cluster.Status.Conditions {
if cond.Type == string(v1.ConditionTypeConfigurationInSync) && cond.Status == metav1.ConditionTrue {
return true
}
}

return false
}, 2*time.Minute).Should(BeTrue())
@scanhex12 scanhex12 force-pushed the reload_without_restart branch from fb801c8 to 6e25096 Compare March 19, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants