mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Merge pull request #52558 from jennybuckley/master
Automatic merge from submit-queue (batch tested with PRs 52831, 52764, 52763, 52673, 52558). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.. Allow updating objects with empty pending initializers list **What this PR does / why we need it**: When updating an object, an empty pending list should be treated as a nil initializer. This PR fixes a bug which prevented this functionality and also adds a test which will ensure this functionality is preserved. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #52202 **Special notes for your reviewer**: /cc @caesarxuchao **Release note**: ```release-note Fixes an initializer bug where update requests which had an empty pending initializers list were erroneously rejected. ```
This commit is contained in:
commit
f67e127a3b
@ -208,6 +208,13 @@ func (i *initializer) Admit(a admission.Attributes) (err error) {
|
||||
}
|
||||
updated := accessor.GetInitializers()
|
||||
|
||||
// controllers deployed with an empty initializers.pending have their initializers set to nil
|
||||
// but should be able to update without changing their manifest
|
||||
if updated != nil && len(updated.Pending) == 0 && updated.Result == nil {
|
||||
accessor.SetInitializers(nil)
|
||||
updated = nil
|
||||
}
|
||||
|
||||
existingAccessor, err := meta.Accessor(a.GetOldObject())
|
||||
if err != nil {
|
||||
// if the old object does not have an accessor, but the new one does, error out
|
||||
@ -222,9 +229,6 @@ func (i *initializer) Admit(a admission.Attributes) (err error) {
|
||||
|
||||
glog.V(5).Infof("Modifying uninitialized resource %s", a.GetResource())
|
||||
|
||||
if updated != nil && len(updated.Pending) == 0 && updated.Result == nil {
|
||||
accessor.SetInitializers(nil)
|
||||
}
|
||||
// because we are called before validation, we need to ensure the update transition is valid.
|
||||
if errs := validation.ValidateInitializersUpdate(updated, existing, initializerFieldPath); len(errs) > 0 {
|
||||
return errors.NewInvalid(a.GetKind().GroupKind(), a.GetName(), errs)
|
||||
|
@ -152,6 +152,22 @@ func TestAdmitUpdate(t *testing.T) {
|
||||
newInitializers: &metav1.Initializers{Pending: []metav1.Initializer{{Name: "init.k8s.io"}}},
|
||||
err: "field is immutable once initialization has completed",
|
||||
},
|
||||
{
|
||||
name: "empty initializer list is treated as nil initializer",
|
||||
oldInitializers: nil,
|
||||
newInitializers: &metav1.Initializers{},
|
||||
verifyUpdatedObj: func(obj runtime.Object) (bool, string) {
|
||||
accessor, err := meta.Accessor(obj)
|
||||
if err != nil {
|
||||
return false, "cannot get accessor"
|
||||
}
|
||||
if accessor.GetInitializers() != nil {
|
||||
return false, "expect nil initializers"
|
||||
}
|
||||
return true, ""
|
||||
},
|
||||
err: "",
|
||||
},
|
||||
}
|
||||
|
||||
plugin := initializer{
|
||||
|
Loading…
Reference in New Issue
Block a user