-
Notifications
You must be signed in to change notification settings - Fork 459
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
Fix StatefulSet Update Logic to Avoid Forbidden Field Updates #2214
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the "expected" statefulset is created based on changes to other resources. Can't we prevent changes to these resources if they would incur changes to the statefulset? Now changes are not made and users may have no clue why their change isn't propagating to the statefulset...
PS: Code looks fine.
@ramondeklein So do you mean that you want to disable the modification of some fields in the operator console (such as |
@fengyinqiao Yes, if we can check if a change in a CRD field would lead to an invalid statefulset, then it would be better to disallow the user from making that change. That would result in an error and the user can deal with that. If that change is allowed to the CRDs, but it won't have any effect to the statefulset, the user will wonder why it won't work. PS: Don't worry about the operator console UI. It has been removed in #2205. |
@ramondeklein I checked it, and the following fields will be ignored in the update of the STS after this PR is merged:
Then the modification of these two fields is prohibited in the CRD. Do you agree or not? The modification method is as follows: type Pool struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"
Name string `json:"name"`
}
type TenantSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="podManagementPolicy is immutable"
PodManagementPolicy appsv1.PodManagementPolicyType `json:"podManagementPolicy,omitempty"`
} |
@fengyinqiao I'm not an operator specialist, so I'm not the one to decide. I just look at what I would expect as a user of the operator. @jiuker @cniackz I think you're more qualified to comment on this... |
@pjuarezd cc |
I think what needs to be done here and in #2196 is an orphaned delete of the statefulset which keeps the pods around and then a re-creation of the statefulset with the updated values. See https://prometheus-operator.dev/docs/platform/storage/#resizing-volumes for reference |
@sebhoss Read your link, this is a manual operation and maintenance of the operation process, which seems inappropriate to do it in the operator, or do we want to support these manual operations in the same way? In addition, after the sts re-creation, the |
@fengyinqiao yeah sorry I was unclear I want I meant & I'm not a maintainer of this repo - just a user who stumbled across this PR randomly 😅 I think the idea behind #2196 is fantastic because it is much better to do this resize PVC dance automatically by an operator than do it manually as we have to do with the prometheus-operator. However the implementation is flawed because it needs to do 3 steps but only does 1 so far:
Since 3. is not implemented you run into a problem that you are trying to solve with this PR. Instead of ignoring certain field updates while updating a statefuset, I think you should adopt what the prometheus-operator people have documented: Delete the sts using I think implementing a validating webhook is a nice idea as well, e.g. it could check whether the used storage class allows resize operations while users are modifying the tenant resource and reject such modification if resize is not possible. Likewise that webhook could prohibit every other update to a tenant that would result in a fatal change to the sts like point 1 from #2214 (comment) |
Description
This PR addresses an issue with the previous implementation of updating a StatefulSet, where the entire
expectedStatefulSet
was being directly updated to Kubernetes. This approach often resulted in update failures since Kubernetes only allows specific fields to be updated in a StatefulSet (replicas, ordinals, template, updateStrategy, persistentVolumeClaimRetentionPolicy, and minReadySeconds).The new implementation introduces a function,
UpdateStatefulSetSpec
, which ensures that only the permissible fields are updated. Additionally, it preserves specific legacy labels, such as the zone label, to maintain backward compatibility.Changes
UpdateStatefulSetSpec
that updates only the allowed fields of a StatefulSet.Function Documentation
Issue Reference
Testing
Additional Notes
@jiuker @cniackz Please review the changes and let me know if any adjustments are needed. Thank you!