Do not reset managedFields in status update strategy

This commit is contained in:
Antoine Pelisse 2020-03-18 14:17:32 -07:00
parent 94cb60e0e8
commit dfe1703ffa
5 changed files with 19 additions and 1 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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))