-
Notifications
You must be signed in to change notification settings - Fork 35
Made operator update StatefulSets not only when replica count changed #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…Update as previous version was modifying cached builStatefulSet
…ic to use equality k8s package
… after resources changed
1b65b03 to
99ceb81
Compare
…Update is correctly detecting changes and got rid of k8s.io equality package for specs comparison
…ent, moved resources test out of the common e2e context and use s.rebuildStatefulSet().Spec in needUpdate
… overriden for it
…lding the spec, causing comparison mismatch
… added after the spec build. Added envFromEqual to the pod comparison
|
Why we cannot just generate new sts spec, marshal .Spec and compare? If you want to ignore some difference in order that could be normalization which sorts some list before serialization into json |
Agree, I think with so many fields it would be a painful experience to support explicit comparison of each one. Also do the mutable/immutable sts fields considered? Do we ignore immutable or everything will just stuck on error? |
@koct9i @l0kix2
I added only mutable fields to the comparison, for the immutable ones we need to create additional Issue and implementation with "delete sts --cascade=orphan" command under the hood, but it is different story |
|
Maybe we could completely eliminate content comparison of managed resources. "Controller" resorce (ytsaurus) has generation which is updated at any changes. We just compare controller resource generation and generation saved in managed resource. |
|
For now, I think that field-by-field comparison approach is not our best option.
I suggest we go back to the issue and discuss our options #374 |
PR is aiming to solve Issue #374.
Overview
This PR implements comprehensive StatefulSet spec change detection to enable the operator to detect and respond to configuration changes (resources, env vars, volumes, etc.) beyond just replica count changes and images.
Changes:
That logic compares:
I tried to implement comparison using k8s.io/apimachinery/pkg/api/equality package, but it led to the infinite recreating loop. The same applies to the strategicpatch.CreateTwoWayMergePatch (it uses json document merging, not semantic equality, but the problem is similar)
Both of them detects Kubernetes default values, that doesn't matter for us to compare, but led to the false-positive Update status on the operator.
Here you can see how postgres-operator compares sts's fields: https://github.com/zalando/postgres-operator/blob/3bc244fe397ad084de8ddc3e02a1670f6b4c0949/pkg/cluster/cluster.go#L648
tl;dr - also field-by-field
Problem: YqlAgent adds environment variables (YT_FORCE_IPV4, YT_FORCE_IPV6, token) and modifies commands AFTER building the base spec, causing mismatches during comparison
Solution: Extracted modifications into applyYqlAgentContainerModifications()
Overrode needUpdate() and needStatefulSetSpecUpdate() to apply modifications before comparison
execNode - ExecNode combines NodeResources + JobResources, requiring special handling. Overrode needStatefulSetSpecUpdate() to compute expected total resources before comparison
httProxy - because httpProxy adds volumes for TLS encryption after the buildStatefulSet() and it will cause infinite update loop, cause during every reconcilation loop operator will think there is difference in the statefulSet spec.
rpcProxy - the same as for http-proxy
Added needUpdateWithSpecCheck() to allow components to provide custom spec comparison logic.
Updated needUpdate to use the new comparison function
Added several tests: