Draft
Conversation
There was a problem hiding this comment.
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 USERScommands instead of restarting pods. - Add an e2e test asserting that
ExtraUsersConfigupdates 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()) |
fb801c8 to
6e25096
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Some configuration updates don't require a pod restart. This pull request improves that behavior.