diff --git a/pkg/registry/flowcontrol/flowschema/strategy.go b/pkg/registry/flowcontrol/flowschema/strategy.go index fee6b97a4d6..6286e1a1cc0 100644 --- a/pkg/registry/flowcontrol/flowschema/strategy.go +++ b/pkg/registry/flowcontrol/flowschema/strategy.go @@ -94,7 +94,12 @@ var StatusStrategy = flowSchemaStatusStrategy{Strategy} func (flowSchemaStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) { newFlowSchema := obj.(*flowcontrol.FlowSchema) oldFlowSchema := old.(*flowcontrol.FlowSchema) + + // managedFields must be preserved since it's been modified to + // track changed fields in the status update. + managedFields := newFlowSchema.ManagedFields newFlowSchema.ObjectMeta = oldFlowSchema.ObjectMeta + newFlowSchema.ManagedFields = managedFields newFlowSchema.Spec = oldFlowSchema.Spec } diff --git a/pkg/registry/flowcontrol/prioritylevelconfiguration/strategy.go b/pkg/registry/flowcontrol/prioritylevelconfiguration/strategy.go index 9340407ed76..9cc7877a4d7 100644 --- a/pkg/registry/flowcontrol/prioritylevelconfiguration/strategy.go +++ b/pkg/registry/flowcontrol/prioritylevelconfiguration/strategy.go @@ -94,7 +94,12 @@ var StatusStrategy = priorityLevelConfigurationStatusStrategy{Strategy} func (priorityLevelConfigurationStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) { newPriorityLevelConfiguration := obj.(*flowcontrol.PriorityLevelConfiguration) oldPriorityLevelConfiguration := old.(*flowcontrol.PriorityLevelConfiguration) + + // managedFields must be preserved since it's been modified to + // track changed fields in the status update. + managedFields := newPriorityLevelConfiguration.ManagedFields newPriorityLevelConfiguration.ObjectMeta = oldPriorityLevelConfiguration.ObjectMeta + newPriorityLevelConfiguration.ManagedFields = managedFields newPriorityLevelConfiguration.Spec = oldPriorityLevelConfiguration.Spec } diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/status_strategy.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/status_strategy.go index 1710eb2e15a..b31b627039f 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/status_strategy.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/status_strategy.go @@ -38,6 +38,10 @@ func (a statusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.O newCustomResource := newCustomResourceObject.UnstructuredContent() status, ok := newCustomResource["status"] + // managedFields must be preserved since it's been modified to + // track changed fields in the status update. + managedFields := newCustomResourceObject.GetManagedFields() + // copy old object into new object oldCustomResourceObject := old.(*unstructured.Unstructured) // overridding the resourceVersion in metadata is safe here, we have already checked that @@ -45,6 +49,7 @@ func (a statusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.O *newCustomResourceObject = *oldCustomResourceObject.DeepCopy() // set status + newCustomResourceObject.SetManagedFields(managedFields) newCustomResource = newCustomResourceObject.UnstructuredContent() if ok { newCustomResource["status"] = status diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go index ec016fd3c8d..ad989ad75ca 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go @@ -252,7 +252,9 @@ func ResetObjectMetaForStatus(meta, existingMeta Object) { meta.SetAnnotations(existingMeta.GetAnnotations()) meta.SetFinalizers(existingMeta.GetFinalizers()) meta.SetOwnerReferences(existingMeta.GetOwnerReferences()) - meta.SetManagedFields(existingMeta.GetManagedFields()) + // managedFields must be preserved since it's been modified to + // track changed fields in the status update. + //meta.SetManagedFields(existingMeta.GetManagedFields()) } // MarshalJSON implements json.Marshaler diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go index 54963c4ca21..62023c07967 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go @@ -189,6 +189,7 @@ func TestResetObjectMetaForStatus(t *testing.T) { existingMeta.SetCreationTimestamp(Time{}) existingMeta.SetDeletionTimestamp(nil) existingMeta.SetDeletionGracePeriodSeconds(nil) + existingMeta.SetManagedFields(nil) if !reflect.DeepEqual(meta, existingMeta) { t.Error(diff.ObjectDiff(meta, existingMeta))